@@ -363,13 +363,15 @@ impl<'a> Parser<'a> {
363363 let mut last_plus_span = None ;
364364 let mut was_negative = false ;
365365 while self . can_begin_bound ( ) {
366- self . parse_generic_bound (
367- colon_span,
368- last_plus_span,
369- & mut bounds,
370- & mut negative_bounds,
371- & mut was_negative,
372- ) ?;
366+ match self . parse_generic_bound ( colon_span, last_plus_span) ? {
367+ Ok ( bound) => bounds. push ( bound) ,
368+ Err ( neg_sp) => {
369+ was_negative = true ;
370+ if let Some ( neg_sp) = neg_sp {
371+ negative_bounds. push ( neg_sp) ;
372+ }
373+ }
374+ }
373375
374376 if !allow_plus || !self . eat_plus ( ) {
375377 break
@@ -436,21 +438,19 @@ impl<'a> Parser<'a> {
436438 & mut self ,
437439 colon_span : Option < Span > ,
438440 last_plus_span : Option < Span > ,
439- bounds : & mut Vec < GenericBound > ,
440- negative_bounds : & mut Vec < Span > ,
441- was_negative : & mut bool ,
442- ) -> PResult < ' a , ( ) > {
441+ ) -> PResult < ' a , Result < GenericBound , Option < Span > > > {
443442 let lo = self . token . span ;
444443 let has_parens = self . eat ( & token:: OpenDelim ( token:: Paren ) ) ;
445444 let inner_lo = self . token . span ;
446445 let is_negative = self . eat ( & token:: Not ) ;
447446 let question = if self . eat ( & token:: Question ) { Some ( self . prev_span ) } else { None } ;
448447 if self . token . is_lifetime ( ) {
449448 self . error_opt_out_lifetime ( question) ;
450- bounds . push ( GenericBound :: Outlives ( self . expect_lifetime ( ) ) ) ;
449+ let bound = GenericBound :: Outlives ( self . expect_lifetime ( ) ) ;
451450 if has_parens {
452451 self . recover_paren_lifetime ( lo, inner_lo) ?;
453452 }
453+ Ok ( Ok ( bound) )
454454 } else {
455455 let lifetime_defs = self . parse_late_bound_lifetime_defs ( ) ?;
456456 let path = self . parse_path ( PathStyle :: Type ) ?;
@@ -459,21 +459,17 @@ impl<'a> Parser<'a> {
459459 }
460460 let poly_span = lo. to ( self . prev_span ) ;
461461 if is_negative {
462- * was_negative = true ;
463- if let Some ( sp) = last_plus_span. or ( colon_span) {
464- negative_bounds. push ( sp. to ( poly_span) ) ;
465- }
462+ Ok ( Err ( last_plus_span. or ( colon_span) . map ( |sp| sp. to ( poly_span) ) ) )
466463 } else {
467464 let poly_trait = PolyTraitRef :: new ( lifetime_defs, path, poly_span) ;
468465 let modifier = if question. is_some ( ) {
469466 TraitBoundModifier :: Maybe
470467 } else {
471468 TraitBoundModifier :: None
472469 } ;
473- bounds . push ( GenericBound :: Trait ( poly_trait, modifier) ) ;
470+ Ok ( Ok ( GenericBound :: Trait ( poly_trait, modifier) ) )
474471 }
475472 }
476- Ok ( ( ) )
477473 }
478474
479475 fn error_opt_out_lifetime ( & self , question : Option < Span > ) {
0 commit comments