initial fix
This commit is contained in:
parent
caad063933
commit
9d311b5c2b
4 changed files with 75 additions and 2 deletions
|
|
@ -20,6 +20,19 @@ fn array() {
|
|||
};
|
||||
|
||||
let _ = if false { ["test"].iter() } else { [].iter() };
|
||||
|
||||
let smth = Some(vec![1, 2, 3]);
|
||||
|
||||
// Don't trigger when the empty collection iter is relied upon for its concrete type
|
||||
// But do trigger if it is just an iterator, despite being an argument to a method
|
||||
for i in smth.as_ref().map_or([].iter(), |s| s.iter()).chain(std::iter::empty()) {
|
||||
println!("{i}");
|
||||
}
|
||||
|
||||
// Same as above, but for regular function calls
|
||||
for i in Option::map_or(smth.as_ref(), [].iter(), |s| s.iter()) {
|
||||
println!("{i}");
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! in_macros {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,19 @@ fn array() {
|
|||
};
|
||||
|
||||
let _ = if false { ["test"].iter() } else { [].iter() };
|
||||
|
||||
let smth = Some(vec![1, 2, 3]);
|
||||
|
||||
// Don't trigger when the empty collection iter is relied upon for its concrete type
|
||||
// But do trigger if it is just an iterator, despite being an argument to a method
|
||||
for i in smth.as_ref().map_or([].iter(), |s| s.iter()).chain([].iter()) {
|
||||
println!("{i}");
|
||||
}
|
||||
|
||||
// Same as above, but for regular function calls
|
||||
for i in Option::map_or(smth.as_ref(), [].iter(), |s| s.iter()) {
|
||||
println!("{i}");
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! in_macros {
|
||||
|
|
|
|||
|
|
@ -37,5 +37,11 @@ error: `iter` call on an empty collection
|
|||
LL | assert_eq!(None.iter().next(), Option::<&i32>::None);
|
||||
| ^^^^^^^^^^^ help: try: `std::iter::empty()`
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
error: `iter` call on an empty collection
|
||||
--> tests/ui/iter_on_empty_collections.rs:28:66
|
||||
|
|
||||
LL | for i in smth.as_ref().map_or([].iter(), |s| s.iter()).chain([].iter()) {
|
||||
| ^^^^^^^^^ help: try: `std::iter::empty()`
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue