-
Notifications
You must be signed in to change notification settings - Fork 13.8k
don't panic on extern with just multiple quotes in the name #147413
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
base: master
Are you sure you want to change the base?
Conversation
/// If called on an empty ident, or with name just single quotes, returns an empty ident which is invalid. | ||
/// Creating empty ident will trigger debug assertions. | ||
/// Use `without_first_quote_checked` instead if not certain this will return valid ident. | ||
pub fn without_first_quote(self) -> Ident { |
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 function is called “without first quote”, it's meant to only remove the first quote. Good catch regarding trim_start_matches
(I hope nobody in the compiler is "relying" on this behavior); so please replace it with strip_prefix
if possible (see suggestion below)
compiler/rustc_span/src/symbol.rs
Outdated
/// Creating empty ident will trigger debug assertions. | ||
/// Use `without_first_quote_checked` instead if not certain this will return valid ident. | ||
pub fn without_first_quote(self) -> Ident { | ||
Ident::new(Symbol::intern(self.as_str().trim_start_matches('\'')), self.span) |
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.
Ident::new(Symbol::intern(self.as_str().trim_start_matches('\'')), self.span) | |
self.as_str().strip_prefix('\'').map_or(self, |name| Ident::new(Symbol::intern(name), self.span)) |
similarly for the newly introduced function if it's even needed (I've only skimmed this PR).
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, you're right I forgot that the function is without_first_quote. Let's verify that this doesn't introduce any weird regression as you mentioned though.
c8d0983
to
cb06d91
Compare
Now the |
CI should be sufficient, it runs most tests we're interested in for this sort of change. |
Thanks for catching this! r? fmease @bors r+ rollup |
Continues #147377.
That PR fixed ICE when the extern name was a single quote
"'"
, but multiple quotes like"''"
cause the same problem.I had a random revelation that the trimming can remove more than one quote.
r? @nnethercote