-
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
Tracking Issue for RFC 3101: Reserved Prefixes #84978
Comments
@rustbot claim I'm interested at implementing this. But there are some questions.
Possible solutions:
(See also the discussion at zulip https://rust-lang.zulipchat.com/#narrow/stream/268952-edition-2021/topic/reserved.20prefixes/near/238470099.) |
This comment has been minimized.
This comment has been minimized.
Some relevant examples regarding string (and similarly char) literals – the first two copied from the linked zulip discussion (archive) – include match"foo" { _ => () }
if"foo".eq("foo") {}
while"foo".ne("foo") {}
if let"foo" = "foo" {}
loop {
break"foo"
};
for _ in"foo".chars() {}
return"foo" which raises the question whether we want to exclude all keywords or maybe certain keywords from the disallowed prefixes. |
Note that lexer isn't currently aware of the keyword list (*), and making it aware is a step in the wrong direction, IMO. (*) After all, every left-hand side of a macro is able to introduce its own syntax entirely independent from Rust syntax, with its own keyword list, and lexer works with macro inputs too. |
@petrochenkov I was wondering about "jointness". The idea here would be that we produce the same tokens, but in the Rust parser we check for (e.g.) |
Yeah, it should be applicable to |
@petrochenkov So do you mean that we should emit errors for reserved prefixes in the parser instead of the lexer? I think it does not solve the problem about But I think it sounds good because it can easily solve almost all problems pointed out by @steffahn . For example, we can distinguish lifetimes from string literals and we can also distinguish keywords from identifiers. And we can have better diagnostics messages like
But I've found currently parsing the macro arguments and expanding macros is done in |
Yes, at least for breakage-prone things like
Could you remind what is the problem with
String escaping is done during parsing (proc macros can do custom escaping in particular), so lexer doesn't need to discern between raw and non-raw strings unless
|
It does need to discern. Both |
We can certainly just accept that any future form of raw string will have to use |
@petrochenkov Thanks for your reply first.
We may get different results ( I'm not sure why you ask this. Maybe I misunderstood the problem?
Now the lexer reports the start position and the end position for every token, so it has to do some (although simplified) escaping, see rust/compiler/rustc_lexer/src/lib.rs Lines 653 to 671 in bf24e6b
If we check reserved prefixes in parser, I think the best place is in I will conduct more experiments on this, but now I'm curious about your opinions (if any). |
Note that the 'jointness' solution won't really work. That's exactly what we wanted to avoid by reserving prefixes in the lexer, to make sure we don't have to decide right now on the lexing rules for every possible prefix. As I wrote in #84979 (comment):
Also, this doesn't seem to be true:
Proc macros cannot accept string literals with escape sequences or characters that don't match the prefix. These errors are given without parsing: #[proc_macro]
pub fn hey(_: TokenStream) -> TokenStream {
TokenStream::new()
} hey!("\xFF");
hey!(b"å");
|
As for |
I wrote up a summary of what I believe to be the issues and concerns raised thus far: https://hackmd.io/YLe7viGLTu2PfE5sQO4v0w I think that, on balance, the right path is to continue with a hard lex error (also for keywords). I don't think the lexer should know about the keyword listing, but it would have to know about the edition. Is there any critical problem with this, @petrochenkov or @matklad? The downsides of using jointness information (and some unknowns) are covered in the hackmd. |
This seems to have already been completed. Apart from edition 2021 not being stable yet, this is stable. |
Re-opening as we have not made a stabilization decision here. Has there been a Rust reference PR? I drafted a stabilization report in this hackmd. |
@TriageBot release-assignment I don't believe @lrh2000 is still pushing this forward. |
@rustbot release-assignment |
Stabilization proposed in #88140 |
For the record, T-lang decided to retroactively reserve |
This is a tracking issue for the RFC "Reserved Prefixes" (rust-lang/rfcs#3101).
The feature gate for the issue is
#![feature(reserved_prefixes)]
.About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Steps
Unresolved Questions
proc_macro::TokenStream::from_str
, which does not take any edition information? (raised here) --> Discussed in Reserved Prefixes RFC: How to handleTokenStream::from_str
? #84979Implementation history
The text was updated successfully, but these errors were encountered: