about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorLeón Orell Valerian Liehr <me@fmease.dev>2025-09-10 21:41:00 +0200
committerLeón Orell Valerian Liehr <me@fmease.dev>2025-09-10 23:24:31 +0200
commitf5dad62d4cdf139fb1c6cf2fa24ac525167501cc (patch)
treec48e35ace7a7be49dc307bb9811ca0200b2abbc6 /compiler
parent1558e65c9eec9ee0309e1920266e0a4325b63784 (diff)
downloadrust-f5dad62d4cdf139fb1c6cf2fa24ac525167501cc.tar.gz
rust-f5dad62d4cdf139fb1c6cf2fa24ac525167501cc.zip
Less greedily parse `[const]` bounds
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_parse/src/parser/ty.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs
index 138e828a230..23aaafac934 100644
--- a/compiler/rustc_parse/src/parser/ty.rs
+++ b/compiler/rustc_parse/src/parser/ty.rs
@@ -1015,12 +1015,18 @@ impl<'a> Parser<'a> {
             || self.check(exp!(Tilde))
             || self.check_keyword(exp!(For))
             || self.check(exp!(OpenParen))
-            || self.check(exp!(OpenBracket))
+            || self.can_begin_maybe_const_bound()
             || self.check_keyword(exp!(Const))
             || self.check_keyword(exp!(Async))
             || self.check_keyword(exp!(Use))
     }
 
+    fn can_begin_maybe_const_bound(&mut self) -> bool {
+        self.check(exp!(OpenBracket))
+            && self.look_ahead(1, |t| t.is_keyword(kw::Const))
+            && self.look_ahead(2, |t| *t == token::CloseBracket)
+    }
+
     /// Parse a bound.
     ///
     /// ```ebnf
@@ -1199,10 +1205,7 @@ impl<'a> Parser<'a> {
             let span = tilde.to(self.prev_token.span);
             self.psess.gated_spans.gate(sym::const_trait_impl, span);
             BoundConstness::Maybe(span)
-        } else if self.check(exp!(OpenBracket))
-            && self.look_ahead(1, |t| t.is_keyword(kw::Const))
-            && self.look_ahead(2, |t| *t == token::CloseBracket)
-        {
+        } else if self.can_begin_maybe_const_bound() {
             let start = self.token.span;
             self.bump();
             self.expect_keyword(exp!(Const)).unwrap();