-
Notifications
You must be signed in to change notification settings - Fork 13k
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
change guarded string reserved tokens to #"
, ##"
, ###
#133924
Conversation
reserving `##` broke the peg proc macro
@rustbot labels +A-edition-2024 +T-lang +I-lang-nominated +I-lang-easy-decision After compiler review, please assign this to me. This is a reduction in what we're deciding to reserve, so we'll cover it in a lang meeting, but it should be an easy call. |
Is there something that makes |
@workingjubilee speaking only for myself, the second thing. I did a search trying to find It does bring up a good point, though: we could go all the way to |
In particular, we thought that even if it were to be used by someone, that it could be fixed by adding a space at the call site, but here, with |
My concern is more (heh) procedural: I am not certain if any sequence of tokens is significantly different from another when considering the fact that a proc macro1 can use that specific joined sequence as syntax. You can peer into Rust source strings if you want and implement logic that conditions on that within a proc macro. And more! You have all the magical powers of an impure, imperative language at your disposal. The input of function proc macros is not required to parse as Rust, only tokenize. So, accepting this PR kinda implies a precedent of extending our stability/migration policies to arbitrary syntax extensions to Rust. Meanwhile, the very purpose of editions is to allow some things to simply break, without migration:
So, the correct decision may be to simply allow the "break", then think a bit harder in the future about how to do "API evolution" for everyone's microcompilers. Instead of this PR as it stands, we would want a tweak of the rustfix and diagnostics... I think it should be possible to recognize we're in a span that is input to a function macro? Then maybe we would consider an RFC or something on a policy concerning stability expectations for proc macros2? Or not! Like, the vibe could go either way. This is a fairly harmless change in the reservation to make. I care more about bringing attention to "this decision seems like it has different premise from most stability/migration-related decisions" than what specific decision is made here: y'all can flip a coin if ya want. Footnotes
|
The problem here is not the addition of new syntax, but rather the removal of syntax (by reserving it). |
r? compiler |
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.
Will this need to be backported in order to make it to the 2024 ed release? I'm concerned about making these kind of changes to a brittle part of the lexer in a hurry :(
I'm not seeing any reasons this won't work as expected, but I'm feeling some unspecified unease that I can't put my finger on. It could be anything from my subconscious waiting for my brain to catch up, to the cold I'm recovering from, so I can't provide good feedback on an alternative.
@@ -415,8 +415,16 @@ impl Cursor<'_> { | |||
} | |||
|
|||
// Guarded string literal prefix: `#"` or `##` |
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 we update this comment?
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.
Yes. Will do
'#' if matches!( | ||
(self.first(), self.second()), | ||
// #" ##" ### | ||
('"', _) | ('#', '"') | ('#', '#') |
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.
Miiiildly concerned about the implicit interaction between parser and lexer with these now, given the new reserved syntax, but that goes beyond this PR and is more about the feature as a whole, and I'm not going to block that.
debug_assert!(self.prev() != '#'); | ||
|
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 this be replaced with a check of str_before
in maybe_report_guarded_str
?
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.
I don't think this check should exist at all, and I'm surprised it hasn't blown up yet. It will blow up on ####
if running in debug.
No; not right now at least. The edition will ship with Rust 1.85 which branches 2025-01-03. |
We talked about this in the lang call today. Our inclination was to keep the reservation for Niko raised an interesting idea, which is that similar to what we do with We're of course influenced here also by the fact that this feature does not appear to be documented or widely used. All that said, we wanted to touch base with the author of the See: |
As I explain in more detail on the rust-peg issue, the peg Definitely doesn't seem worth the effort adding workarounds for this if |
☔ The latest upstream changes (presumably #134414) made this pull request unmergeable. Please resolve the merge conflicts. |
@kevinmehall Thank you very much for your response! We try (to some degree) to think about macro breaking changes across edition boundaries, because one of the most complex parts of the edition mechanism is the ability to apply macros from one crate to code from another crate that may be using a different edition. As observed here, it isn't guaranteed (because proc macros in particular can do arbitrary things), but we try to watch for cases like this and coordinate. |
Closing this based on the feedback suggesting that we don't need to worry about |
reserving
##
broke the peg proc macrofixes #133887
cc @ehuss @traviscross
Tracking: