-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Adjust spans into the for loops context before creating the new desugaring spans.
#148465
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
Open
Jarcho
wants to merge
1
commit into
rust-lang:master
Choose a base branch
from
Jarcho:for_span
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+94
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| macro_rules! deref { | ||
| ($e:expr) => { *$e }; | ||
| } | ||
|
|
||
| fn f1<'a>(mut iter: Box<dyn Iterator<Item=&'a mut u8>>) { | ||
| for item in deref!(iter) { *item = 0 } | ||
| //~^ ERROR `dyn Iterator<Item = &'a mut u8>` is not an iterator | ||
| } | ||
|
|
||
| fn f2(x: &mut i32) { | ||
| for _item in deref!(x) {} | ||
| //~^ ERROR `i32` is not an iterator | ||
| } | ||
|
|
||
| struct Wrapped(i32); | ||
|
|
||
| macro_rules! borrow_deref { | ||
| ($e:expr) => { &mut *$e }; | ||
| } | ||
|
|
||
| fn f3<'a>(mut iter: Box<dyn Iterator<Item=&'a mut i32>>) { | ||
| for Wrapped(item) in borrow_deref!(iter) { *item = 0 } | ||
| //~^ ERROR mismatched types | ||
| } | ||
|
|
||
| fn main() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| error[E0277]: `dyn Iterator<Item = &'a mut u8>` is not an iterator | ||
| --> $DIR/iter_from_mac_call.rs:6:17 | ||
| | | ||
| LL | for item in deref!(iter) { *item = 0 } | ||
| | ^^^^^^^^^^^^ the trait `IntoIterator` is not implemented for `dyn Iterator<Item = &'a mut u8>` | ||
| | | ||
| = note: the trait bound `dyn Iterator<Item = &'a mut u8>: IntoIterator` is not satisfied | ||
| = note: required for `dyn Iterator<Item = &'a mut u8>` to implement `IntoIterator` | ||
| help: consider mutably borrowing here | ||
| | | ||
| LL | for item in &mut deref!(iter) { *item = 0 } | ||
| | ++++ | ||
|
|
||
| error[E0277]: `i32` is not an iterator | ||
| --> $DIR/iter_from_mac_call.rs:11:18 | ||
| | | ||
| LL | for _item in deref!(x) {} | ||
| | ^^^^^^^^^ `i32` is not an iterator | ||
| | | ||
| = help: the trait `Iterator` is not implemented for `i32` | ||
| = note: if you want to iterate between `start` until a value `end`, use the exclusive range syntax `start..end` or the inclusive range syntax `start..=end` | ||
| = note: required for `i32` to implement `IntoIterator` | ||
|
|
||
| error[E0308]: mismatched types | ||
| --> $DIR/iter_from_mac_call.rs:22:9 | ||
| | | ||
| LL | for Wrapped(item) in borrow_deref!(iter) { *item = 0 } | ||
| | ^^^^^^^^^^^^^ ------------------- this is an iterator with items of type `&mut i32` | ||
| | | | ||
| | expected `i32`, found `Wrapped` | ||
|
|
||
| error: aborting due to 3 previous errors | ||
|
|
||
| Some errors have detailed explanations: E0277, E0308. | ||
| For more information about an error, try `rustc --explain E0277`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The currently failing
tests/ui/suggest-dereferences/invalid-suggest-deref-issue127590can be fixed by making a second mark rather than reusingfor_ctxt. I'm not exactly clear why this matters since the only change this makes is using two identical, but separateSyntaxContexts.Ideally only a single
SyntaxContextwould be created since there's only oneforloop.Uh oh!
There was an error while loading. Please reload this page.
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.
Narrowed this down to being different expansion call sites. If we replace the for loop with a call to
into_iterthen it always produces three diagnostics.Errors
The third error is filtered on for loops since when deduplicating obligation failures if the cause span is in a desugaring then the call site span is used instead. Originally the call site span for the
into_itercall is the head expression which causes it to be suppressed since this matches the second error. With this PR the call site span is the for loop itself which doesn't match the previous two errors.If this is actually a problem I can mark the head expression separately. I don't see this as too big of a deal since the second error will be present in either case and it's just as useless as the third one.