Lint `Option.map(f)` where f never returns

This commit is contained in:
Phil Turnbull 2017-01-22 12:45:45 -05:00 committed by Philipp Hansch
parent e5ecbb55ee
commit 302f5d05f5
No known key found for this signature in database
GPG Key ID: B6FA06A6E0E2665B
2 changed files with 10 additions and 1 deletions

View File

@ -45,7 +45,7 @@ fn is_nil_function(cx: &LateContext, expr: &hir::Expr) -> bool {
if let ty::TyFnDef(_, _, bare) = ty.sty {
if let Some(fn_type) = cx.tcx.no_late_bound_regions(&bare.sig) {
return fn_type.output().is_nil();
return fn_type.output().is_nil() || fn_type.output().is_never();
}
}
false

View File

@ -7,6 +7,10 @@
fn do_nothing<T>(_: T) {}
fn diverge<T>(_: T) -> ! {
panic!()
}
fn plus_one(value: usize) -> usize {
value + 1
}
@ -39,4 +43,9 @@ fn main() {
//~^ ERROR called `map(f)` on an Option value where `f` is a nil function
//~| HELP try this
//~| SUGGESTION if let Some(...) = x.field { do_nothing(...) }
x.field.map(diverge);
//~^ ERROR called `map(f)` on an Option value where `f` is a nil function
//~| HELP try this
//~| SUGGESTION if let Some(...) = x.field { diverge(...) }
}