-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Recover invalid assoc type bounds using ==
#87566
Merged
bors
merged 2 commits into
rust-lang:master
from
JohnTitor:find-eqeq-on-assoc-type-bounds
Sep 17, 2021
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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,14 @@ | ||
pub trait MyTrait { | ||
type Assoc; | ||
} | ||
|
||
pub fn foo<S, T>(_s: S, _t: T) | ||
where | ||
S: MyTrait, | ||
T: MyTrait<Assoc == S::Assoc>, | ||
//~^ ERROR: expected one of `,` or `>`, found `==` | ||
//~| ERROR: this trait takes 0 generic arguments but 1 generic argument was supplied | ||
{ | ||
} | ||
|
||
fn main() {} |
This file contains 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,28 @@ | ||
error: expected one of `,` or `>`, found `==` | ||
--> $DIR/issue-87493.rs:8:22 | ||
| | ||
LL | T: MyTrait<Assoc == S::Assoc>, | ||
| ^^ expected one of `,` or `>` | ||
| | ||
help: if you meant to use an associated type binding, replace `==` with `=` | ||
| | ||
LL | T: MyTrait<Assoc = S::Assoc>, | ||
| ~ | ||
|
||
error[E0107]: this trait takes 0 generic arguments but 1 generic argument was supplied | ||
--> $DIR/issue-87493.rs:8:8 | ||
| | ||
LL | T: MyTrait<Assoc == S::Assoc>, | ||
| ^^^^^^^------------------- help: remove these generics | ||
| | | ||
| expected 0 generic arguments | ||
| | ||
note: trait defined here, with 0 generic parameters | ||
--> $DIR/issue-87493.rs:1:11 | ||
| | ||
LL | pub trait MyTrait { | ||
| ^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0107`. |
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.
I feel like this is the wrong place for this. Haven't dug into this, but I would have expected this to be in the same place as the associated type parsing code? There, we just "accept" with an error
==
when we really want=
.I guess this is potentially "ambiguous" if
Assoc == S::Assoc
gets treated as a const arg, which I guess is what currently happens.Is there anything we can to be smarter here? Would we theoretically be allowed to have a variable named
Assoc
? I'm trying to think of if we had complete knowledge of all traits, types, variables, etc. in scope, are there any cases where we can know if this should be a bracketed const expr arg or an associated type binding?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.
I got somewhat confused as to why we didn't have a
==
binop here, but looking at the surrounding code I can now see that we discard whatever op this was and what is being parsed here is the RHS, namely a single path. So I'm getting around to thinking that this is not a bad place to make this check.