Skip to content

Conversation

Zoxc
Copy link
Contributor

@Zoxc Zoxc commented May 27, 2017

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.

@rust-highfive
Copy link
Contributor

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

@@ -2146,10 +2147,11 @@ impl<'a> LoweringContext<'a> {
// let result = match ::std::iter::IntoIterator::into_iter(<head>) {
// mut iter => {
// [opt_ident]: loop {
// match ::std::iter::Iterator::next(&mut iter) {
// ::std::option::Option::Some(<pat>) => <body>,
// let <pat> = match ::std::iter::Iterator::next(&mut iter) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@@ -452,12 +452,14 @@ enum Method { GET, POST }


E0297: r##"
#### Note: this error code is no longer emitted by the compiler.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rust-lang/compiler This is an annoying (lack of a?) convention - is there any consensus?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@eddyb eddyb added the S-waiting-on-crater Status: Waiting on a crater run to be completed. label May 27, 2017
@Mark-Simulacrum Mark-Simulacrum added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 28, 2017
@eddyb
Copy link
Member

eddyb commented May 28, 2017

Started crater run.

@eddyb
Copy link
Member

eddyb commented May 28, 2017

Crater report is pretty long, but by looking at non-root regressions I found something.

@eddyb eddyb removed the S-waiting-on-crater Status: Waiting on a crater run to be completed. label May 28, 2017

fn main() {
for i in 0..3 {
unsafe { std::mem::uninitialized() }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ().

@@ -2172,7 +2172,7 @@ impl<'a> LoweringContext<'a> {
// ::std::option::Option::Some(val) => val,
// ::std::option::Option::None => break
// };
// <body>
// <body>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not the same, ; corresponds to StmtSemi.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, there aren't really syntax for StmtExpr?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certain expressions (loops? not sure. maybe if too) don't require ; after them.


// Check that the tail statement in the body can be unit
for _ in 0..3 {
()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not that interesting, since it doesn't directly check for the property I care about, i.e. that non-() bodies are denied.

@steveklabnik
Copy link
Contributor

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

for _ in 0..3 {
()
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline, here and in the other test.

@eddyb eddyb added the S-waiting-on-crater Status: Waiting on a crater run to be completed. label Jun 1, 2017
@eddyb
Copy link
Member

eddyb commented Jun 1, 2017

Started a second crater run.

@eddyb
Copy link
Member

eddyb commented Jun 1, 2017

Second crater report is clean (modulo network errors)!

@eddyb eddyb removed the S-waiting-on-crater Status: Waiting on a crater run to be completed. label Jun 1, 2017
@Mark-Simulacrum
Copy link
Member

I believe the documentation still needs updating (#42265 (comment)) and @eddyb wanted a few changes made (#42265 (comment)).

@Zoxc
Copy link
Contributor Author

Zoxc commented Jun 4, 2017

Those have both been addressed.

@Mark-Simulacrum
Copy link
Member

Ah, okay. Thanks!

@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 4, 2017
@eddyb
Copy link
Member

eddyb commented Jun 4, 2017

@bors r+

@bors
Copy link
Collaborator

bors commented Jun 4, 2017

📌 Commit cfdbff7 has been approved by eddyb

@Mark-Simulacrum Mark-Simulacrum added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jun 4, 2017
@Mark-Simulacrum Mark-Simulacrum removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 4, 2017
@bors
Copy link
Collaborator

bors commented Jun 4, 2017

⌛ Testing commit cfdbff7 with merge 0b17b4c...

bors added a commit that referenced this pull request Jun 4, 2017
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.
@bors
Copy link
Collaborator

bors commented Jun 4, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: eddyb
Pushing 0b17b4c to master...

// ::std::option::Option::None => break
// }
// };
// SemiExpr(<body>);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is wrong, the statement used is a StmtExpr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants