-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not emit note in coerce if loop iterates at least once #122679
Conversation
rustbot has assigned @compiler-errors. Use r? to explicitly pick a reviewer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should be suppressing this without replacing it with a better error message and suggestion.
For example, we should explain why Rust doesn't know that 0..10
won't loop at least once, and perhaps we should suggest adding an unreachable!("...")
after the loop?
Agreed. I'll make the changes. |
☔ The latest upstream changes (presumably #120926) made this pull request unmergeable. Please resolve the merge conflicts. |
e2c6942
to
0d52c10
Compare
This comment has been minimized.
This comment has been minimized.
Actually, the fn infinite() -> bool {
for _i in 0.. {
return false;
}
}
fn finite_atleast_once() -> bool {
for _i in 0..3 {
return false;
}
}
fn zero_times() -> bool {
for _i in 0..0 {
return false;
}
} (Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=49c635d409f3f5bd70031d89d183edf4) The error actually stems from the fn func() -> bool {
{
let _t =
match #[lang = "into_iter"](#[lang = "Range"]{
start: ...,
end: ...,}) {
mut iter =>
loop {
match #[lang = "next"](&mut iter) {
#[lang = "None"] {} => break,
#[lang = "Some"] { 0: i } => { return false; }
}
},
};
_t
}
} As you can see, the type of the tail expr Given that, the current note, I will open a different PR with that change and close this one. |
0d52c10
to
fa374a8
Compare
Here's the new PR: #123125 |
…iters-2, r=estebank Remove suggestion about iteration count in coerce Fixes rust-lang#122561 The iteration count-centric suggestion was implemented in PR rust-lang#100094, but it was based on the wrong assumption that the type mismatch error depends on the number of times the loop iterates. As it turns out, that is not true (see this comment for details: rust-lang#122679 (comment)) This PR attempts to remedy the situation by changing the suggestion from the one centered on iteration count to a simple suggestion to add a return value. It should also fix rust-lang#100285 by simply making it redundant.
…iters-2, r=estebank Remove suggestion about iteration count in coerce Fixes rust-lang#122561 The iteration count-centric suggestion was implemented in PR rust-lang#100094, but it was based on the wrong assumption that the type mismatch error depends on the number of times the loop iterates. As it turns out, that is not true (see this comment for details: rust-lang#122679 (comment)) This PR attempts to remedy the situation by changing the suggestion from the one centered on iteration count to a simple suggestion to add a return value. It should also fix rust-lang#100285 by simply making it redundant.
…r=estebank Remove suggestion about iteration count in coerce Fixes #122561 The iteration count-centric suggestion was implemented in PR #100094, but it was based on the wrong assumption that the type mismatch error depends on the number of times the loop iterates. As it turns out, that is not true (see this comment for details: rust-lang/rust#122679 (comment)) This PR attempts to remedy the situation by changing the suggestion from the one centered on iteration count to a simple suggestion to add a return value. It should also fix #100285 by simply making it redundant.
…r=estebank Remove suggestion about iteration count in coerce Fixes #122561 The iteration count-centric suggestion was implemented in PR #100094, but it was based on the wrong assumption that the type mismatch error depends on the number of times the loop iterates. As it turns out, that is not true (see this comment for details: rust-lang/rust#122679 (comment)) This PR attempts to remedy the situation by changing the suggestion from the one centered on iteration count to a simple suggestion to add a return value. It should also fix #100285 by simply making it redundant.
…r=estebank Remove suggestion about iteration count in coerce Fixes #122561 The iteration count-centric suggestion was implemented in PR #100094, but it was based on the wrong assumption that the type mismatch error depends on the number of times the loop iterates. As it turns out, that is not true (see this comment for details: rust-lang/rust#122679 (comment)) This PR attempts to remedy the situation by changing the suggestion from the one centered on iteration count to a simple suggestion to add a return value. It should also fix #100285 by simply making it redundant.
Fixes #122561
The fix is a bit conservative. It covers only the cases when it is easy to deduce the loop iteration count such as when the expr iterated over is a range or an array literal. It does not cover more involved cases such as when it is a local, a vec or a method call.