@@ -7,6 +7,7 @@ use crate::errors::{self, CandidateTraitNote, NoAssociatedItem};
7
7
use crate :: Expectation ;
8
8
use crate :: FnCtxt ;
9
9
use core:: ops:: ControlFlow ;
10
+ use itertools:: Itertools ;
10
11
use rustc_ast:: ast:: Mutability ;
11
12
use rustc_attr:: parse_confusables;
12
13
use rustc_data_structures:: fx:: { FxIndexMap , FxIndexSet } ;
@@ -3291,14 +3292,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3291
3292
param. name. ident( ) ,
3292
3293
) ) ;
3293
3294
let bounds_span = hir_generics. bounds_span_for_suggestions ( def_id) ;
3294
- if rcvr_ty. is_ref ( ) && param. is_impl_trait ( ) && bounds_span. is_some ( ) {
3295
+ if rcvr_ty. is_ref ( )
3296
+ && param. is_impl_trait ( )
3297
+ && let Some ( ( bounds_span, _) ) = bounds_span
3298
+ {
3295
3299
err. multipart_suggestions (
3296
3300
msg,
3297
3301
candidates. iter ( ) . map ( |t| {
3298
3302
vec ! [
3299
3303
( param. span. shrink_to_lo( ) , "(" . to_string( ) ) ,
3300
3304
(
3301
- bounds_span. unwrap ( ) ,
3305
+ bounds_span,
3302
3306
format!( " + {})" , self . tcx. def_path_str( t. def_id) ) ,
3303
3307
) ,
3304
3308
]
@@ -3308,20 +3312,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3308
3312
return ;
3309
3313
}
3310
3314
3311
- let ( sp, introducer) = if let Some ( span) = bounds_span {
3312
- ( span, Introducer :: Plus )
3313
- } else if let Some ( colon_span) = param. colon_span {
3314
- ( colon_span. shrink_to_hi ( ) , Introducer :: Nothing )
3315
- } else if param. is_impl_trait ( ) {
3316
- ( param. span . shrink_to_hi ( ) , Introducer :: Plus )
3317
- } else {
3318
- ( param. span . shrink_to_hi ( ) , Introducer :: Colon )
3319
- } ;
3315
+ let ( sp, introducer, open_paren_sp) =
3316
+ if let Some ( ( span, open_paren_sp) ) = bounds_span {
3317
+ ( span, Introducer :: Plus , open_paren_sp)
3318
+ } else if let Some ( colon_span) = param. colon_span {
3319
+ ( colon_span. shrink_to_hi ( ) , Introducer :: Nothing , None )
3320
+ } else if param. is_impl_trait ( ) {
3321
+ ( param. span . shrink_to_hi ( ) , Introducer :: Plus , None )
3322
+ } else {
3323
+ ( param. span . shrink_to_hi ( ) , Introducer :: Colon , None )
3324
+ } ;
3320
3325
3321
- err. span_suggestions (
3322
- sp,
3323
- msg,
3324
- candidates. iter ( ) . map ( |t| {
3326
+ let mut suggs = vec ! [ ] ;
3327
+
3328
+ let suggestion = candidates
3329
+ . iter ( )
3330
+ . map ( |t| {
3325
3331
format ! (
3326
3332
"{} {}" ,
3327
3333
match introducer {
@@ -3331,9 +3337,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3331
3337
} ,
3332
3338
self . tcx. def_path_str( t. def_id)
3333
3339
)
3334
- } ) ,
3335
- Applicability :: MaybeIncorrect ,
3336
- ) ;
3340
+ } )
3341
+ . join ( "" ) ;
3342
+ if let Some ( open_paren_sp) = open_paren_sp {
3343
+ suggs. push ( ( open_paren_sp, "(" . to_string ( ) ) ) ;
3344
+ suggs. push ( ( sp, format ! ( "){suggestion}" ) ) ) ;
3345
+ } else {
3346
+ suggs. push ( ( sp, suggestion) ) ;
3347
+ }
3348
+
3349
+ err. multipart_suggestion ( msg, suggs, Applicability :: MaybeIncorrect ) ;
3350
+
3337
3351
return ;
3338
3352
}
3339
3353
Node :: Item ( hir:: Item {
0 commit comments