-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
librustc: Remove for
desugaring
#15809
Conversation
check_match.rs will also have to be extended to look at ExprForLoop. |
If anyone else is confused why this diff-stat so large: the 500+ lines of the Iterator trait and its documentation have been duplicated purely for staging. |
Could you also add some tests that do things like implement |
@alexcrichton Yup, I was planning to do that before submitting the final. |
Why is the duplication necessary? The stage0 compiler should still be able to desugar the |
It now needs a lang item; and one would expect that unrecognised lang items are an error, meaning the stage0 compiler couldn't handle it. However, this doesn't seem to be the case (unrecognised lang items are silently ignored: http://is.gd/wfG8JS), so it does appear that the duplication is unnecessary. |
@huonw Hrm, I would have expected an unrecognized lang item to emit a warning (instead of an error). |
This is ready for initial review; there's still one borrow check test failing but it should be fairly easy to fix. r? @pnkfelix |
for
desugaringfor
desugaring
This is passing tests now. There are two bugs which I would like to fix in follow ups, as they are backwards compatible modulo gated features and don't impact much code (less than 10 occurrences in the whole codebase):
|
r? @pnkfelix |
@pcwalton make sure to update the description in this ticket, so that bors commit message doesn't say "WIP" and "do not merge yet". (or i am happy to update the description myself, if you would prefer to hand that off to me). |
@@ -1701,6 +1702,77 @@ fn try_overloaded_index(fcx: &FnCtxt, | |||
} | |||
} | |||
|
|||
/// Given the head of a `for` expression, looks up the `next` method in the | |||
/// `Iterator` trait. Fails if the expression does not implement `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.
On this comment, add a note to the effect that "the return type represents the concrete element type A
of in the Iterator<A>
that is producing the for loop's elements"
@pcwalton okay, LGTM. You can mark with r=me after you add the comment I asked for in src/librustc/middle/typeck/check/mod.rs |
This makes edge cases in which the `Iterator` trait was not in scope and/or `Option` or its variants were not in scope work properly. This breaks code that looks like: struct MyStruct { ... } impl MyStruct { fn next(&mut self) -> Option<int> { ... } } for x in MyStruct { ... } { ... } Change ad-hoc `next` methods like the above to implementations of the `Iterator` trait. For example: impl Iterator<int> for MyStruct { fn next(&mut self) -> Option<int> { ... } } Closes rust-lang#15392. [breaking-change]
librustc: Stop desugaring `for` expressions and translate them directly. This makes edge cases in which the `Iterator` trait was not in scope and/or `Option` or its variants were not in scope work properly. This breaks code that looks like: struct MyStruct { ... } impl MyStruct { fn next(&mut self) -> Option<int> { ... } } for x in MyStruct { ... } { ... } Change ad-hoc `next` methods like the above to implementations of the `Iterator` trait. For example: impl Iterator<int> for MyStruct { fn next(&mut self) -> Option<int> { ... } } Closes #15392. [breaking-change]
…, r=HKalbasi feat: make extract_variable assist in place ![extract_variable_without_select](https://github.com/rust-lang/rust-analyzer/assets/71162630/96be2de4-42c9-4b24-b3e1-8b3e3a2da1d9) close rust-lang/rust-analyzer#15796
librustc: Stop desugaring
for
expressions and translate them directly.This makes edge cases in which the
Iterator
trait was not in scopeand/or
Option
or its variants were not in scope work properly.This breaks code that looks like:
Change ad-hoc
next
methods like the above to implementations of theIterator
trait. For example:Closes #15392.
[breaking-change]