@@ -363,13 +363,15 @@ impl<'a> Parser<'a> {
363
363
let mut last_plus_span = None ;
364
364
let mut was_negative = false ;
365
365
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
+ }
373
375
374
376
if !allow_plus || !self . eat_plus ( ) {
375
377
break
@@ -436,21 +438,19 @@ impl<'a> Parser<'a> {
436
438
& mut self ,
437
439
colon_span : Option < Span > ,
438
440
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 > > > {
443
442
let lo = self . token . span ;
444
443
let has_parens = self . eat ( & token:: OpenDelim ( token:: Paren ) ) ;
445
444
let inner_lo = self . token . span ;
446
445
let is_negative = self . eat ( & token:: Not ) ;
447
446
let question = if self . eat ( & token:: Question ) { Some ( self . prev_span ) } else { None } ;
448
447
if self . token . is_lifetime ( ) {
449
448
self . error_opt_out_lifetime ( question) ;
450
- bounds . push ( GenericBound :: Outlives ( self . expect_lifetime ( ) ) ) ;
449
+ let bound = GenericBound :: Outlives ( self . expect_lifetime ( ) ) ;
451
450
if has_parens {
452
451
self . recover_paren_lifetime ( lo, inner_lo) ?;
453
452
}
453
+ Ok ( Ok ( bound) )
454
454
} else {
455
455
let lifetime_defs = self . parse_late_bound_lifetime_defs ( ) ?;
456
456
let path = self . parse_path ( PathStyle :: Type ) ?;
@@ -459,21 +459,17 @@ impl<'a> Parser<'a> {
459
459
}
460
460
let poly_span = lo. to ( self . prev_span ) ;
461
461
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) ) ) )
466
463
} else {
467
464
let poly_trait = PolyTraitRef :: new ( lifetime_defs, path, poly_span) ;
468
465
let modifier = if question. is_some ( ) {
469
466
TraitBoundModifier :: Maybe
470
467
} else {
471
468
TraitBoundModifier :: None
472
469
} ;
473
- bounds . push ( GenericBound :: Trait ( poly_trait, modifier) ) ;
470
+ Ok ( Ok ( GenericBound :: Trait ( poly_trait, modifier) ) )
474
471
}
475
472
}
476
- Ok ( ( ) )
477
473
}
478
474
479
475
fn error_opt_out_lifetime ( & self , question : Option < Span > ) {
0 commit comments