redundant_closure ignore coerced closure

This commit is contained in:
dswij 2022-02-23 23:04:06 +08:00
parent 95396f61bc
commit 33bf9e9a54
4 changed files with 30 additions and 16 deletions

View file

@ -37,7 +37,7 @@ fn main() {
}
// See #815
let e = Some(1u8).map(divergent);
let e = Some(1u8).map(|a| divergent(a));
let e = Some(1u8).map(generic);
let e = Some(1u8).map(generic);
// See #515
@ -233,7 +233,7 @@ fn late_bound_lifetimes() {
{
}
map_str(|s| take_asref_path(s));
map_str_to_path(std::convert::AsRef::as_ref);
map_str_to_path(|s| s.as_ref());
}
mod type_param_bound {
@ -279,3 +279,15 @@ mod bind_by_ref {
Some(A).map(|ref a| B::from(a));
}
}
// #7812 False positive on coerced closure
fn coerced_closure() {
fn function_returning_unit<F: FnMut(i32)>(f: F) {}
function_returning_unit(|x| std::process::exit(x));
fn arr() -> &'static [u8; 0] {
&[]
}
fn slice_fn(_: impl FnOnce() -> &'static [u8]) {}
slice_fn(|| arr());
}

View file

@ -279,3 +279,15 @@ mod bind_by_ref {
Some(A).map(|ref a| B::from(a));
}
}
// #7812 False positive on coerced closure
fn coerced_closure() {
fn function_returning_unit<F: FnMut(i32)>(f: F) {}
function_returning_unit(|x| std::process::exit(x));
fn arr() -> &'static [u8; 0] {
&[]
}
fn slice_fn(_: impl FnOnce() -> &'static [u8]) {}
slice_fn(|| arr());
}

View file

@ -24,12 +24,6 @@ error: redundant closure
LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted
| ^^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `below`
error: redundant closure
--> $DIR/eta.rs:40:27
|
LL | let e = Some(1u8).map(|a| divergent(a));
| ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `divergent`
error: redundant closure
--> $DIR/eta.rs:41:27
|
@ -122,11 +116,5 @@ error: redundant closure
LL | Some(1).map(|n| in_loop(n));
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `in_loop`
error: redundant closure
--> $DIR/eta.rs:236:21
|
LL | map_str_to_path(|s| s.as_ref());
| ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::convert::AsRef::as_ref`
error: aborting due to 21 previous errors
error: aborting due to 19 previous errors