]> git.lizzy.rs Git - rust.git/commitdiff
Fix FP in `REDUNDANT_CLOSURE` with divergent functions
authormcarton <cartonmartin+git@gmail.com>
Wed, 30 Mar 2016 21:07:21 +0000 (23:07 +0200)
committermcarton <cartonmartin+git@gmail.com>
Wed, 30 Mar 2016 21:12:24 +0000 (23:12 +0200)
src/eta_reduction.rs
tests/compile-fail/eta.rs

index bae971f46acdbda2d9a4ae67cf7eab5fd62a7d7f..c080968ef84fefcf326765f69ac9ce3bdab1adc1 100644 (file)
@@ -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;
                         }
                     }
index 3fd089bf5883906a9436835666a2ea0078f91d10..a744489fa9c242319d31c8a1ca5e5d829b2a6209 100644 (file)
@@ -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<Box<::std::ops::Deref<Target = [i32]>>> =
         Some(vec![1i32, 2]).map(|v| -> Box<::std::ops::Deref<Target = [i32]>> { Box::new(v) });
@@ -47,3 +55,11 @@ fn all<X, F>(x: &[X], y: &X, f: F) -> bool
 fn below(x: &u8, y: &u8) -> bool { x < y }
 
 unsafe fn unsafe_fn(_: u8) { }
+
+fn divergent(_: u8) -> ! {
+    unimplemented!()
+}
+
+fn generic<T>(_: T) -> u8 {
+    0
+}