[filter_map_bool_then]: peel as many refs as needed
This commit is contained in:
parent
f54275f20f
commit
860e800fa0
4 changed files with 40 additions and 5 deletions
|
|
@ -59,4 +59,12 @@ fn issue11309<'a>(iter: impl Iterator<Item = (&'a str, &'a str)>) -> Vec<&'a str
|
|||
fn issue11503() {
|
||||
let bools: &[bool] = &[true, false, false, true];
|
||||
let _: Vec<usize> = bools.iter().enumerate().filter(|&(i, b)| *b).map(|(i, b)| i).collect();
|
||||
|
||||
// Need to insert multiple derefs if there is more than one layer of references
|
||||
let bools: &[&&bool] = &[&&true, &&false, &&false, &&true];
|
||||
let _: Vec<usize> = bools.iter().enumerate().filter(|&(i, b)| ***b).map(|(i, b)| i).collect();
|
||||
|
||||
// Should also suggest derefs when going through a mutable reference
|
||||
let bools: &[&mut bool] = &[&mut true];
|
||||
let _: Vec<usize> = bools.iter().enumerate().filter(|&(i, b)| **b).map(|(i, b)| i).collect();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,4 +59,12 @@ fn issue11309<'a>(iter: impl Iterator<Item = (&'a str, &'a str)>) -> Vec<&'a str
|
|||
fn issue11503() {
|
||||
let bools: &[bool] = &[true, false, false, true];
|
||||
let _: Vec<usize> = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect();
|
||||
|
||||
// Need to insert multiple derefs if there is more than one layer of references
|
||||
let bools: &[&&bool] = &[&&true, &&false, &&false, &&true];
|
||||
let _: Vec<usize> = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect();
|
||||
|
||||
// Should also suggest derefs when going through a mutable reference
|
||||
let bools: &[&mut bool] = &[&mut true];
|
||||
let _: Vec<usize> = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,5 +43,17 @@ error: usage of `bool::then` in `filter_map`
|
|||
LL | let _: Vec<usize> = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&(i, b)| *b).map(|(i, b)| i)`
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
error: usage of `bool::then` in `filter_map`
|
||||
--> $DIR/filter_map_bool_then.rs:65:50
|
||||
|
|
||||
LL | let _: Vec<usize> = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&(i, b)| ***b).map(|(i, b)| i)`
|
||||
|
||||
error: usage of `bool::then` in `filter_map`
|
||||
--> $DIR/filter_map_bool_then.rs:69:50
|
||||
|
|
||||
LL | let _: Vec<usize> = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&(i, b)| **b).map(|(i, b)| i)`
|
||||
|
||||
error: aborting due to 9 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue