Skip to content

Commit 4f17633

Browse files
committed
Merge pull request #817 from mcarton/eta
Fix FP in `REDUNDANT_CLOSURE` with divergent functions
2 parents f98e3ec + 7095b5d commit 4f17633

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/eta_reduction.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ fn check_closure(cx: &LateContext, expr: &Expr) {
6161
match fn_ty.sty {
6262
// Is it an unsafe function? They don't implement the closure traits
6363
ty::TyFnDef(_, _, fn_ty) | ty::TyFnPtr(fn_ty) => {
64-
if fn_ty.unsafety == Unsafety::Unsafe {
64+
if fn_ty.unsafety == Unsafety::Unsafe ||
65+
fn_ty.sig.skip_binder().output == ty::FnOutput::FnDiverging {
6566
return;
6667
}
6768
}

tests/compile-fail/eta.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ fn main() {
2222
Some(1u8).map(|a| unsafe_fn(a)); // unsafe fn
2323
}
2424

25+
// See #815
26+
let e = Some(1u8).map(|a| divergent(a));
27+
let e = Some(1u8).map(|a| generic(a));
28+
//~^ ERROR redundant closure found
29+
//~| HELP remove closure as shown
30+
//~| SUGGESTION map(generic);
31+
let e = Some(1u8).map(generic);
32+
2533
// See #515
2634
let a: Option<Box<::std::ops::Deref<Target = [i32]>>> =
2735
Some(vec![1i32, 2]).map(|v| -> Box<::std::ops::Deref<Target = [i32]>> { Box::new(v) });
@@ -47,3 +55,11 @@ where F: Fn(&X, &X) -> bool {
4755
fn below(x: &u8, y: &u8) -> bool { x < y }
4856

4957
unsafe fn unsafe_fn(_: u8) { }
58+
59+
fn divergent(_: u8) -> ! {
60+
unimplemented!()
61+
}
62+
63+
fn generic<T>(_: T) -> u8 {
64+
0
65+
}

0 commit comments

Comments
 (0)