about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-11-09 19:52:46 +0000
committerbors <bors@rust-lang.org>2024-11-09 19:52:46 +0000
commit4adafcf40aa6064d2bbcb44bc1a50b3b1e86e5e0 (patch)
treea0da7a51a5ccaeda83b15d2b7f866d08dcb4d8cd /compiler/rustc_parse/src
parentb026d85107d4c33e7d2571c70115a29a5d2a4cf5 (diff)
parent3aa1a247998c2fb4b13bdaf860ff132b78228510 (diff)
downloadrust-4adafcf40aa6064d2bbcb44bc1a50b3b1e86e5e0.tar.gz
rust-4adafcf40aa6064d2bbcb44bc1a50b3b1e86e5e0.zip
Auto merge of #132815 - matthiaskrgr:rollup-nti992u, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #132341 (Reject raw lifetime followed by `'`, like regular lifetimes do)
 - #132363 (Enforce that raw lifetimes must be valid raw identifiers)
 - #132744 (add regression test for #90781)
 - #132754 (Simplify the internal API for declaring command-line options)
 - #132772 (use `download-rustc="if-unchanged"` as a global default)
 - #132774 (Use lld with non-LLVM backends)
 - #132799 (Make `Ty::primitive_symbol` recognize `str`)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse/src')
-rw-r--r--compiler/rustc_parse/src/errors.rs8
-rw-r--r--compiler/rustc_parse/src/lexer/mod.rs14
2 files changed, 18 insertions, 4 deletions
diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs
index fdd500e90f8..7ec4ad6dc35 100644
--- a/compiler/rustc_parse/src/errors.rs
+++ b/compiler/rustc_parse/src/errors.rs
@@ -2019,6 +2019,14 @@ pub(crate) struct CannotBeRawIdent {
 }
 
 #[derive(Diagnostic)]
+#[diag(parse_cannot_be_raw_lifetime)]
+pub(crate) struct CannotBeRawLifetime {
+    #[primary_span]
+    pub span: Span,
+    pub ident: Symbol,
+}
+
+#[derive(Diagnostic)]
 #[diag(parse_keyword_lifetime)]
 pub(crate) struct KeywordLifetime {
     #[primary_span]
diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs
index d627ef3d2cb..226de65445c 100644
--- a/compiler/rustc_parse/src/lexer/mod.rs
+++ b/compiler/rustc_parse/src/lexer/mod.rs
@@ -294,15 +294,21 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
                     let prefix_span = self.mk_sp(start, ident_start);
 
                     if prefix_span.at_least_rust_2021() {
-                        let lifetime_name_without_tick = self.str_from(ident_start);
+                        let span = self.mk_sp(start, self.pos);
+
+                        let lifetime_name_without_tick = Symbol::intern(&self.str_from(ident_start));
+                        if !lifetime_name_without_tick.can_be_raw() {
+                            self.dcx().emit_err(errors::CannotBeRawLifetime { span, ident: lifetime_name_without_tick });
+                        }
+
                         // Put the `'` back onto the lifetime name.
-                        let mut lifetime_name = String::with_capacity(lifetime_name_without_tick.len() + 1);
+                        let mut lifetime_name = String::with_capacity(lifetime_name_without_tick.as_str().len() + 1);
                         lifetime_name.push('\'');
-                        lifetime_name += lifetime_name_without_tick;
+                        lifetime_name += lifetime_name_without_tick.as_str();
                         let sym = Symbol::intern(&lifetime_name);
 
                         // Make sure we mark this as a raw identifier.
-                        self.psess.raw_identifier_spans.push(self.mk_sp(start, self.pos));
+                        self.psess.raw_identifier_spans.push(span);
 
                         token::Lifetime(sym, IdentIsRaw::Yes)
                     } else {