extract parse_generic_arg
This commit is contained in:
parent
aa4999ec69
commit
f91de44d07
@ -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);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user