about summary refs log tree commit diff
path: root/src/librustc_parse/parser/path.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/librustc_parse/parser/path.rs')
-rw-r--r--src/librustc_parse/parser/path.rs22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/librustc_parse/parser/path.rs b/src/librustc_parse/parser/path.rs
index 90185642524..f6d0f27eb18 100644
--- a/src/librustc_parse/parser/path.rs
+++ b/src/librustc_parse/parser/path.rs
@@ -399,8 +399,7 @@ impl<'a> Parser<'a> {
 
     /// Parses a single argument in the angle arguments `<...>` of a path segment.
     fn parse_angle_arg(&mut self) -> PResult<'a, Option<AngleBracketedArg>> {
-        let arg = if self.check_ident()
-            && self.look_ahead(1, |t| matches!(t.kind, token::Eq | token::Colon))
+        if self.check_ident() && self.look_ahead(1, |t| matches!(t.kind, token::Eq | token::Colon))
         {
             // Parse associated type constraint.
             let lo = self.token.span;
@@ -422,10 +421,18 @@ impl<'a> Parser<'a> {
             }
 
             let constraint = AssocTyConstraint { id: ast::DUMMY_NODE_ID, ident, kind, span };
-            AngleBracketedArg::Constraint(constraint)
-        } else if self.check_lifetime() && self.look_ahead(1, |t| !t.is_like_plus()) {
+            Ok(Some(AngleBracketedArg::Constraint(constraint)))
+        } else {
+            Ok(self.parse_generic_arg()?.map(AngleBracketedArg::Arg))
+        }
+    }
+
+    /// Parse a generic argument in a path segment.
+    /// This does not include constraints, e.g., `Item = u8`, which is handled in `parse_angle_arg`.
+    fn parse_generic_arg(&mut self) -> PResult<'a, Option<GenericArg>> {
+        let arg = if self.check_lifetime() && self.look_ahead(1, |t| !t.is_like_plus()) {
             // Parse lifetime argument.
-            AngleBracketedArg::Arg(GenericArg::Lifetime(self.expect_lifetime()))
+            GenericArg::Lifetime(self.expect_lifetime())
         } else if self.check_const_arg() {
             // Parse const argument.
             let expr = if let token::OpenDelim(token::Brace) = self.token.kind {
@@ -451,11 +458,10 @@ impl<'a> Parser<'a> {
             } else {
                 self.parse_literal_maybe_minus()?
             };
-            let value = AnonConst { id: ast::DUMMY_NODE_ID, value: expr };
-            AngleBracketedArg::Arg(GenericArg::Const(value))
+            GenericArg::Const(AnonConst { id: ast::DUMMY_NODE_ID, value: expr })
         } else if self.check_type() {
             // Parse type argument.
-            AngleBracketedArg::Arg(GenericArg::Type(self.parse_ty()?))
+            GenericArg::Type(self.parse_ty()?)
         } else {
             return Ok(None);
         };