don't panic on extern with just multiple quotes in the name#147413
don't panic on extern with just multiple quotes in the name#147413bors merged 1 commit intorust-lang:masterfrom
Conversation
| /// If called on an empty ident, or with name just single quotes, returns an empty ident which is invalid. | ||
| /// Creating empty ident will trigger debug assertions. | ||
| /// Use `without_first_quote_checked` instead if not certain this will return valid ident. | ||
| pub fn without_first_quote(self) -> Ident { |
There was a problem hiding this comment.
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)
compiler/rustc_span/src/symbol.rs
Outdated
| /// Creating empty ident will trigger debug assertions. | ||
| /// Use `without_first_quote_checked` instead if not certain this will return valid ident. | ||
| pub fn without_first_quote(self) -> Ident { | ||
| Ident::new(Symbol::intern(self.as_str().trim_start_matches('\'')), self.span) |
There was a problem hiding this comment.
| 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)) |
similarly for the newly introduced function if it's even needed (I've only skimmed this PR).
There was a problem hiding this comment.
Yes, you're right I forgot that the function is without_first_quote. Let's verify that this doesn't introduce any weird regression as you mentioned though.
c8d0983 to
cb06d91
Compare
|
Now the |
|
CI should be sufficient, it runs most tests we're interested in for this sort of change. |
|
Thanks for catching this! r? fmease @bors r+ rollup |
…, 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`
Rollup of 7 pull requests Successful merges: - #145495 (Use declarative macro for `#[derive(TryFromU32)]`) - #147165 (test: Subtract code_offset from width for ui_testing) - #147354 (Fix wrong span for hightlight for duplicated diff lines) - #147395 (Improve diagnostics: update note and add help message) - #147396 (Fluent tidy improvements) - #147407 (Update books) - #147413 (don't panic on extern with just multiple quotes in the name) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #147413 - karolzwolak:extern-multiple-quotes, r=fmease don't panic on extern with just multiple quotes in the name Continues #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``
Rollup of 7 pull requests Successful merges: - rust-lang/rust#145495 (Use declarative macro for `#[derive(TryFromU32)]`) - rust-lang/rust#147165 (test: Subtract code_offset from width for ui_testing) - rust-lang/rust#147354 (Fix wrong span for hightlight for duplicated diff lines) - rust-lang/rust#147395 (Improve diagnostics: update note and add help message) - rust-lang/rust#147396 (Fluent tidy improvements) - rust-lang/rust#147407 (Update books) - rust-lang/rust#147413 (don't panic on extern with just multiple quotes in the name) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 7 pull requests Successful merges: - rust-lang/rust#145495 (Use declarative macro for `#[derive(TryFromU32)]`) - rust-lang/rust#147165 (test: Subtract code_offset from width for ui_testing) - rust-lang/rust#147354 (Fix wrong span for hightlight for duplicated diff lines) - rust-lang/rust#147395 (Improve diagnostics: update note and add help message) - rust-lang/rust#147396 (Fluent tidy improvements) - rust-lang/rust#147407 (Update books) - rust-lang/rust#147413 (don't panic on extern with just multiple quotes in the name) r? `@ghost` `@rustbot` modify labels: rollup
Continues #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