Skip to content

Conversation

karolzwolak
Copy link
Member

@karolzwolak karolzwolak commented Oct 6, 2025

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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 6, 2025
/// 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 {
Copy link
Member

@fmease fmease Oct 6, 2025

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)

/// 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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).

Copy link
Member Author

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.

@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 6, 2025
@karolzwolak karolzwolak force-pushed the extern-multiple-quotes branch from c8d0983 to cb06d91 Compare October 6, 2025 20:19
@karolzwolak
Copy link
Member Author

karolzwolak commented Oct 6, 2025

Now the Ident::without_first_quote() will strip only the first quote -- not all leading quotes. It might be prudent to run some additional tests to make sure it doesn't break anything. I don't have the privileges nor the knowledge what try bot runs we could do though.

@fmease
Copy link
Member

fmease commented Oct 6, 2025

CI should be sufficient, it runs most tests we're interested in for this sort of change.

@fmease
Copy link
Member

fmease commented Oct 6, 2025

Thanks for catching this! r? fmease @bors r+ rollup

@bors
Copy link
Collaborator

bors commented Oct 6, 2025

📌 Commit cb06d91 has been approved by fmease

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants