diff --git a/src/eta_reduction.rs b/src/eta_reduction.rs index bae971f46ac..c080968ef84 100644 --- a/src/eta_reduction.rs +++ b/src/eta_reduction.rs @@ -61,7 +61,8 @@ fn check_closure(cx: &LateContext, expr: &Expr) { match fn_ty.sty { // Is it an unsafe function? They don't implement the closure traits ty::TyFnDef(_, _, fn_ty) | ty::TyFnPtr(fn_ty) => { - if fn_ty.unsafety == Unsafety::Unsafe { + if fn_ty.unsafety == Unsafety::Unsafe || + fn_ty.sig.skip_binder().output == ty::FnOutput::FnDiverging { return; } } diff --git a/tests/compile-fail/eta.rs b/tests/compile-fail/eta.rs index 3fd089bf588..a744489fa9c 100644 --- a/tests/compile-fail/eta.rs +++ b/tests/compile-fail/eta.rs @@ -22,6 +22,14 @@ fn main() { Some(1u8).map(|a| unsafe_fn(a)); // unsafe fn } + // See #815 + let e = Some(1u8).map(|a| divergent(a)); + let e = Some(1u8).map(|a| generic(a)); + //~^ ERROR redundant closure found + //~| HELP remove closure as shown + //~| SUGGESTION map(generic); + let e = Some(1u8).map(generic); + // See #515 let a: Option>> = Some(vec![1i32, 2]).map(|v| -> Box<::std::ops::Deref> { Box::new(v) }); @@ -47,3 +55,11 @@ where F: Fn(&X, &X) -> bool { fn below(x: &u8, y: &u8) -> bool { x < y } unsafe fn unsafe_fn(_: u8) { } + +fn divergent(_: u8) -> ! { + unimplemented!() +} + +fn generic(_: T) -> u8 { + 0 +}