about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/expr.rs
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-06-20 16:36:35 -0400
committerMichael Goulet <michael@errs.io>2024-07-16 12:06:25 -0400
commitd0a1851ec2cf84bdb41bc4d788b3995a8463c543 (patch)
tree6b7333a6eb3800ad80d39cfb57080251d7e5db3d /compiler/rustc_parse/src/parser/expr.rs
parenta91f7d72f12efcc00ecf71591f066c534d45ddf7 (diff)
downloadrust-d0a1851ec2cf84bdb41bc4d788b3995a8463c543.tar.gz
rust-d0a1851ec2cf84bdb41bc4d788b3995a8463c543.zip
Deny keyword lifetimes pre-expansion
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs13
1 files changed, 10 insertions, 3 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index 4bd20be4171..0ba8c66f48f 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -2932,10 +2932,17 @@ impl<'a> Parser<'a> {
     }
 
     pub(crate) fn eat_label(&mut self) -> Option<Label> {
-        self.token.lifetime().map(|ident| {
+        if let Some(ident) = self.token.lifetime() {
+            // Disallow `'fn`, but with a better error message than `expect_lifetime`.
+            if ident.without_first_quote().is_reserved() {
+                self.dcx().emit_err(errors::InvalidLabel { span: ident.span, name: ident.name });
+            }
+
             self.bump();
-            Label { ident }
-        })
+            Some(Label { ident })
+        } else {
+            None
+        }
     }
 
     /// Parses a `match ... { ... }` expression (`match` token already eaten).