@@ -2395,19 +2395,23 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
2395
2395
type_param_span : Option < ( Span , bool ) > ,
2396
2396
bound_kind : GenericKind < ' tcx > ,
2397
2397
sub : S ,
2398
+ add_lt_sugg : Option < ( Span , String ) > ,
2398
2399
) {
2399
2400
let msg = "consider adding an explicit lifetime bound" ;
2400
2401
if let Some ( ( sp, has_lifetimes) ) = type_param_span {
2401
2402
let suggestion =
2402
2403
if has_lifetimes { format ! ( " + {}" , sub) } else { format ! ( ": {}" , sub) } ;
2403
- err. span_suggestion_verbose (
2404
- sp,
2405
- & format ! ( "{}..." , msg) ,
2406
- suggestion,
2404
+ let mut suggestions = vec ! [ ( sp, suggestion) ] ;
2405
+ if let Some ( add_lt_sugg) = add_lt_sugg {
2406
+ suggestions. push ( add_lt_sugg) ;
2407
+ }
2408
+ err. multipart_suggestion_verbose (
2409
+ format ! ( "{msg}..." ) ,
2410
+ suggestions,
2407
2411
Applicability :: MaybeIncorrect , // Issue #41966
2408
2412
) ;
2409
2413
} else {
2410
- let consider = format ! ( "{} `{}: {}`..." , msg, bound_kind, sub, ) ;
2414
+ let consider = format ! ( "{} `{}: {}`..." , msg, bound_kind, sub) ;
2411
2415
err. help ( & consider) ;
2412
2416
}
2413
2417
}
@@ -2423,7 +2427,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
2423
2427
} ;
2424
2428
let mut sugg =
2425
2429
vec ! [ ( sp, suggestion) , ( span. shrink_to_hi( ) , format!( " + {}" , new_lt) ) ] ;
2426
- if let Some ( lt) = add_lt_sugg {
2430
+ if let Some ( lt) = add_lt_sugg. clone ( ) {
2427
2431
sugg. push ( lt) ;
2428
2432
sugg. rotate_right ( 1 ) ;
2429
2433
}
@@ -2529,7 +2533,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
2529
2533
// for the bound is not suitable for suggestions when `-Zverbose` is set because it
2530
2534
// uses `Debug` output, so we handle it specially here so that suggestions are
2531
2535
// always correct.
2532
- binding_suggestion ( & mut err, type_param_span, bound_kind, name) ;
2536
+ binding_suggestion ( & mut err, type_param_span, bound_kind, name, None ) ;
2533
2537
err
2534
2538
}
2535
2539
@@ -2542,7 +2546,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
2542
2546
"{} may not live long enough" ,
2543
2547
labeled_user_string
2544
2548
) ;
2545
- binding_suggestion ( & mut err, type_param_span, bound_kind, "'static" ) ;
2549
+ binding_suggestion ( & mut err, type_param_span, bound_kind, "'static" , None ) ;
2546
2550
err
2547
2551
}
2548
2552
@@ -2576,7 +2580,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
2576
2580
new_binding_suggestion ( & mut err, type_param_span) ;
2577
2581
}
2578
2582
_ => {
2579
- binding_suggestion ( & mut err, type_param_span, bound_kind, new_lt) ;
2583
+ binding_suggestion (
2584
+ & mut err,
2585
+ type_param_span,
2586
+ bound_kind,
2587
+ new_lt,
2588
+ add_lt_sugg,
2589
+ ) ;
2580
2590
}
2581
2591
}
2582
2592
}
0 commit comments