@@ -1803,7 +1803,7 @@ impl<'a> Parser<'a> {
1803
1803
let mut bounds = vec ! [ GenericBound :: Trait ( poly_trait_ref, TraitBoundModifier :: None ) ] ;
1804
1804
if parse_plus {
1805
1805
self . eat_plus ( ) ; // `+`, or `+=` gets split and `+` is discarded
1806
- bounds. append ( & mut self . parse_generic_bounds ( None ) ?) ;
1806
+ bounds. append ( & mut self . parse_generic_bounds ( Some ( self . prev_span ) ) ?) ;
1807
1807
}
1808
1808
Ok ( TyKind :: TraitObject ( bounds, TraitObjectSyntax :: None ) )
1809
1809
}
@@ -5523,6 +5523,7 @@ impl<'a> Parser<'a> {
5523
5523
let mut bounds = Vec :: new ( ) ;
5524
5524
let mut negative_bounds = Vec :: new ( ) ;
5525
5525
let mut last_plus_span = None ;
5526
+ let mut was_negative = false ;
5526
5527
loop {
5527
5528
// This needs to be synchronized with `Token::can_begin_bound`.
5528
5529
let is_bound_start = self . check_path ( ) || self . check_lifetime ( ) ||
@@ -5567,9 +5568,10 @@ impl<'a> Parser<'a> {
5567
5568
}
5568
5569
let poly_span = lo. to ( self . prev_span ) ;
5569
5570
if is_negative {
5570
- negative_bounds. push (
5571
- last_plus_span. or ( colon_span) . unwrap ( )
5572
- . to ( poly_span) ) ;
5571
+ was_negative = true ;
5572
+ if let Some ( sp) = last_plus_span. or ( colon_span) {
5573
+ negative_bounds. push ( sp. to ( poly_span) ) ;
5574
+ }
5573
5575
} else {
5574
5576
let poly_trait = PolyTraitRef :: new ( lifetime_defs, path, poly_span) ;
5575
5577
let modifier = if question. is_some ( ) {
@@ -5591,26 +5593,28 @@ impl<'a> Parser<'a> {
5591
5593
}
5592
5594
}
5593
5595
5594
- if !negative_bounds. is_empty ( ) {
5596
+ if !negative_bounds. is_empty ( ) || was_negative {
5595
5597
let plural = negative_bounds. len ( ) > 1 ;
5596
5598
let mut err = self . struct_span_err ( negative_bounds,
5597
5599
"negative trait bounds are not supported" ) ;
5598
- let bound_list = colon_span. unwrap ( ) . to ( self . prev_span ) ;
5599
- let mut new_bound_list = String :: new ( ) ;
5600
- if !bounds. is_empty ( ) {
5601
- let mut snippets = bounds. iter ( ) . map ( |bound| bound. span ( ) )
5602
- . map ( |span| self . sess . source_map ( ) . span_to_snippet ( span) ) ;
5603
- while let Some ( Ok ( snippet) ) = snippets. next ( ) {
5604
- new_bound_list. push_str ( " + " ) ;
5605
- new_bound_list. push_str ( & snippet) ;
5606
- }
5607
- new_bound_list = new_bound_list. replacen ( " +" , ":" , 1 ) ;
5608
- }
5609
- err. span_suggestion_short ( bound_list,
5610
- & format ! ( "remove the trait bound{}" ,
5611
- if plural { "s" } else { "" } ) ,
5612
- new_bound_list,
5613
- Applicability :: MachineApplicable ) ;
5600
+ if let Some ( bound_list) = colon_span {
5601
+ let bound_list = bound_list. to ( self . prev_span ) ;
5602
+ let mut new_bound_list = String :: new ( ) ;
5603
+ if !bounds. is_empty ( ) {
5604
+ let mut snippets = bounds. iter ( ) . map ( |bound| bound. span ( ) )
5605
+ . map ( |span| self . sess . source_map ( ) . span_to_snippet ( span) ) ;
5606
+ while let Some ( Ok ( snippet) ) = snippets. next ( ) {
5607
+ new_bound_list. push_str ( " + " ) ;
5608
+ new_bound_list. push_str ( & snippet) ;
5609
+ }
5610
+ new_bound_list = new_bound_list. replacen ( " +" , ":" , 1 ) ;
5611
+ }
5612
+ err. span_suggestion_short ( bound_list,
5613
+ & format ! ( "remove the trait bound{}" ,
5614
+ if plural { "s" } else { "" } ) ,
5615
+ new_bound_list,
5616
+ Applicability :: MachineApplicable ) ;
5617
+ }
5614
5618
err. emit ( ) ;
5615
5619
}
5616
5620
@@ -5646,7 +5650,7 @@ impl<'a> Parser<'a> {
5646
5650
5647
5651
// Parse optional colon and param bounds.
5648
5652
let bounds = if self . eat ( & token:: Colon ) {
5649
- self . parse_generic_bounds ( None ) ?
5653
+ self . parse_generic_bounds ( Some ( self . prev_span ) ) ?
5650
5654
} else {
5651
5655
Vec :: new ( )
5652
5656
} ;
@@ -6091,7 +6095,7 @@ impl<'a> Parser<'a> {
6091
6095
// or with mandatory equality sign and the second type.
6092
6096
let ty = self . parse_ty ( ) ?;
6093
6097
if self . eat ( & token:: Colon ) {
6094
- let bounds = self . parse_generic_bounds ( None ) ?;
6098
+ let bounds = self . parse_generic_bounds ( Some ( self . prev_span ) ) ?;
6095
6099
where_clause. predicates . push ( ast:: WherePredicate :: BoundPredicate (
6096
6100
ast:: WhereBoundPredicate {
6097
6101
span : lo. to ( self . prev_span ) ,
@@ -7643,7 +7647,7 @@ impl<'a> Parser<'a> {
7643
7647
tps. where_clause = self . parse_where_clause ( ) ?;
7644
7648
let alias = if existential {
7645
7649
self . expect ( & token:: Colon ) ?;
7646
- let bounds = self . parse_generic_bounds ( None ) ?;
7650
+ let bounds = self . parse_generic_bounds ( Some ( self . prev_span ) ) ?;
7647
7651
AliasKind :: Existential ( bounds)
7648
7652
} else {
7649
7653
self . expect ( & token:: Eq ) ?;
0 commit comments