Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Member

@fmease fmease Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is called “without first quote”, it's meant to only remove the first quote. Good catch regarding trim_start_matches (I hope nobody in the compiler is "relying" on this behavior); so please replace it with strip_prefix if possible (see suggestion below)

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".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
32 changes: 32 additions & 0 deletions tests/ui/extern/extern-only-quotes-issue-147365.stderr
Original file line number Diff line number Diff line change
@@ -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`.
16 changes: 0 additions & 16 deletions tests/ui/extern/extern-single-quote-issue-147365.stderr

This file was deleted.

Loading