diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 92dd56f3d5894..36214dd1c3ed2 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -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 { - 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". diff --git a/tests/ui/extern/extern-single-quote-issue-147365.rs b/tests/ui/extern/extern-only-quotes-issue-147365.rs similarity index 63% rename from tests/ui/extern/extern-single-quote-issue-147365.rs rename to tests/ui/extern/extern-only-quotes-issue-147365.rs index b50016bd65f31..3a492b4fb4f86 100644 --- a/tests/ui/extern/extern-single-quote-issue-147365.rs +++ b/tests/ui/extern/extern-only-quotes-issue-147365.rs @@ -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() {} diff --git a/tests/ui/extern/extern-only-quotes-issue-147365.stderr b/tests/ui/extern/extern-only-quotes-issue-147365.stderr new file mode 100644 index 0000000000000..fabc0fd4916b7 --- /dev/null +++ b/tests/ui/extern/extern-only-quotes-issue-147365.stderr @@ -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`. diff --git a/tests/ui/extern/extern-single-quote-issue-147365.stderr b/tests/ui/extern/extern-single-quote-issue-147365.stderr deleted file mode 100644 index d761bc3ebf323..0000000000000 --- a/tests/ui/extern/extern-single-quote-issue-147365.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error[E0703]: invalid ABI: found `'` - --> $DIR/extern-single-quote-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: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0703`.