Lint `Option.map(f)` where f never returns
This commit is contained in:
parent
e5ecbb55ee
commit
302f5d05f5
|
@ -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
|
||||
|
|
|
@ -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(...) }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue