Rollup merge of #147413 - karolzwolak:extern-multiple-quotes, r=fmease

don't panic on extern with just multiple quotes in the name

Continues rust-lang/rust#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``
This commit is contained in:
Matthias Krüger 2025-10-07 07:04:20 +02:00 committed by GitHub
commit 21bf6db483
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 41 additions and 19 deletions

View file

@ -2511,9 +2511,11 @@ impl Ident {
}
/// Creates a new ident with the same span and name with leading quote removed, if any.
/// If called on an empty ident, or with name just a single quote, returns an empty ident which is invalid.
/// Calling it on a `'` ident will return an empty ident, which triggers debug assertions.
pub fn without_first_quote(self) -> Ident {
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))
}
/// "Normalize" ident for use in comparisons using "item hygiene".

View file

@ -2,8 +2,12 @@
// https://github.com/rust-lang/rust/issues/147365
// Ensures we don't trigger debug assert by creating an empty Ident when determining whether
// the single quote is a raw lifetime.
// the quotes are a raw lifetime.
extern "'" {} //~ ERROR invalid ABI: found `'`
extern "''" {} //~ ERROR invalid ABI: found `''`
extern "'''" {} //~ ERROR invalid ABI: found `'''`
fn main() {}

View file

@ -0,0 +1,32 @@
error[E0703]: invalid ABI: found `'`
--> $DIR/extern-only-quotes-issue-147365.rs:7:8
|
LL | extern "'" {}
| ^^^ invalid ABI
|
= note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions
help: there's a similarly named valid ABI `C`
|
LL - extern "'" {}
LL + extern "C" {}
|
error[E0703]: invalid ABI: found `''`
--> $DIR/extern-only-quotes-issue-147365.rs:9:8
|
LL | extern "''" {}
| ^^^^ invalid ABI
|
= note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions
error[E0703]: invalid ABI: found `'''`
--> $DIR/extern-only-quotes-issue-147365.rs:11:8
|
LL | extern "'''" {}
| ^^^^^ invalid ABI
|
= note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0703`.

View file

@ -1,16 +0,0 @@
error[E0703]: invalid ABI: found `'`
--> $DIR/extern-single-quote-issue-147365.rs:7:8
|
LL | extern "'" {}
| ^^^ invalid ABI
|
= note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions
help: there's a similarly named valid ABI `C`
|
LL - extern "'" {}
LL + extern "C" {}
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0703`.