diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-03-22 05:12:51 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-03-27 07:39:15 +0100 |
| commit | f91de44d073e40d6d4682ad41d61cadcc0fcedeb (patch) | |
| tree | 72fce9edb228089cc8418571615e30baedfa19cc | |
| parent | aa4999ec6963162c38b74a4d50857d1cf2bfbc26 (diff) | |
| download | rust-f91de44d073e40d6d4682ad41d61cadcc0fcedeb.tar.gz rust-f91de44d073e40d6d4682ad41d61cadcc0fcedeb.zip | |
extract parse_generic_arg
| -rw-r--r-- | src/librustc_parse/parser/path.rs | 22 |
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); }; |
