@@ -256,10 +256,12 @@ impl<'a> Parser<'a> {
256
256
return Ok ( ty) ;
257
257
}
258
258
259
- let lo = self . token . span ;
260
259
let mut impl_dyn_multi = false ;
260
+ let mut paren_ty_plus = false ;
261
+
262
+ let lo = self . token . span ;
261
263
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 ) ?
263
265
} else if self . eat ( exp ! ( Bang ) ) {
264
266
// Never type `!`
265
267
TyKind :: Never
@@ -370,7 +372,7 @@ impl<'a> Parser<'a> {
370
372
371
373
// Try to recover from use of `+` with incorrect priority.
372
374
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) ?,
374
376
AllowPlus :: No => self . maybe_report_ambiguous_plus ( impl_dyn_multi, & ty) ,
375
377
}
376
378
if let RecoverQuestionMark :: Yes = recover_question_mark {
@@ -395,7 +397,12 @@ impl<'a> Parser<'a> {
395
397
/// Parses either:
396
398
/// - `(TYPE)`, a parenthesized type.
397
399
/// - `(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 > {
399
406
let mut trailing_plus = false ;
400
407
let ( ts, trailing) = self . parse_paren_comma_seq ( |p| {
401
408
let ty = p. parse_ty ( ) ?;
@@ -404,20 +411,14 @@ impl<'a> Parser<'a> {
404
411
} ) ?;
405
412
406
413
if ts. len ( ) == 1 && matches ! ( trailing, Trailing :: No ) {
414
+ * paren_ty_plus = trailing_plus;
407
415
let ty = ts. into_iter ( ) . next ( ) . unwrap ( ) . into_inner ( ) ;
408
- let maybe_bounds = allow_plus == AllowPlus :: Yes && self . token . is_like_plus ( ) ;
409
416
match ty. kind {
410
417
// `(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 ( ) =>
419
420
{
420
- self . parse_remaining_bounds ( bounds , true )
421
+ self . parse_remaining_bounds_path ( ThinVec :: new ( ) , path , lo , true )
421
422
}
422
423
// `(TYPE)`
423
424
_ => Ok ( TyKind :: Paren ( P ( ty) ) ) ,
0 commit comments