Skip to content

Commit e5fe68d

Browse files
nnethercotecuviper
authored andcommitted
Avoid creating an empty identifer in Symbol::to_ident_string.
Because that causes an assertion failure in debug builds. Fixes #140884. (cherry picked from commit 1cc0e38)
1 parent 281a202 commit e5fe68d

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

compiler/rustc_span/src/symbol.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2583,7 +2583,8 @@ impl Symbol {
25832583
/// (`token_to_string`, `Ident::to_string`), except that symbols don't keep the rawness flag
25842584
/// or edition, so we have to guess the rawness using the global edition.
25852585
pub fn to_ident_string(self) -> String {
2586-
Ident::with_dummy_span(self).to_string()
2586+
// Avoid creating an empty identifier, because that asserts in debug builds.
2587+
if self == kw::Empty { String::new() } else { Ident::with_dummy_span(self).to_string() }
25872588
}
25882589
}
25892590

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extern "" {} //~ ERROR invalid ABI: found ``
2+
3+
fn main() {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0703]: invalid ABI: found ``
2+
--> $DIR/extern-empty-string-issue-140884.rs:1:8
3+
|
4+
LL | extern "" {}
5+
| ^^ invalid ABI
6+
|
7+
= note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions
8+
help: there's a similarly named valid ABI `C`
9+
|
10+
LL | extern "C" {}
11+
| +
12+
13+
error: aborting due to 1 previous error
14+
15+
For more information about this error, try `rustc --explain E0703`.

0 commit comments

Comments
 (0)