@@ -2395,19 +2395,23 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
23952395 type_param_span : Option < ( Span , bool ) > ,
23962396 bound_kind : GenericKind < ' tcx > ,
23972397 sub : S ,
2398+ add_lt_sugg : Option < ( Span , String ) > ,
23982399 ) {
23992400 let msg = "consider adding an explicit lifetime bound" ;
24002401 if let Some ( ( sp, has_lifetimes) ) = type_param_span {
24012402 let suggestion =
24022403 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,
24072411 Applicability :: MaybeIncorrect , // Issue #41966
24082412 ) ;
24092413 } else {
2410- let consider = format ! ( "{} `{}: {}`..." , msg, bound_kind, sub, ) ;
2414+ let consider = format ! ( "{} `{}: {}`..." , msg, bound_kind, sub) ;
24112415 err. help ( & consider) ;
24122416 }
24132417 }
@@ -2423,7 +2427,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
24232427 } ;
24242428 let mut sugg =
24252429 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 ( ) {
24272431 sugg. push ( lt) ;
24282432 sugg. rotate_right ( 1 ) ;
24292433 }
@@ -2529,7 +2533,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
25292533 // for the bound is not suitable for suggestions when `-Zverbose` is set because it
25302534 // uses `Debug` output, so we handle it specially here so that suggestions are
25312535 // 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 ) ;
25332537 err
25342538 }
25352539
@@ -2542,7 +2546,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
25422546 "{} may not live long enough" ,
25432547 labeled_user_string
25442548 ) ;
2545- binding_suggestion ( & mut err, type_param_span, bound_kind, "'static" ) ;
2549+ binding_suggestion ( & mut err, type_param_span, bound_kind, "'static" , None ) ;
25462550 err
25472551 }
25482552
@@ -2576,7 +2580,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
25762580 new_binding_suggestion ( & mut err, type_param_span) ;
25772581 }
25782582 _ => {
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+ ) ;
25802590 }
25812591 }
25822592 }
0 commit comments