-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Tracking issue for RFC 2151, Raw Identifiers #48589
Comments
@Centril you rock! @petrochenkov, think you could supply some mentoring instructions here? |
I'd like to take a shot at this. It seems like it'd be a decent way to learn how rustc works. |
The relevant code is probably this, you'll want to make the We could add an You'll also need to feature gate this but we can do that later. lmk if you have questions |
This is possible, but would be unfortunate. Idents are used everywhere and supposed to be small. Ideally we should limit the effect of EDIT: The first paragraph is about |
Some clarifications are needed:
// `union` is a normal ident, this is not an error
union U {
....
}
// `union` is a raw ident, is this an error?
r#union U {
...
}
#[derive(Default)]
struct S;
impl S {
fn f() -> S {
r#Self::default() // Is this an error?
}
} |
oh, I didn't realize we reuse Ident from the lexer. I think I think it's ok for |
Also, lifetime identifiers weren't covered by the RFC - |
I think it's fine if we don't have raw lifetime identifiers. Lifetimes are crate-local, their identifiers never need to be used by consumers of your crate, so lifetimes clashing with keywords can simply be fixed on epochs. Admittedly, writing a lint that makes that automatic may be tricky. Raw identifiers are primarily necessary because people may need to call e.g. functions named |
Yeah, it's mostly a consistency question rather than a practical issue. |
From what I've been seeing while looking around the codebase, I think the best way to implement this is to add a new parameter to I think this would make implementing epoch-specific keywords easier, since there's no question of what My main questions, right now, would be:
I'll implement lifetime parameters if it turns out to be easy to, I guess. As Manishearth said, it's not something you really need to escape ever. |
Yes, we should not be affecting Symbol. Regarding the feature gate, we can solve the problem later, but I was thinking of doing a delayed error or something since we don't know what feature gates are available whilst lexing
I think that's fine. Folks usually do this as |
I think it's best if we don't allow this to work for lifetime parameters, actually. We restrict the number of places where raw identifiers are allowed at a first pass, and if we need this for a later epoch, we add it then |
But yeah, your plan sounds good otherwise |
.... right, that makes sense. The lexer obviously doesn't know what feature flags there are, because it's busy lexing them. :D |
In my opinion,
They are not special anymore.
Is this just about So e.g. cc @rust-lang/lang -- do others agree? |
@nikomatsakis That's exactly what I'd have expected. That said, I don't know what that means with macros, since apparently this works: macro_rules! foo {
($i:ident) => {
$i Foo {
x: u32,
y: i32,
}
}
}
foo!(union); (I wish it didn't, but it might be too late?) |
I hesitate about treating impl Foo {
fn foo(self, r#self: Bar) {
println!("I have distinct {} and {} at the same time?", self, r#self);
}
} Maybe that's in fact OK, but if so it's at least a corner case to test... (In general, |
@scottmcm I'd expect your |
I've found some other unexpected places where raw identifiers might show up while implementing this. Should these be allowed?
There's some weirdness with the built-in procedural macros taking raw identifiers too:
Also, |
Procedural macros see them after lexing, so that will Just Work. I don't think libproc_macro needs to know anything? Again, this is all after lexing. I personally think it's fine to allow all those. Simplifies things. |
This needs to know about the new field in |
Yeah, fair. As long as it's unstable we can tweak it.
८ मार्च, २०१८ १०:१५ म.उ. रोजी, "Lymia Aluysia" <notifications@github.com>
ने लिहिले:
… libproc_macro has an unstable enums that represent a token:
https://doc.rust-lang.org/nightly/proc_macro/enum.TokenNode.html
This needs to know about the new field in token::Ident to properly
serialize/deserialize it.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#48589 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABivSCOe13j2WQTrr0q94xEQlHXUW0aUks5tch4SgaJpZM4SVdSg>
.
|
Actually, checking on the playground, it looks like this isn't even unique to contextual keywords: https://play.rust-lang.org/?gist=98bba154f78cd9aba5838bf82ac2fbb4&version=stable |
Hrm, another strange case that came up while writing tests: Given this macro definition, which branch should macro_rules! test_macro {
(a) => { ... };
(r#a) => { ... };
} |
@nikomatsakis ^ ? Could even make this change based on the epoch. idk. |
macro matching is kinda-sorta-breakable already |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
You can't detect |
The final comment period, with a disposition to merge, as per the review above, is now complete. |
I've nominated this mostly so that someone (lang team, maybe) can find or select someone to write up docs and stabilize this feature. |
This is in need of a stabilization PR! There's a stabilization guide on the forge. This feature is already documented in the edition guide, so much of that documentation can probably be reused in the stabilization PRs. Please post here if you plan to take this issue! (I'll circulate it around and see if anyone wants to take it as a good first or third PR) |
I'll have a go. This looks pretty straightforward. |
When it comes to new documentation, is there anything that should be updated besides the Reference? I'm not sure it belongs in the Book. |
…mertj Stabilise raw_identifiers feature * [Reference PR](rust-lang/reference#395) * [Book PR](rust-lang/book#1480) * [Rust by Example PR](rust-lang/rust-by-example#1095) Closes rust-lang#48589. r? @cramertj CC @cuviper @Centril
…mertj Stabilise raw_identifiers feature * [Reference PR](rust-lang/reference#395) * [Book PR](rust-lang/book#1480) * [Rust by Example PR](rust-lang/rust-by-example#1095) Closes rust-lang#48589. r? @cramertj CC @cuviper @Centril
Stabilise raw_identifiers feature * [Reference PR](rust-lang/reference#395) * [Book PR](rust-lang/book#1480) * [Rust by Example PR](rust-lang/rust-by-example#1095) Closes #48589. r? @cramertj CC @cuviper @Centril
Merged! I think some boxes can be ticked off now, @Centril. :-) |
As for the unresolved questions:
|
For instance, if the |
@cuviper Right, makes sense. I think the rules should be the same as what I proposed for diagnostics, in that case. |
@Centril
The |
Inter-language-operability was not a goal of this RFC, it was purely limited to inter-edition-operability within Rust. AFAIK |
This is a tracking issue for RFC 2151 (rust-lang/rfcs#2151).
Steps:
Unresolved questions:
Probably not.
r#
syntax when printing identifiers that overlap keywords?Depends on the edition?
r#
syntax? e.g. to documentpub use old_epoch::*
The text was updated successfully, but these errors were encountered: