Skip to content

Commit 21bf6db

Browse files
authored
Rollup merge of rust-lang#147413 - karolzwolak:extern-multiple-quotes, r=fmease
don't panic on extern with just multiple quotes in the name Continues rust-lang#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``
2 parents 0471a58 + cb06d91 commit 21bf6db

File tree

4 files changed

+41
-19
lines changed

4 files changed

+41
-19
lines changed

compiler/rustc_span/src/symbol.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,9 +2511,11 @@ impl Ident {
25112511
}
25122512

25132513
/// Creates a new ident with the same span and name with leading quote removed, if any.
2514-
/// If called on an empty ident, or with name just a single quote, returns an empty ident which is invalid.
2514+
/// Calling it on a `'` ident will return an empty ident, which triggers debug assertions.
25152515
pub fn without_first_quote(self) -> Ident {
2516-
Ident::new(Symbol::intern(self.as_str().trim_start_matches('\'')), self.span)
2516+
self.as_str()
2517+
.strip_prefix('\'')
2518+
.map_or(self, |name| Ident::new(Symbol::intern(name), self.span))
25172519
}
25182520

25192521
/// "Normalize" ident for use in comparisons using "item hygiene".

tests/ui/extern/extern-single-quote-issue-147365.rs renamed to tests/ui/extern/extern-only-quotes-issue-147365.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
// https://github.com/rust-lang/rust/issues/147365
44
// Ensures we don't trigger debug assert by creating an empty Ident when determining whether
5-
// the single quote is a raw lifetime.
5+
// the quotes are a raw lifetime.
66

77
extern "'" {} //~ ERROR invalid ABI: found `'`
88

9+
extern "''" {} //~ ERROR invalid ABI: found `''`
10+
11+
extern "'''" {} //~ ERROR invalid ABI: found `'''`
12+
913
fn main() {}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error[E0703]: invalid ABI: found `'`
2+
--> $DIR/extern-only-quotes-issue-147365.rs:7: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 "'" {}
11+
LL + extern "C" {}
12+
|
13+
14+
error[E0703]: invalid ABI: found `''`
15+
--> $DIR/extern-only-quotes-issue-147365.rs:9:8
16+
|
17+
LL | extern "''" {}
18+
| ^^^^ invalid ABI
19+
|
20+
= note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions
21+
22+
error[E0703]: invalid ABI: found `'''`
23+
--> $DIR/extern-only-quotes-issue-147365.rs:11:8
24+
|
25+
LL | extern "'''" {}
26+
| ^^^^^ invalid ABI
27+
|
28+
= note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions
29+
30+
error: aborting due to 3 previous errors
31+
32+
For more information about this error, try `rustc --explain E0703`.

tests/ui/extern/extern-single-quote-issue-147365.stderr

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)