fix [redundant_closure] suggesting incorrect code with F: Fn()

This commit is contained in:
J-ZhengLi 2024-05-29 16:21:59 +08:00
parent 722de3b546
commit db30f6ce9f
4 changed files with 54 additions and 9 deletions

View file

@ -471,3 +471,14 @@ mod issue_10854 {
}
}
}
mod issue_12853 {
fn f_by_value<F: Fn(u32)>(f: F) {
let x = Box::new(|| None.map(&f));
x();
}
fn f_by_ref<F: Fn(u32)>(f: &F) {
let x = Box::new(|| None.map(f));
x();
}
}

View file

@ -471,3 +471,14 @@ mod issue_10854 {
}
}
}
mod issue_12853 {
fn f_by_value<F: Fn(u32)>(f: F) {
let x = Box::new(|| None.map(|x| f(x)));
x();
}
fn f_by_ref<F: Fn(u32)>(f: &F) {
let x = Box::new(|| None.map(|x| f(x)));
x();
}
}

View file

@ -190,5 +190,17 @@ error: redundant closure
LL | test.map(|t| t.method())
| ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `crate::issue_10854::d::Test::method`
error: aborting due to 31 previous errors
error: redundant closure
--> tests/ui/eta.rs:477:38
|
LL | let x = Box::new(|| None.map(|x| f(x)));
| ^^^^^^^^ help: replace the closure with the function itself: `&f`
error: redundant closure
--> tests/ui/eta.rs:481:38
|
LL | let x = Box::new(|| None.map(|x| f(x)));
| ^^^^^^^^ help: replace the closure with the function itself: `f`
error: aborting due to 33 previous errors