diff --git a/clippy_lints/src/map_nil_fn.rs b/clippy_lints/src/map_nil_fn.rs index 0fd2c176a643..9502c5d05632 100644 --- a/clippy_lints/src/map_nil_fn.rs +++ b/clippy_lints/src/map_nil_fn.rs @@ -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 diff --git a/tests/compile-fail/map_nil_fn.rs b/tests/compile-fail/map_nil_fn.rs index 0338216c5782..03f77c500348 100644 --- a/tests/compile-fail/map_nil_fn.rs +++ b/tests/compile-fail/map_nil_fn.rs @@ -7,6 +7,10 @@ fn do_nothing(_: T) {} +fn diverge(_: 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(...) } }