Move parse_remaining_bounds into a separate function
This commit is contained in:
parent
6e75def7db
commit
8838cd10f2
1 changed files with 21 additions and 20 deletions
|
@ -1365,18 +1365,15 @@ impl<'a> Parser<'a> {
|
||||||
match ty.node {
|
match ty.node {
|
||||||
// `(TY_BOUND_NOPAREN) + BOUND + ...`.
|
// `(TY_BOUND_NOPAREN) + BOUND + ...`.
|
||||||
TyKind::Path(None, ref path) if maybe_bounds => {
|
TyKind::Path(None, ref path) if maybe_bounds => {
|
||||||
self.bump(); // `+`
|
self.parse_remaining_bounds(Vec::new(), path.clone(), lo, true)?
|
||||||
let pt = PolyTraitRef::new(Vec::new(), path.clone(), lo.to(self.prev_span));
|
|
||||||
let mut bounds = vec![TraitTyParamBound(pt, TraitBoundModifier::None)];
|
|
||||||
bounds.append(&mut self.parse_ty_param_bounds()?);
|
|
||||||
TyKind::TraitObject(bounds)
|
|
||||||
}
|
}
|
||||||
TyKind::TraitObject(ref bounds)
|
TyKind::TraitObject(ref bounds)
|
||||||
if maybe_bounds && bounds.len() == 1 && !trailing_plus => {
|
if maybe_bounds && bounds.len() == 1 && !trailing_plus => {
|
||||||
self.bump(); // `+`
|
let path = match bounds[0] {
|
||||||
let mut bounds = bounds.clone();
|
TraitTyParamBound(ref pt, ..) => pt.trait_ref.path.clone(),
|
||||||
bounds.append(&mut self.parse_ty_param_bounds()?);
|
_ => self.bug("unexpected lifetime bound"),
|
||||||
TyKind::TraitObject(bounds)
|
};
|
||||||
|
self.parse_remaining_bounds(Vec::new(), path, lo, true)?
|
||||||
}
|
}
|
||||||
// `(TYPE)`
|
// `(TYPE)`
|
||||||
_ => TyKind::Paren(P(ty))
|
_ => TyKind::Paren(P(ty))
|
||||||
|
@ -1429,11 +1426,8 @@ impl<'a> Parser<'a> {
|
||||||
// Just a type path or bound list (trait object type) starting with a trait.
|
// Just a type path or bound list (trait object type) starting with a trait.
|
||||||
// `Type`
|
// `Type`
|
||||||
// `Trait1 + Trait2 + 'a`
|
// `Trait1 + Trait2 + 'a`
|
||||||
if allow_plus && self.eat(&token::BinOp(token::Plus)) {
|
if allow_plus && self.check(&token::BinOp(token::Plus)) {
|
||||||
let poly_trait = PolyTraitRef::new(Vec::new(), path, lo.to(self.prev_span));
|
self.parse_remaining_bounds(Vec::new(), path, lo, true)?
|
||||||
let mut bounds = vec![TraitTyParamBound(poly_trait, TraitBoundModifier::None)];
|
|
||||||
bounds.append(&mut self.parse_ty_param_bounds()?);
|
|
||||||
TyKind::TraitObject(bounds)
|
|
||||||
} else {
|
} else {
|
||||||
TyKind::Path(None, path)
|
TyKind::Path(None, path)
|
||||||
}
|
}
|
||||||
|
@ -1451,12 +1445,8 @@ impl<'a> Parser<'a> {
|
||||||
self.parse_ty_bare_fn(lifetime_defs)?
|
self.parse_ty_bare_fn(lifetime_defs)?
|
||||||
} else {
|
} else {
|
||||||
let path = self.parse_path(PathStyle::Type)?;
|
let path = self.parse_path(PathStyle::Type)?;
|
||||||
let poly_trait = PolyTraitRef::new(lifetime_defs, path, lo.to(self.prev_span));
|
let parse_plus = allow_plus && self.check(&token::BinOp(token::Plus));
|
||||||
let mut bounds = vec![TraitTyParamBound(poly_trait, TraitBoundModifier::None)];
|
self.parse_remaining_bounds(lifetime_defs, path, lo, parse_plus)?
|
||||||
if allow_plus && self.eat(&token::BinOp(token::Plus)) {
|
|
||||||
bounds.append(&mut self.parse_ty_param_bounds()?)
|
|
||||||
}
|
|
||||||
TyKind::TraitObject(bounds)
|
|
||||||
}
|
}
|
||||||
} else if self.eat_keyword(keywords::Impl) {
|
} else if self.eat_keyword(keywords::Impl) {
|
||||||
// FIXME: figure out priority of `+` in `impl Trait1 + Trait2` (#34511).
|
// FIXME: figure out priority of `+` in `impl Trait1 + Trait2` (#34511).
|
||||||
|
@ -1479,6 +1469,17 @@ impl<'a> Parser<'a> {
|
||||||
Ok(P(ty))
|
Ok(P(ty))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parse_remaining_bounds(&mut self, lifetime_defs: Vec<LifetimeDef>, path: ast::Path,
|
||||||
|
lo: Span, parse_plus: bool) -> PResult<'a, TyKind> {
|
||||||
|
let poly_trait_ref = PolyTraitRef::new(lifetime_defs, path, lo.to(self.prev_span));
|
||||||
|
let mut bounds = vec![TraitTyParamBound(poly_trait_ref, TraitBoundModifier::None)];
|
||||||
|
if parse_plus {
|
||||||
|
self.bump(); // `+`
|
||||||
|
bounds.append(&mut self.parse_ty_param_bounds()?);
|
||||||
|
}
|
||||||
|
Ok(TyKind::TraitObject(bounds))
|
||||||
|
}
|
||||||
|
|
||||||
fn maybe_recover_from_bad_type_plus(&mut self, allow_plus: bool, ty: &Ty) -> PResult<'a, ()> {
|
fn maybe_recover_from_bad_type_plus(&mut self, allow_plus: bool, ty: &Ty) -> PResult<'a, ()> {
|
||||||
// Do not add `+` to expected tokens.
|
// Do not add `+` to expected tokens.
|
||||||
if !allow_plus || self.token != token::BinOp(token::Plus) {
|
if !allow_plus || self.token != token::BinOp(token::Plus) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue