fix filter_map_bool_then with a bool reference
This commit is contained in:
parent
0273ed3afd
commit
c9b212d5ff
4 changed files with 20 additions and 3 deletions
|
|
@ -55,3 +55,8 @@ fn main() {
|
|||
fn issue11309<'a>(iter: impl Iterator<Item = (&'a str, &'a str)>) -> Vec<&'a str> {
|
||||
iter.filter_map(|(_, s): (&str, _)| Some(s)).collect()
|
||||
}
|
||||
|
||||
fn issue11503() {
|
||||
let bools: &[bool] = &[true, false, false, true];
|
||||
let _: Vec<usize> = bools.iter().enumerate().filter(|&(i, b)| *b).map(|(i, b)| i).collect();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,3 +55,8 @@ fn main() {
|
|||
fn issue11309<'a>(iter: impl Iterator<Item = (&'a str, &'a str)>) -> Vec<&'a str> {
|
||||
iter.filter_map(|(_, s): (&str, _)| Some(s)).collect()
|
||||
}
|
||||
|
||||
fn issue11503() {
|
||||
let bools: &[bool] = &[true, false, false, true];
|
||||
let _: Vec<usize> = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,5 +37,11 @@ error: usage of `bool::then` in `filter_map`
|
|||
LL | v.clone().iter().filter_map(|i| (i == &NonCopy).then(|| i));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i == &NonCopy)).map(|i| i)`
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
error: usage of `bool::then` in `filter_map`
|
||||
--> $DIR/filter_map_bool_then.rs:61: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 7 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue