Merge pull request #817 from mcarton/eta

Fix FP in `REDUNDANT_CLOSURE` with divergent functions
This commit is contained in:
llogiq 2016-03-30 23:21:48 +02:00
commit 4f17633653
2 changed files with 18 additions and 1 deletions

View 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;
}
}

View 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 @@ 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>(_: T) -> u8 {
0
}