@@ -1794,7 +1794,7 @@ impl<'a> Parser<'a> {
1794
1794
let mut bounds = vec ! [ GenericBound :: Trait ( poly_trait_ref, TraitBoundModifier :: None ) ] ;
1795
1795
if parse_plus {
1796
1796
self . eat_plus ( ) ; // `+`, or `+=` gets split and `+` is discarded
1797
- bounds. append ( & mut self . parse_generic_bounds ( None ) ?) ;
1797
+ bounds. append ( & mut self . parse_generic_bounds ( Some ( self . prev_span ) ) ?) ;
1798
1798
}
1799
1799
Ok ( TyKind :: TraitObject ( bounds, TraitObjectSyntax :: None ) )
1800
1800
}
@@ -5502,6 +5502,7 @@ impl<'a> Parser<'a> {
5502
5502
let mut bounds = Vec :: new ( ) ;
5503
5503
let mut negative_bounds = Vec :: new ( ) ;
5504
5504
let mut last_plus_span = None ;
5505
+ let mut was_negative = false ;
5505
5506
loop {
5506
5507
// This needs to be synchronized with `Token::can_begin_bound`.
5507
5508
let is_bound_start = self . check_path ( ) || self . check_lifetime ( ) ||
@@ -5546,9 +5547,10 @@ impl<'a> Parser<'a> {
5546
5547
}
5547
5548
let poly_span = lo. to ( self . prev_span ) ;
5548
5549
if is_negative {
5549
- negative_bounds. push (
5550
- last_plus_span. or ( colon_span) . unwrap ( )
5551
- . to ( poly_span) ) ;
5550
+ was_negative = true ;
5551
+ if let Some ( sp) = last_plus_span. or ( colon_span) {
5552
+ negative_bounds. push ( sp. to ( poly_span) ) ;
5553
+ }
5552
5554
} else {
5553
5555
let poly_trait = PolyTraitRef :: new ( lifetime_defs, path, poly_span) ;
5554
5556
let modifier = if question. is_some ( ) {
@@ -5570,26 +5572,28 @@ impl<'a> Parser<'a> {
5570
5572
}
5571
5573
}
5572
5574
5573
- if !negative_bounds. is_empty ( ) {
5575
+ if !negative_bounds. is_empty ( ) || was_negative {
5574
5576
let plural = negative_bounds. len ( ) > 1 ;
5575
5577
let mut err = self . struct_span_err ( negative_bounds,
5576
5578
"negative trait bounds are not supported" ) ;
5577
- let bound_list = colon_span. unwrap ( ) . to ( self . prev_span ) ;
5578
- let mut new_bound_list = String :: new ( ) ;
5579
- if !bounds. is_empty ( ) {
5580
- let mut snippets = bounds. iter ( ) . map ( |bound| bound. span ( ) )
5581
- . map ( |span| self . sess . source_map ( ) . span_to_snippet ( span) ) ;
5582
- while let Some ( Ok ( snippet) ) = snippets. next ( ) {
5583
- new_bound_list. push_str ( " + " ) ;
5584
- new_bound_list. push_str ( & snippet) ;
5585
- }
5586
- new_bound_list = new_bound_list. replacen ( " +" , ":" , 1 ) ;
5587
- }
5588
- err. span_suggestion_short ( bound_list,
5589
- & format ! ( "remove the trait bound{}" ,
5590
- if plural { "s" } else { "" } ) ,
5591
- new_bound_list,
5592
- Applicability :: MachineApplicable ) ;
5579
+ if let Some ( bound_list) = colon_span {
5580
+ let bound_list = bound_list. to ( self . prev_span ) ;
5581
+ let mut new_bound_list = String :: new ( ) ;
5582
+ if !bounds. is_empty ( ) {
5583
+ let mut snippets = bounds. iter ( ) . map ( |bound| bound. span ( ) )
5584
+ . map ( |span| self . sess . source_map ( ) . span_to_snippet ( span) ) ;
5585
+ while let Some ( Ok ( snippet) ) = snippets. next ( ) {
5586
+ new_bound_list. push_str ( " + " ) ;
5587
+ new_bound_list. push_str ( & snippet) ;
5588
+ }
5589
+ new_bound_list = new_bound_list. replacen ( " +" , ":" , 1 ) ;
5590
+ }
5591
+ err. span_suggestion_short ( bound_list,
5592
+ & format ! ( "remove the trait bound{}" ,
5593
+ if plural { "s" } else { "" } ) ,
5594
+ new_bound_list,
5595
+ Applicability :: MachineApplicable ) ;
5596
+ }
5593
5597
err. emit ( ) ;
5594
5598
}
5595
5599
@@ -5625,7 +5629,7 @@ impl<'a> Parser<'a> {
5625
5629
5626
5630
// Parse optional colon and param bounds.
5627
5631
let bounds = if self . eat ( & token:: Colon ) {
5628
- self . parse_generic_bounds ( None ) ?
5632
+ self . parse_generic_bounds ( Some ( self . prev_span ) ) ?
5629
5633
} else {
5630
5634
Vec :: new ( )
5631
5635
} ;
@@ -6070,7 +6074,7 @@ impl<'a> Parser<'a> {
6070
6074
// or with mandatory equality sign and the second type.
6071
6075
let ty = self . parse_ty ( ) ?;
6072
6076
if self . eat ( & token:: Colon ) {
6073
- let bounds = self . parse_generic_bounds ( None ) ?;
6077
+ let bounds = self . parse_generic_bounds ( Some ( self . prev_span ) ) ?;
6074
6078
where_clause. predicates . push ( ast:: WherePredicate :: BoundPredicate (
6075
6079
ast:: WhereBoundPredicate {
6076
6080
span : lo. to ( self . prev_span ) ,
@@ -7626,7 +7630,7 @@ impl<'a> Parser<'a> {
7626
7630
tps. where_clause = self . parse_where_clause ( ) ?;
7627
7631
let alias = if existential {
7628
7632
self . expect ( & token:: Colon ) ?;
7629
- let bounds = self . parse_generic_bounds ( None ) ?;
7633
+ let bounds = self . parse_generic_bounds ( Some ( self . prev_span ) ) ?;
7630
7634
AliasKind :: Existential ( bounds)
7631
7635
} else {
7632
7636
self . expect ( & token:: Eq ) ?;
0 commit comments