-
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
Enforce the comma after lifetime arguments and before type arguments #24547
Conversation
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
self.last_token = if self.token.is_ident() || self.token.is_path() { | ||
self.last_token = if self.token.is_ident() || | ||
self.token.is_path() || | ||
self.token == token::Comma { |
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'm not sure about the performance impact of this bufferring.
I see I can modify parse_lifetimes
to avoid this, but that will look unnatural.
We may eventually need / want a help in the output reminding that |
type Type_1<'a T> = &'a T; //~ error: expected `,` or `>` after lifetime name, found `T` | ||
|
||
|
||
//type Type_2 = Type_1_<'static ()>; // error: expected `,` or `>` after lifetime name, found `(` |
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.
Why are these tests commented out?
Why are there nine compile-fail tests, with no header comment, that all appear similar (even duplicates?) based on a quick skim? Was that accidental? |
// except according to those terms. | ||
|
||
type MyType<'a, T> = &'a T; | ||
|
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.
Hmm, shouldn't these tests be checking (perhaps in addition) all the same cases when parsing MyOtherType<'a>
, with no type argument?
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.
Sorry that was phrased poorly; what I meant was that cases like Box <MyOtherType <'static>>
etc need checking too, with the >>
token after a lifetime, right?
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.
Ugh never mind again, you did check that, I just missed it twice
Because you cannot resume from parsing error, so I have to test different errors in separate files. I'll try suggesting |
Oh yes these 9 compile-fail files are similar intentionally, the difference is just that only one parsing error is uncommented at once. I'll add comments to make this clear. |
technically a breaking change, might want to edit the PR message to reflect that |
right. fixed. I'm trying to make a different approach, which will make catching the Currently I'm using I think we cannot pretty-print a type this early, so I will just make the codemap feels right, and use the first token to generate a note, e.g. suggest "do you mean Or am I missing something? Any suggestions, @pnkfelix ? |
@bombless oh yes, I do not object to being fairly generic in the help message; this would not be the first place that we've inserted |
@bombless as for catching the leading |
Okay I'll do that. |
Nits fixed, @pnkfelix |
☔ The latest upstream changes (presumably #24674) made this pull request unmergeable. Please resolve the merge conflicts. |
rebased |
Do you mean that there's other places in parser.rs need to print a generic type? I don't really understand this, sorry. |
@bombless Yeah, sorry, I can see that my use of the phrase "GenericType" can be easily misinterpreted there; it was the name I was referring to as being generic, not the type ... That is, I was trying to say this:
The main thing I would suggest is this: If you were literally suggesting that when
then I advise that you not use ellipses in that fashion, but instead use a placeholder name for the type that you cannot print. Like so:
where Update: Then again, maybe it is not feasible to attempt to try to plug in placeholders into the type arguments for
Update 2: In some ways the english text prefixing to the two suggestions in this final example output is just as important, or perhaps more important, than the suggestion itself, in that (I hope) it makes it much clearer why there is an ambiguity here as to what the original intent of the user was. |
⌛ Testing commit 0ad48e4 with merge 00c48d3... |
Closes #20616 It breaks code such as <https://github.com/rust-lang/rust/blob/c64feb63418fd05bd6e5adc6f9ad763aa6a594b1/src/librustc_typeck/check/method/suggest.rs#L367>, so this is a [breaking-change], you have to add missing comma after the last lifetime arguement now.
Rust now enforces a comma between lifetime and type, see rust-lang/rust#24547 for the change.
(potential future cleanup: maybe just get rid of the commented out cases in all the tests...) |
accepted for beta backport. |
Backported. |
Closes #20616
It breaks code such as
rust/src/librustc_typeck/check/method/suggest.rs
Line 367 in c64feb6