Skip to content

Commit 5b150e3

Browse files
authored
Rollup merge of #141318 - nnethercote:fix-140884, r=compiler-errors
Avoid creating an empty identifer in `Symbol::to_ident_string`. Because that causes an assertion failure in debug builds. Fixes #140884. r? `@oli-obk`
2 parents aaa684f + 1cc0e38 commit 5b150e3

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

compiler/rustc_span/src/symbol.rs

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

tests/crashes/140884.rs

Lines changed: 0 additions & 6 deletions
This file was deleted.
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)