@@ -714,6 +714,7 @@ impl<'a> Parser<'a> {
714714 /// ```
715715 fn parse_generic_bound ( & mut self ) -> PResult < ' a , GenericBound > {
716716 let lo = self . token . span ;
717+ let leading_token = self . prev_token . clone ( ) ;
717718 let has_parens = self . eat ( & token:: OpenDelim ( Delimiter :: Parenthesis ) ) ;
718719 let inner_lo = self . token . span ;
719720
@@ -722,7 +723,7 @@ impl<'a> Parser<'a> {
722723 self . error_lt_bound_with_modifiers ( modifiers) ;
723724 self . parse_generic_lt_bound ( lo, inner_lo, has_parens) ?
724725 } else {
725- self . parse_generic_ty_bound ( lo, has_parens, modifiers) ?
726+ self . parse_generic_ty_bound ( lo, has_parens, modifiers, & leading_token ) ?
726727 } ;
727728
728729 Ok ( bound)
@@ -827,6 +828,7 @@ impl<'a> Parser<'a> {
827828 lo : Span ,
828829 has_parens : bool ,
829830 modifiers : BoundModifiers ,
831+ leading_token : & Token ,
830832 ) -> PResult < ' a , GenericBound > {
831833 let mut lifetime_defs = self . parse_late_bound_lifetime_defs ( ) ?;
832834 let mut path = if self . token . is_keyword ( kw:: Fn )
@@ -873,18 +875,18 @@ impl<'a> Parser<'a> {
873875 }
874876
875877 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 ) {
881881 let bounds = vec ! [ ] ;
882882 self . parse_remaining_bounds ( bounds, true ) ?;
883883 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+ } ,
888890 } ) ;
889891 } else {
890892 self . expect ( & token:: CloseDelim ( Delimiter :: Parenthesis ) ) ?;
0 commit comments