about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-08-31 08:48:35 +0000
committerbors <bors@rust-lang.org>2024-08-31 08:48:35 +0000
commit9649706eada1b2c68cf6504356efb058f68ad739 (patch)
tree56962b1c7e8f6064ad1b13548feb2ec07b0e30be /compiler/rustc_parse/src
parentfa72f0763de6bc1596208fc1419883ce5aea0de4 (diff)
parent25e3b6641018a917c7e7bcbd1dfc593f15eeb6e3 (diff)
downloadrust-9649706eada1b2c68cf6504356efb058f68ad739.tar.gz
rust-9649706eada1b2c68cf6504356efb058f68ad739.zip
Auto merge of #129809 - matthiaskrgr:rollup-cyygnxh, r=matthiaskrgr
Rollup of 15 pull requests

Successful merges:

 - #120221 (Don't make statement nonterminals match pattern nonterminals)
 - #126183 (Separate core search logic with search ui)
 - #129123 (rustdoc-json: Add test for `Self` type)
 - #129366 (linker: Synchronize native library search in rustc and linker)
 - #129527 (Don't use `TyKind` in a lint)
 - #129534 (Deny `wasm_c_abi` lint to nudge the last 25%)
 - #129640 (Re-enable android tests/benches in alloc/core)
 - #129642 (Bump backtrace to 0.3.74~ish)
 - #129675 (allow BufReader::peek to be called on unsized types)
 - #129723 (Simplify some extern providers)
 - #129724 (Remove `Option<!>` return types.)
 - #129725 (Stop using `ty::GenericPredicates` for non-predicates_of queries)
 - #129731 (Allow running `./x.py test compiler`)
 - #129751 (interpret/visitor: make memory order iteration slightly more efficient)
 - #129754 (wasi: Fix sleeping for `Duration::MAX`)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse/src')
-rw-r--r--compiler/rustc_parse/src/parser/nonterminal.rs20
-rw-r--r--compiler/rustc_parse/src/parser/pat.rs6
-rw-r--r--compiler/rustc_parse/src/parser/path.rs5
3 files changed, 10 insertions, 21 deletions
diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs
index 999f6f0eeb0..e66d0df012b 100644
--- a/compiler/rustc_parse/src/parser/nonterminal.rs
+++ b/compiler/rustc_parse/src/parser/nonterminal.rs
@@ -86,25 +86,7 @@ impl<'a> Parser<'a> {
                 token::Interpolated(nt) => may_be_ident(nt),
                 _ => false,
             },
-            NonterminalKind::Pat(pat_kind) => match &token.kind {
-                // box, ref, mut, and other identifiers (can stricten)
-                token::Ident(..) | token::NtIdent(..) |
-                token::OpenDelim(Delimiter::Parenthesis) |  // tuple pattern
-                token::OpenDelim(Delimiter::Bracket) |      // slice pattern
-                token::BinOp(token::And) |                  // reference
-                token::BinOp(token::Minus) |                // negative literal
-                token::AndAnd |                             // double reference
-                token::Literal(_) |                         // literal
-                token::DotDot |                             // range pattern (future compat)
-                token::DotDotDot |                          // range pattern (future compat)
-                token::PathSep |                             // path
-                token::Lt |                                 // path (UFCS constant)
-                token::BinOp(token::Shl) => true,           // path (double UFCS)
-                // leading vert `|` or-pattern
-                token::BinOp(token::Or) => matches!(pat_kind, PatWithOr),
-                token::Interpolated(nt) => may_be_ident(nt),
-                _ => false,
-            },
+            NonterminalKind::Pat(pat_kind) => token.can_begin_pattern(pat_kind),
             NonterminalKind::Lifetime => match &token.kind {
                 token::Lifetime(_) | token::NtLifetime(..) => true,
                 _ => false,
diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs
index cc68ae237ba..8233f9a7943 100644
--- a/compiler/rustc_parse/src/parser/pat.rs
+++ b/compiler/rustc_parse/src/parser/pat.rs
@@ -444,7 +444,11 @@ impl<'a> Parser<'a> {
 
         let mut lo = self.token.span;
 
-        if self.token.is_keyword(kw::Let) && self.look_ahead(1, |tok| tok.can_begin_pattern()) {
+        if self.token.is_keyword(kw::Let)
+            && self.look_ahead(1, |tok| {
+                tok.can_begin_pattern(token::NtPatKind::PatParam { inferred: false })
+            })
+        {
             self.bump();
             self.dcx().emit_err(RemoveLet { span: lo });
             lo = self.token.span;
diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs
index d8bf10e6021..8ee40ecd77e 100644
--- a/compiler/rustc_parse/src/parser/path.rs
+++ b/compiler/rustc_parse/src/parser/path.rs
@@ -378,7 +378,10 @@ impl<'a> Parser<'a> {
                     if self.may_recover()
                         && prev_token_before_parsing == token::PathSep
                         && (style == PathStyle::Expr && self.token.can_begin_expr()
-                            || style == PathStyle::Pat && self.token.can_begin_pattern())
+                            || style == PathStyle::Pat
+                                && self.token.can_begin_pattern(token::NtPatKind::PatParam {
+                                    inferred: false,
+                                }))
                     {
                         snapshot = Some(self.create_snapshot_for_diagnostic());
                     }