@@ -714,6 +714,7 @@ impl<'a> Parser<'a> {
714
714
/// ```
715
715
fn parse_generic_bound ( & mut self ) -> PResult < ' a , GenericBound > {
716
716
let lo = self . token . span ;
717
+ let leading_token = self . prev_token . clone ( ) ;
717
718
let has_parens = self . eat ( & token:: OpenDelim ( Delimiter :: Parenthesis ) ) ;
718
719
let inner_lo = self . token . span ;
719
720
@@ -722,7 +723,7 @@ impl<'a> Parser<'a> {
722
723
self . error_lt_bound_with_modifiers ( modifiers) ;
723
724
self . parse_generic_lt_bound ( lo, inner_lo, has_parens) ?
724
725
} else {
725
- self . parse_generic_ty_bound ( lo, has_parens, modifiers) ?
726
+ self . parse_generic_ty_bound ( lo, has_parens, modifiers, & leading_token ) ?
726
727
} ;
727
728
728
729
Ok ( bound)
@@ -827,6 +828,7 @@ impl<'a> Parser<'a> {
827
828
lo : Span ,
828
829
has_parens : bool ,
829
830
modifiers : BoundModifiers ,
831
+ leading_token : & Token ,
830
832
) -> PResult < ' a , GenericBound > {
831
833
let mut lifetime_defs = self . parse_late_bound_lifetime_defs ( ) ?;
832
834
let mut path = if self . token . is_keyword ( kw:: Fn )
@@ -873,18 +875,18 @@ impl<'a> Parser<'a> {
873
875
}
874
876
875
877
if has_parens {
876
- if self . token . is_like_plus ( ) {
877
- // Someone has written something like `&dyn (Trait + Other)`. The correct code
878
- // would be `&(dyn Trait + Other)`, but we don't have access to the appropriate
879
- // span to suggest that. When written as `&dyn Trait + Other`, an appropriate
880
- // suggestion is given.
878
+ // Someone has written something like `&dyn (Trait + Other)`. The correct code
879
+ // would be `&(dyn Trait + Other)`
880
+ if self . token . is_like_plus ( ) && leading_token. is_keyword ( kw:: Dyn ) {
881
881
let bounds = vec ! [ ] ;
882
882
self . parse_remaining_bounds ( bounds, true ) ?;
883
883
self . expect ( & token:: CloseDelim ( Delimiter :: Parenthesis ) ) ?;
884
- let sp = vec ! [ lo, self . prev_token. span] ;
885
- self . sess . emit_err ( errors:: IncorrectBracesTraitBounds {
886
- span : sp,
887
- sugg : errors:: IncorrectBracesTraitBoundsSugg { l : lo, r : self . prev_token . span } ,
884
+ self . sess . emit_err ( errors:: IncorrectParensTraitBounds {
885
+ span : vec ! [ lo, self . prev_token. span] ,
886
+ sugg : errors:: IncorrectParensTraitBoundsSugg {
887
+ wrong_span : leading_token. span . shrink_to_hi ( ) . to ( lo) ,
888
+ new_span : leading_token. span . shrink_to_lo ( ) ,
889
+ } ,
888
890
} ) ;
889
891
} else {
890
892
self . expect ( & token:: CloseDelim ( Delimiter :: Parenthesis ) ) ?;
0 commit comments