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>2025-04-04 21:36:03 +0000
committerMichael Goulet <michael@errs.io>2025-04-04 21:36:12 +0000
commit6dfbe7c986d55a5a48f625d37d4576092e5638eb (patch)
tree771866e17b0f65cdcf3977597fe066783cc005c5 /compiler/rustc_parse/src/parser/expr.rs
parent82eb03ec6220ee435e0e07fdaf3f0a68a79aab17 (diff)
downloadrust-6dfbe7c986d55a5a48f625d37d4576092e5638eb.tar.gz
rust-6dfbe7c986d55a5a48f625d37d4576092e5638eb.zip
Detect and provide suggestion for `&raw EXPR`
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index e1e6b93abf3..8ae660cb780 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -829,6 +829,18 @@ impl<'a> Parser<'a> {
         if let Some(lt) = lifetime {
             self.error_remove_borrow_lifetime(span, lt.ident.span.until(expr.span));
         }
+
+        // Add expected tokens if we parsed `&raw` as an expression.
+        // This will make sure we see "expected `const`, `mut`", and
+        // guides recovery in case we write `&raw expr`.
+        if borrow_kind == ast::BorrowKind::Ref
+            && mutbl == ast::Mutability::Not
+            && matches!(&expr.kind, ExprKind::Path(None, p) if p.is_ident(kw::Raw))
+        {
+            self.expected_token_types.insert(TokenType::KwMut);
+            self.expected_token_types.insert(TokenType::KwConst);
+        }
+
         Ok((span, ExprKind::AddrOf(borrow_kind, mutbl, expr)))
     }