-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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
Implement raw lifetimes and labels ('r#ident
)
#126452
base: master
Are you sure you want to change the base?
Conversation
The only theoretical breakage is this: macro_rules! lt {
($lt:lifetime # $id:ident) => {}
}
lt!('r#a); edit: whoops, @fmease also notes that it breaks: #[cfg(any())] fn f<'async>(_: &'async ()) {} |
This comment has been minimized.
This comment has been minimized.
Also, this doesn't reserve all prefixed lifetimes -- it just implements |
rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead. cc @rust-lang/rust-analyzer Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt |
r-a and rustfmt changes are required due to changes to lexer and parser, respectively. |
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.
rustfmt changes look straightforward to me. Do you think it's worth adding a basic test in src/tools/rustfmt/tests/target
for these new raw lifetimes and labels?
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.
Oh good point. I have no idea if raw lifetimes even format correctly 😅
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.
🤞🏼fingers crossed they just work out of the box. Given the changes to the parser does the span include the whole 'r#label
or 'r#lifetime
?
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.
should include the whole span, so if we extract the lifetime name from the span (and not from the ident.name
Symbol
) then we should be fine 👍 I'll implement those tests tho
The job Click to see the possible cause of the failure (guessed by this bot)
|
@@ -1201,7 +1201,14 @@ impl<'a> Parser<'a> { | |||
|
|||
/// Parses a single lifetime `'a` or panics. | |||
pub(super) fn expect_lifetime(&mut self) -> Lifetime { | |||
if let Some(ident) = self.token.lifetime() { | |||
if let Some((ident, is_raw)) = self.token.lifetime() { |
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.
This PR also moves keyword lifetime validation (i.e. checking that we don't have something like 'async) from ast validation to the parser
For the T-lang meeting: Theoretical breakage of stable code:
#[cfg(any())] fn f<'async>(_: &'async ()) {}
@bors try |
Implement raw lifetimes and labels (`'r#ident`) This PR implements a syntax for raw lifetimes and labels as requested in rust-lang#126335. This PR also moves keyword lifetime validation (i.e. checking that we don't have something like `'async`) from ast validation to the parser, similar to how we handle raw identifiers, since we don't distinguish raw identifiers after parsing. This PR additionally extends the `keyword_idents_2024` lint to also check identifiers. cc `@traviscross` r? parser
☀️ Try build successful - checks-actions |
@craterbot check |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
|
There's a crate that specifically |
FWIW, as documented over https://docs.rs/with_locals/0.3.2/with_locals/index.html#remarks, the
|
@rustbot labels -I-lang-nominated We discussed this in the lang triage call today. We confirmed that we mean for all prefixed lifetimes to be reserved, not just Secondly, we confirmed that we're OK with moving the validation of keywords in lifetimes to pre-expansion from post-expansion. We similarly consider this a bug fix. While the breakage of the convenience feature of the Thanks in particular to @danielhenrymantilla for being responsive on this and understanding of the situation. |
This PR implements a syntax for raw lifetimes and labels as requested in #126335.
This PR also moves keyword lifetime validation (i.e. checking that we don't have something like
'async
) from ast validation to the parser, similar to how we handle raw identifiers, since we don't distinguish raw identifiers after parsing.This PR additionally extends the
keyword_idents_2024
lint to also check identifiers.cc @traviscross
r? parser