Avoid creating an empty identifer in Symbol::to_ident_string.

Because that causes an assertion failure in debug builds.

Fixes #140884.
This commit is contained in:
Nicholas Nethercote 2025-05-21 13:28:08 +10:00
parent 59372f2c81
commit 1cc0e38fdc
4 changed files with 20 additions and 7 deletions

View file

@ -2592,7 +2592,8 @@ impl Symbol {
/// (`token_to_string`, `Ident::to_string`), except that symbols don't keep the rawness flag
/// or edition, so we have to guess the rawness using the global edition.
pub fn to_ident_string(self) -> String {
Ident::with_dummy_span(self).to_string()
// Avoid creating an empty identifier, because that asserts in debug builds.
if self == kw::Empty { String::new() } else { Ident::with_dummy_span(self).to_string() }
}
}

View file

@ -1,6 +0,0 @@
//@ known-bug: #140884
//@ needs-rustc-debug-assertions
fn a() {
extern "" {}
}

View file

@ -0,0 +1,3 @@
extern "" {} //~ ERROR invalid ABI: found ``
fn main() {}

View file

@ -0,0 +1,15 @@
error[E0703]: invalid ABI: found ``
--> $DIR/extern-empty-string-issue-140884.rs:1: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 "C" {}
| +
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0703`.