-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not emit iteration note in coerce if loop does iterate
This fix does not cover all the cases when the loop iterates such as when the iterate value is a local instead of a literal
- Loading branch information
Showing
3 changed files
with
572 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// Regression test for #122561 | ||
// Checks that we do our best not to emit the note | ||
// saying the loop might run zero times if it is | ||
// clear it will certainly run at least once | ||
|
||
|
||
// ----- Should not emit note for these ----- | ||
fn atleast_once_iter_range() -> bool { | ||
for i in 0..3 { | ||
//~^ ERROR mismatched types | ||
return false; | ||
} | ||
} | ||
|
||
fn atleast_once_iter_range_neg() -> bool { | ||
for i in -3..-1 { | ||
//~^ ERROR mismatched types | ||
return false; | ||
} | ||
} | ||
|
||
fn atleast_once_iter_range_inclusive() -> bool { | ||
for i in 0..=3 { | ||
//~^ ERROR mismatched types | ||
return false; | ||
} | ||
} | ||
|
||
fn atleast_once_iter_range_inclusive_neg() -> bool { | ||
for i in -3..=-1 { | ||
//~^ ERROR mismatched types | ||
return false; | ||
} | ||
} | ||
|
||
fn atleast_once_iter_infinite_range() -> bool { | ||
for i in 0.. { | ||
//~^ ERROR mismatched types | ||
return false; | ||
} | ||
} | ||
|
||
fn atleast_once_iter_infinite_range_neg() -> bool { | ||
for i in -3.. { | ||
//~^ ERROR mismatched types | ||
return false; | ||
} | ||
} | ||
|
||
fn atleast_once_iter_array() -> bool { | ||
for i in [1, 2, 3] { | ||
//~^ ERROR mismatched types | ||
return false; | ||
} | ||
} | ||
|
||
fn atleast_once_iter_array_ref() -> bool { | ||
for i in &[1, 2, 3] { | ||
//~^ ERROR mismatched types | ||
return false; | ||
} | ||
} | ||
|
||
|
||
// ----- Should emit note for these ----- | ||
fn zero_iter_range() -> bool { | ||
for i in 0..0 { | ||
//~^ ERROR mismatched types | ||
return false; | ||
} | ||
} | ||
|
||
fn zero_iter_array() -> bool { | ||
for i in [] { | ||
//~^ ERROR mismatched types | ||
return false; | ||
} | ||
} | ||
|
||
fn zero_iter_array_ref() -> bool { | ||
for i in &[] { | ||
//~^ ERROR mismatched types | ||
return false; | ||
} | ||
} | ||
|
||
// For the following cases the loop does iterate at | ||
// least once but we aren't currently smart enough | ||
// to not emit the note for them. We might add such | ||
// smarts in the future | ||
fn atlast_once_iter_array_var() -> bool { | ||
let x = [1, 2, 3]; | ||
for i in x { | ||
//~^ ERROR mismatched types | ||
return false; | ||
} | ||
} | ||
|
||
fn atleast_once_iter_vec() -> bool { | ||
for i in vec![1, 2, 3] { | ||
//~^ ERROR mismatched types | ||
return false; | ||
} | ||
} | ||
|
||
fn atleast_once_iter_array_iter() -> bool { | ||
for i in [1, 2, 3].iter() { | ||
//~^ ERROR mismatched types | ||
return false; | ||
} | ||
} | ||
|
||
fn atleast_once_iter_func_result() -> bool { | ||
for i in get_iter() { | ||
//~^ ERROR mismatched types | ||
return false; | ||
} | ||
} | ||
|
||
|
||
// Helper function | ||
fn get_iter() -> impl Iterator<Item=i32> { | ||
1.. | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.