about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/expr.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-07-16 21:46:24 +0000
committerbors <bors@rust-lang.org>2024-07-16 21:46:24 +0000
commit7d356ebde329df5f38186efe3e7c5e8dabac7cb7 (patch)
tree314d1e77a6a89745c12133d1376ee5a3b9ee5f3e /compiler/rustc_parse/src/parser/expr.rs
parent032be6f7bbe091c7dfa29f115e94b9cc9bae1758 (diff)
parent7d534dd4eb176dc60f0ca4615ce5fb9c32313884 (diff)
downloadrust-7d356ebde329df5f38186efe3e7c5e8dabac7cb7.tar.gz
rust-7d356ebde329df5f38186efe3e7c5e8dabac7cb7.zip
Auto merge of #127831 - tgross35:rollup-c0j9n7b, r=tgross35
Rollup of 7 pull requests

Successful merges:

 - #124033 (Sync ar_archive_writer to LLVM 18.1.3)
 - #126699 (Delegation: support coercion for target expression)
 - #126762 (Deny keyword lifetimes pre-expansion)
 - #126967 (Promote the `wasm32-wasip2` target to Tier 2)
 - #127390 (Migrate `raw-dylib-inline-cross-dylib` and `raw-dylib-custom-dlltool` `run-make` tests to rmake)
 - #127501 (Invert infer `error_reporting` mod struture)
 - #127816 (Update method name to reflect changes to its internals)

r? `@ghost`
`@rustbot` modify labels: rollup
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).