@@ -256,10 +256,12 @@ impl<'a> Parser<'a> {
256256 return Ok ( ty) ;
257257 }
258258
259- let lo = self . token . span ;
260259 let mut impl_dyn_multi = false ;
260+ let mut paren_ty_plus = false ;
261+
262+ let lo = self . token . span ;
261263 let kind = if self . check ( exp ! ( OpenParen ) ) {
262- self . parse_ty_tuple_or_parens ( lo, allow_plus) ?
264+ self . parse_ty_tuple_or_parens ( lo, allow_plus, & mut paren_ty_plus ) ?
263265 } else if self . eat ( exp ! ( Bang ) ) {
264266 // Never type `!`
265267 TyKind :: Never
@@ -370,7 +372,7 @@ impl<'a> Parser<'a> {
370372
371373 // Try to recover from use of `+` with incorrect priority.
372374 match allow_plus {
373- AllowPlus :: Yes => self . maybe_recover_from_bad_type_plus ( & ty) ?,
375+ AllowPlus :: Yes => self . maybe_recover_from_bad_type_plus ( paren_ty_plus , & ty) ?,
374376 AllowPlus :: No => self . maybe_report_ambiguous_plus ( impl_dyn_multi, & ty) ,
375377 }
376378 if let RecoverQuestionMark :: Yes = recover_question_mark {
@@ -395,7 +397,12 @@ impl<'a> Parser<'a> {
395397 /// Parses either:
396398 /// - `(TYPE)`, a parenthesized type.
397399 /// - `(TYPE,)`, a tuple with a single field of type TYPE.
398- fn parse_ty_tuple_or_parens ( & mut self , lo : Span , allow_plus : AllowPlus ) -> PResult < ' a , TyKind > {
400+ fn parse_ty_tuple_or_parens (
401+ & mut self ,
402+ lo : Span ,
403+ allow_plus : AllowPlus ,
404+ paren_ty_plus : & mut bool ,
405+ ) -> PResult < ' a , TyKind > {
399406 let mut trailing_plus = false ;
400407 let ( ts, trailing) = self . parse_paren_comma_seq ( |p| {
401408 let ty = p. parse_ty ( ) ?;
@@ -404,20 +411,14 @@ impl<'a> Parser<'a> {
404411 } ) ?;
405412
406413 if ts. len ( ) == 1 && matches ! ( trailing, Trailing :: No ) {
414+ * paren_ty_plus = trailing_plus;
407415 let ty = ts. into_iter ( ) . next ( ) . unwrap ( ) . into_inner ( ) ;
408- let maybe_bounds = allow_plus == AllowPlus :: Yes && self . token . is_like_plus ( ) ;
409416 match ty. kind {
410417 // `(TY_BOUND_NOPAREN) + BOUND + ...`.
411- TyKind :: Path ( None , path) if maybe_bounds => {
412- self . parse_remaining_bounds_path ( ThinVec :: new ( ) , path, lo, true )
413- }
414- // For `('a) + …`, we know that `'a` in type position already lead to an error being
415- // emitted. To reduce output, let's indirectly suppress E0178 (bad `+` in type) and
416- // other irrelevant consequential errors.
417- TyKind :: TraitObject ( bounds, TraitObjectSyntax :: None )
418- if maybe_bounds && bounds. len ( ) == 1 && !trailing_plus =>
418+ TyKind :: Path ( None , path)
419+ if allow_plus == AllowPlus :: Yes && self . token . is_like_plus ( ) =>
419420 {
420- self . parse_remaining_bounds ( bounds , true )
421+ self . parse_remaining_bounds_path ( ThinVec :: new ( ) , path , lo , true )
421422 }
422423 // `(TYPE)`
423424 _ => Ok ( TyKind :: Paren ( P ( ty) ) ) ,
0 commit comments