diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-08 11:04:26 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-21 19:20:41 +0100 |
| commit | 18e5b2f98c7768f0342333e7b6bb6c506f663515 (patch) | |
| tree | 96a31526f5ab6f07b1204770d4c919731f126600 /src/librustc_parse/parser | |
| parent | 8a9a992a6430371cb71a8abddd6839f6f1dde699 (diff) | |
| download | rust-18e5b2f98c7768f0342333e7b6bb6c506f663515.tar.gz rust-18e5b2f98c7768f0342333e7b6bb6c506f663515.zip | |
functionalize parse_generic_bound
Diffstat (limited to 'src/librustc_parse/parser')
| -rw-r--r-- | src/librustc_parse/parser/ty.rs | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/src/librustc_parse/parser/ty.rs b/src/librustc_parse/parser/ty.rs index f0a1b36bc36..72f831aab06 100644 --- a/src/librustc_parse/parser/ty.rs +++ b/src/librustc_parse/parser/ty.rs @@ -363,13 +363,15 @@ impl<'a> Parser<'a> { let mut last_plus_span = None; let mut was_negative = false; while self.can_begin_bound() { - self.parse_generic_bound( - colon_span, - last_plus_span, - &mut bounds, - &mut negative_bounds, - &mut was_negative, - )?; + match self.parse_generic_bound(colon_span, last_plus_span)? { + Ok(bound) => bounds.push(bound), + Err(neg_sp) => { + was_negative = true; + if let Some(neg_sp) = neg_sp { + negative_bounds.push(neg_sp); + } + } + } if !allow_plus || !self.eat_plus() { break @@ -436,10 +438,7 @@ impl<'a> Parser<'a> { &mut self, colon_span: Option<Span>, last_plus_span: Option<Span>, - bounds: &mut Vec<GenericBound>, - negative_bounds: &mut Vec<Span>, - was_negative: &mut bool, - ) -> PResult<'a, ()> { + ) -> PResult<'a, Result<GenericBound, Option<Span>>> { let lo = self.token.span; let has_parens = self.eat(&token::OpenDelim(token::Paren)); let inner_lo = self.token.span; @@ -447,10 +446,11 @@ impl<'a> Parser<'a> { let question = if self.eat(&token::Question) { Some(self.prev_span) } else { None }; if self.token.is_lifetime() { self.error_opt_out_lifetime(question); - bounds.push(GenericBound::Outlives(self.expect_lifetime())); + let bound = GenericBound::Outlives(self.expect_lifetime()); if has_parens { self.recover_paren_lifetime(lo, inner_lo)?; } + Ok(Ok(bound)) } else { let lifetime_defs = self.parse_late_bound_lifetime_defs()?; let path = self.parse_path(PathStyle::Type)?; @@ -459,10 +459,7 @@ impl<'a> Parser<'a> { } let poly_span = lo.to(self.prev_span); if is_negative { - *was_negative = true; - if let Some(sp) = last_plus_span.or(colon_span) { - negative_bounds.push(sp.to(poly_span)); - } + Ok(Err(last_plus_span.or(colon_span).map(|sp| sp.to(poly_span)))) } else { let poly_trait = PolyTraitRef::new(lifetime_defs, path, poly_span); let modifier = if question.is_some() { @@ -470,10 +467,9 @@ impl<'a> Parser<'a> { } else { TraitBoundModifier::None }; - bounds.push(GenericBound::Trait(poly_trait, modifier)); + Ok(Ok(GenericBound::Trait(poly_trait, modifier))) } } - Ok(()) } fn error_opt_out_lifetime(&self, question: Option<Span>) { |
