This commit is contained in:
Oliver Schneider 2017-11-29 17:20:00 +01:00
parent d5b73c184b
commit 273ddafac5
No known key found for this signature in database
GPG key ID: A69F8D225B3AD7D9
2 changed files with 16 additions and 1 deletions

View file

@ -2,7 +2,7 @@ use rustc::lint::*;
use rustc::hir;
use rustc::ty;
use syntax_pos::Span;
use utils::{match_def_path, method_chain_args, span_lint_and_then, walk_ptrs_ty};
use utils::{match_def_path, method_chain_args, span_lint_and_then, walk_ptrs_ty, is_expn_of};
use utils::paths::{BEGIN_PANIC, BEGIN_PANIC_FMT, FROM_TRAIT, OPTION, RESULT};
/// **What it does:** Checks for impls of `From<..>` that contain `panic!()` or `unwrap()`
@ -66,6 +66,7 @@ fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_it
if let ExprPath(QPath::Resolved(_, ref path)) = func_expr.node;
if match_def_path(self.tcx, path.def.def_id(), &BEGIN_PANIC) ||
match_def_path(self.tcx, path.def.def_id(), &BEGIN_PANIC_FMT);
if is_expn_of(expr.span, "unreachable").is_none();
then {
self.result.push(expr.span);
}

View file

@ -61,4 +61,18 @@ impl<'a> From<&'a mut <Box<u32> as ProjStrTrait>::ProjString> for Invalid {
}
}
struct Unreachable;
impl From<String> for Unreachable {
fn from(s: String) -> Unreachable {
if s.is_empty() {
return Unreachable;
}
match s.chars().next() {
Some(_) => Unreachable,
None => unreachable!(), // do not lint the unreachable macro
}
}
}
fn main() {}