-
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
Change the for-loop desugar so the break
does not affect type inference. Fixes #42618
#42634
Conversation
r? @arielb1 (rust_highfive has picked a reviewer for you, use r? to override) |
This looks like a rather fragile area of code. I'm ok with the changes, but I'll rather r? @nikomatsakis |
@Zoxc can we add a run-pass test checking the order of drops with comments explaining the expected order? |
We probably would need this to be in relnotes, presuming it lands. Tagging it as such. |
@Zoxc can you also add a fn main() {
let mut sum = 0;
for i in Vec::new() {
sum += i;
}
} Similarly a fn main() {
for i in Vec::new() { } //~ ERROR type annotations needed
} r=me with those tests |
Removing relnotes, I didn't realize that this behavior had never contaminated stable. |
#42265 needs to be reverted from beta as this is applied |
@bors r+ |
📌 Commit e4baa26 has been approved by |
I took the liberty of adding a few comments to the test for posterity. |
@bors r- oops, forgot one test. |
@bors r+ |
📌 Commit f11cf60 has been approved by |
@bors r+ |
tidy error:
|
@@ -2170,11 +2170,13 @@ impl<'a> LoweringContext<'a> { | |||
// let result = match ::std::iter::IntoIterator::into_iter(<head>) { | |||
// mut iter => { | |||
// [opt_ident]: loop { | |||
// let <pat> = match ::std::iter::Iterator::next(&mut iter) { | |||
// ::std::option::Option::Some(val) => val, | |||
// let mut _next; |
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.
Does the _next
name disable a "unused mut" warning?
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.
It does
@bors r+ |
📌 Commit 1409e70 has been approved by |
Change the for-loop desugar so the `break` does not affect type inference. Fixes #42618 Rewrite the `for` loop desugaring to avoid contaminating the inference results. Under the older desugaring, `for x in vec![] { .. }` would erroneously type-check, even though the type of `vec![]` is unconstrained. (written by @nikomatsakis)
☀️ Test successful - status-appveyor, status-travis |
[beta] backports - #42785 - #42740 - #42735 - #42728 - #42695 - #42659 - #42634 - #42566 I just unilaterally accepted all the non-accepted nominations. Everything picked cleanly. Still testing locally. cc @rust-lang/compiler r? @alexcrichton
[beta] backports - #42785 - #42740 - #42735 - #42728 - #42695 - #42659 - #42634 - #42566 I just unilaterally accepted all the non-accepted nominations. Everything picked cleanly. Still testing locally. cc @rust-lang/compiler r? @alexcrichton
…ielb1 change binding name of for loop lowering to appease clippy With the latest change to for loop lowering (rust-lang#42634), a `_next` binding was introduced. Unfortunately, this [disturbs](https://github.com/Manishearth/rust-clippy/issues/1846) clippy's `used_underscore_binding` lint. This commit just renames the binding to `__next` so clippy will be happy. It should have no other effect.
Rewrite the
for
loop desugaring to avoid contaminating the inference results. Under the older desugaring,for x in vec![] { .. }
would erroneously type-check, even though the type ofvec![]
is unconstrained. (written by @nikomatsakis)