mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-02 01:52:51 +00:00
Add two more tests for redundant_closure
These two cases were fixed by #4008. Closes #1439 changelog: none
This commit is contained in:
parent
910d538ef1
commit
3f637cb369
@ -98,6 +98,30 @@ fn test_redundant_closures_containing_method_calls() {
|
||||
t.iter().filter(|x| x.trait_foo_ref());
|
||||
t.iter().map(|x| x.trait_foo_ref());
|
||||
}
|
||||
|
||||
let mut some = Some(|x| x * x);
|
||||
let arr = [Ok(1), Err(2)];
|
||||
let _: Vec<_> = arr.iter().map(|x| x.map_err(some.take().unwrap())).collect();
|
||||
}
|
||||
|
||||
struct Thunk<T>(Box<FnMut() -> T>);
|
||||
|
||||
impl<T> Thunk<T> {
|
||||
fn new<F: 'static + FnOnce() -> T>(f: F) -> Thunk<T> {
|
||||
let mut option = Some(f);
|
||||
// This should not trigger redundant_closure (#1439)
|
||||
Thunk(Box::new(move || option.take().unwrap()()))
|
||||
}
|
||||
|
||||
fn unwrap(self) -> T {
|
||||
let Thunk(mut f) = self;
|
||||
f()
|
||||
}
|
||||
}
|
||||
|
||||
fn foobar() {
|
||||
let thunk = Thunk::new(|| println!("Hello, world!"));
|
||||
thunk.unwrap()
|
||||
}
|
||||
|
||||
fn meta<F>(f: F)
|
||||
|
@ -98,6 +98,30 @@ fn test_redundant_closures_containing_method_calls() {
|
||||
t.iter().filter(|x| x.trait_foo_ref());
|
||||
t.iter().map(|x| x.trait_foo_ref());
|
||||
}
|
||||
|
||||
let mut some = Some(|x| x * x);
|
||||
let arr = [Ok(1), Err(2)];
|
||||
let _: Vec<_> = arr.iter().map(|x| x.map_err(|e| some.take().unwrap()(e))).collect();
|
||||
}
|
||||
|
||||
struct Thunk<T>(Box<FnMut() -> T>);
|
||||
|
||||
impl<T> Thunk<T> {
|
||||
fn new<F: 'static + FnOnce() -> T>(f: F) -> Thunk<T> {
|
||||
let mut option = Some(f);
|
||||
// This should not trigger redundant_closure (#1439)
|
||||
Thunk(Box::new(move || option.take().unwrap()()))
|
||||
}
|
||||
|
||||
fn unwrap(self) -> T {
|
||||
let Thunk(mut f) = self;
|
||||
f()
|
||||
}
|
||||
}
|
||||
|
||||
fn foobar() {
|
||||
let thunk = Thunk::new(|| println!("Hello, world!"));
|
||||
thunk.unwrap()
|
||||
}
|
||||
|
||||
fn meta<F>(f: F)
|
||||
|
@ -69,16 +69,22 @@ LL | let e: std::vec::Vec<char> = vec!['a', 'b', 'c'].iter().map(|c| c.to_as
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove closure as shown: `char::to_ascii_uppercase`
|
||||
|
||||
error: redundant closure found
|
||||
--> $DIR/eta.rs:145:27
|
||||
--> $DIR/eta.rs:104:50
|
||||
|
|
||||
LL | let _: Vec<_> = arr.iter().map(|x| x.map_err(|e| some.take().unwrap()(e))).collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove closure as shown: `some.take().unwrap()`
|
||||
|
||||
error: redundant closure found
|
||||
--> $DIR/eta.rs:169:27
|
||||
|
|
||||
LL | let a = Some(1u8).map(|a| foo_ptr(a));
|
||||
| ^^^^^^^^^^^^^^ help: remove closure as shown: `foo_ptr`
|
||||
|
||||
error: redundant closure found
|
||||
--> $DIR/eta.rs:150:27
|
||||
--> $DIR/eta.rs:174:27
|
||||
|
|
||||
LL | let a = Some(1u8).map(|a| closure(a));
|
||||
| ^^^^^^^^^^^^^^ help: remove closure as shown: `closure`
|
||||
|
||||
error: aborting due to 13 previous errors
|
||||
error: aborting due to 14 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user