Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for RFC 2151, Raw Identifiers #48589
Comments
Centril
added
B-RFC-approved
T-lang
C-tracking-issue
labels
Feb 27, 2018
This comment has been minimized.
This comment has been minimized.
|
@Centril you rock! @petrochenkov, think you could supply some mentoring instructions here? |
This comment has been minimized.
This comment has been minimized.
|
I'd like to take a shot at this. It seems like it'd be a decent way to learn how rustc works. |
This comment has been minimized.
This comment has been minimized.
|
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 comment has been minimized.
This comment has been minimized.
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 |
This comment has been minimized.
This comment has been minimized.
|
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?
}
} |
This comment has been minimized.
This comment has been minimized.
|
oh, I didn't realize we reuse Ident from the lexer. I think I think it's ok for |
This comment has been minimized.
This comment has been minimized.
|
Also, lifetime identifiers weren't covered by the RFC - |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
Yeah, it's mostly a consistency question rather than a practical issue. |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
But yeah, your plan sounds good otherwise |
This comment has been minimized.
This comment has been minimized.
|
.... right, that makes sense. The lexer obviously doesn't know what feature flags there are, because it's busy lexing them. :D |
This comment has been minimized.
This comment has been minimized.
|
In my opinion,
They are not special anymore.
Is this just about So e.g. cc @rust-lang/lang -- do others agree? |
This comment has been minimized.
This comment has been minimized.
|
@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?) |
This comment has been minimized.
This comment has been minimized.
|
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, |
This comment has been minimized.
This comment has been minimized.
|
@scottmcm I'd expect your |
This comment has been minimized.
This comment has been minimized.
|
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, |
This comment has been minimized.
This comment has been minimized.
|
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 comment has been minimized.
This comment has been minimized.
|
This needs to know about the new field in |
This comment has been minimized.
This comment has been minimized.
|
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>
.
|
This comment has been minimized.
This comment has been minimized.
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 |
This comment has been minimized.
This comment has been minimized.
|
Hrm, another strange case that came up while writing tests: Given this macro definition, which branch should macro_rules! test_macro {
(a) => { ... };
(r#a) => { ... };
} |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis ^ ? Could even make this change based on the epoch. idk. |
This comment has been minimized.
This comment has been minimized.
|
macro matching is kinda-sorta-breakable already |
This comment has been minimized.
This comment has been minimized.
|
Oh, I see what you mean. I meant that Looking at the implementation it seems to be fine. |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Jul 24, 2018
|
|
rfcbot
added
final-comment-period
and removed
proposed-final-comment-period
labels
Jul 24, 2018
This comment has been minimized.
This comment has been minimized.
|
You can't detect |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Aug 3, 2018
|
The final comment period, with a disposition to merge, as per the review above, is now complete. |
rfcbot
added
finished-final-comment-period
and removed
final-comment-period
labels
Aug 3, 2018
Mark-Simulacrum
added
I-nominated
P-high
labels
Aug 7, 2018
This comment has been minimized.
This comment has been minimized.
|
I've nominated this mostly so that someone (lang team, maybe) can find or select someone to write up docs and stabilize this feature. |
cramertj
self-assigned this
Aug 9, 2018
cramertj
added
E-easy
E-mentor
labels
Aug 9, 2018
This comment has been minimized.
This comment has been minimized.
|
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) |
This comment has been minimized.
This comment has been minimized.
|
I'll have a go. This looks pretty straightforward. |
This comment has been minimized.
This comment has been minimized.
|
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. |
kennytm
added a commit
to kennytm/rust
that referenced
this issue
Aug 10, 2018
Centril
removed
the
I-nominated
label
Aug 11, 2018
kennytm
added a commit
to kennytm/rust
that referenced
this issue
Aug 11, 2018
kennytm
added a commit
to kennytm/rust
that referenced
this issue
Aug 11, 2018
kennytm
added a commit
to kennytm/rust
that referenced
this issue
Aug 11, 2018
kennytm
added a commit
to kennytm/rust
that referenced
this issue
Aug 13, 2018
bors
added a commit
that referenced
this issue
Aug 21, 2018
bors
closed this
in
#53236
Aug 21, 2018
This comment has been minimized.
This comment has been minimized.
|
Merged! I think some boxes can be ticked off now, @Centril. :-) |
This comment has been minimized.
This comment has been minimized.
|
As for the unresolved questions:
|
This comment has been minimized.
This comment has been minimized.
For instance, if the |
This comment has been minimized.
This comment has been minimized.
|
@cuviper Right, makes sense. I think the rules should be the same as what I proposed for diagnostics, in that case. |
Centril commentedFeb 27, 2018
•
edited
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::*