-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Opportunistically split !=
to successfully parse never type
#145536
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
base: master
Are you sure you want to change the base?
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
r? petrochenkov or reassign |
|
||
#[cfg(false)] struct W<const X: ! = { loop {} }>; | ||
#[cfg(false)] struct S<const X: != { loop {} }>; | ||
} |
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.
Maybe add this, too:
#![feature(default_field_values)]
struct X<T> {
w: fn(T) -> ! = |_| loop {},
s: fn(T) -> != |_| loop {},
}
Doesn't really matter tho.
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.
Yeah, let's add this one too.
5dd2c57
to
d1e84da
Compare
// Parse `!` | ||
// Ideally we'd use `eat_bang` here to allow us to parse `!=>` as `! =>`. However, | ||
// `break_and_eat` doesn't "reglue" the split-off `=` with any following `>` (since | ||
// that would likely be super fragile and complex). |
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.
It will probably work if the support is added to break_two_token_op
.
As this changes the language grammar, this will need a lang FCP. If you could talk a bit about the analysis and motivation here for the nomination, that would be helpful. This change would allow, e.g., let _: fn() -> != || loop {}; to be accepted both syntactically and semantically. It'd be good for us to find a way to document this in the Reference as well. cc @rust-lang/lang-docs (H/t to our lang advisor @ehuss for raising this.) |
Sorry for not getting back to you. To be honest, there's no practical motivation. However, I really liked what [@]ehuss wrote in rust-lang/reference#1983, however it's been two weeks since I last read it. I guess the general question is: Is there a more principled approach to this (not necessarily wrt. the implementation but also how we want to categorize or describe it in the Reference etc.) or do we "want to keep" adding these things in an ad hoc manner. A possible point of contention: It might hurt forward compatibility since it takes away a bit of whitespace sensitivity (Rust is obv. mostly whitespace insensitive but not fully). |
The more principled approach is to migrate rustc's parser to the single-character token model with Until then we need to consider cases like this as bugs and fix them when they are discovered. That matches what we did in practice in the previous years, all more popular multi-character tokens are already split in the parser when necessary. |
Makes sense. Good enough for me. @rfcbot fcp merge |
Team member @traviscross has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
My understanding from the lang team discussion is that this should be transparent to users at the lexing level and shouldn't limit us in the future (beyond the decision to support parsing this). @rfcbot reviewed |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
On the same assumption as Tyler, |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
Accept code like
let _: != loop {};
orlet _: fn() -> != || loop {};
(previously: syntax error). Similar to sth. like #51068.There's no inherent need to update
can_begin_type
from what I can tell, since macro matcher$ty:ty =
already accepts!=
(edit: this is not true actually, my bad, I don't know what snippet I tested to come to that conclusion) and since no other current direct/transitive callers would 'benefit' from doing that either, so I didn't do it. It's a conservative choice to avoid odd consequences (concrete example: it would widen the follow set of:vis
to include!=
).