split parse_angle_args into loop / single step
This commit is contained in:
parent
91194f795c
commit
abce4881e0
1 changed files with 67 additions and 63 deletions
|
@ -388,10 +388,20 @@ impl<'a> Parser<'a> {
|
|||
/// possibly including trailing comma.
|
||||
fn parse_angle_args(&mut self) -> PResult<'a, Vec<AngleBracketedArg>> {
|
||||
let mut args = Vec::new();
|
||||
loop {
|
||||
if self.check_lifetime() && self.look_ahead(1, |t| !t.is_like_plus()) {
|
||||
while let Some(arg) = self.parse_angle_arg()? {
|
||||
args.push(arg);
|
||||
if !self.eat(&token::Comma) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Ok(args)
|
||||
}
|
||||
|
||||
/// 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_lifetime() && self.look_ahead(1, |t| !t.is_like_plus()) {
|
||||
// Parse lifetime argument.
|
||||
args.push(AngleBracketedArg::Arg(GenericArg::Lifetime(self.expect_lifetime())));
|
||||
AngleBracketedArg::Arg(GenericArg::Lifetime(self.expect_lifetime()))
|
||||
} else if self.check_ident()
|
||||
&& self.look_ahead(1, |t| matches!(t.kind, token::Eq | token::Colon))
|
||||
{
|
||||
|
@ -415,7 +425,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
let constraint = AssocTyConstraint { id: ast::DUMMY_NODE_ID, ident, kind, span };
|
||||
args.push(AngleBracketedArg::Constraint(constraint));
|
||||
AngleBracketedArg::Constraint(constraint)
|
||||
} else if self.check_const_arg() {
|
||||
// Parse const argument.
|
||||
let expr = if let token::OpenDelim(token::Brace) = self.token.kind {
|
||||
|
@ -442,19 +452,13 @@ impl<'a> Parser<'a> {
|
|||
self.parse_literal_maybe_minus()?
|
||||
};
|
||||
let value = AnonConst { id: ast::DUMMY_NODE_ID, value: expr };
|
||||
args.push(AngleBracketedArg::Arg(GenericArg::Const(value)));
|
||||
AngleBracketedArg::Arg(GenericArg::Const(value))
|
||||
} else if self.check_type() {
|
||||
// Parse type argument.
|
||||
args.push(AngleBracketedArg::Arg(GenericArg::Type(self.parse_ty()?)));
|
||||
AngleBracketedArg::Arg(GenericArg::Type(self.parse_ty()?))
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
if !self.eat(&token::Comma) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(args)
|
||||
return Ok(None);
|
||||
};
|
||||
Ok(Some(arg))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue