Change for-loop desugar to not borrow the iterator during the loop#42265
Change for-loop desugar to not borrow the iterator during the loop#42265bors merged 1 commit intorust-lang:masterfrom
Conversation
|
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
src/librustc/hir/lowering.rs
Outdated
There was a problem hiding this comment.
This changes semantics, although I can't think of any situation in which this would fail.
FWIW when I asked about while let Some(x) = iter.next() - that would correspond to the old desugaring, not your new one, wouldn't it?
There was a problem hiding this comment.
@rust-lang/compiler This is an annoying (lack of a?) convention - is there any consensus?
There was a problem hiding this comment.
This seems to be what we have done in the past. I see some instances of ## and some with ####.
Personally, I long to get rid of --explain XXX and just have a "long error mode" in which the long explanations are emitted 'inline'. That would basically make this point irrelevant.
|
Started crater run. |
|
Crater report is pretty long, but by looking at non-root regressions I found something. |
There was a problem hiding this comment.
Not sure this makes sense? I'd rather have a compile-fail test checking there's a type mismatch when there's a body that's not ().
src/librustc/hir/lowering.rs
Outdated
There was a problem hiding this comment.
That's not the same, ; corresponds to StmtSemi.
There was a problem hiding this comment.
Yeah, there aren't really syntax for StmtExpr?
There was a problem hiding this comment.
Certain expressions (loops? not sure. maybe if too) don't require ; after them.
There was a problem hiding this comment.
That's not that interesting, since it doesn't directly check for the property I care about, i.e. that non-() bodies are denied.
|
I am not an expert on what's going on here but if we're changing the sugar, I would like to see https://doc.rust-lang.org/std/iter/#for-loops-and-intoiterator updated |
There was a problem hiding this comment.
Missing newline, here and in the other test.
|
Started a second crater run. |
|
Second crater report is clean (modulo network errors)! |
|
I believe the documentation still needs updating (#42265 (comment)) and @eddyb wanted a few changes made (#42265 (comment)). |
|
Those have both been addressed. |
|
Ah, okay. Thanks! |
|
@bors r+ |
|
📌 Commit cfdbff7 has been approved by |
Change for-loop desugar to not borrow the iterator during the loop This is enables the use of suspend points inside for-loops in movable generators. This is illegal in the current desugaring as `iter` is borrowed across the body.
|
☀️ Test successful - status-appveyor, status-travis |
| // ::std::option::Option::None => break | ||
| // } | ||
| // }; | ||
| // SemiExpr(<body>); |
There was a problem hiding this comment.
This comment is wrong, the statement used is a StmtExpr.
This is enables the use of suspend points inside for-loops in movable generators. This is illegal in the current desugaring as
iteris borrowed across the body.