@@ -80,7 +80,7 @@ impl ForLifetimeSpanType {
80
80
}
81
81
}
82
82
83
- pub ( crate ) fn suggestion ( & self , sugg : & str ) -> String {
83
+ pub ( crate ) fn suggestion ( & self , sugg : impl std :: fmt :: Display ) -> String {
84
84
match self {
85
85
Self :: BoundEmpty | Self :: TypeEmpty => format ! ( "for<{}> " , sugg) ,
86
86
Self :: BoundTail | Self :: TypeTail => format ! ( ", {}" , sugg) ,
@@ -2311,8 +2311,8 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
2311
2311
2312
2312
let suggest_existing =
2313
2313
|err : & mut Diagnostic ,
2314
- name : & str ,
2315
- formatters : Vec < Option < Box < dyn Fn ( & str ) -> String > > > | {
2314
+ name : Symbol ,
2315
+ formatters : Vec < Option < Box < dyn Fn ( Symbol ) -> String > > > | {
2316
2316
if let Some ( MissingLifetimeSpot :: HigherRanked { span : for_span, span_type } ) =
2317
2317
self . missing_named_lifetime_spots . iter ( ) . rev ( ) . next ( )
2318
2318
{
@@ -2332,7 +2332,8 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
2332
2332
// If all single char lifetime names are present, we wrap around and double the chars.
2333
2333
let lt_name = ( 1 ..)
2334
2334
. flat_map ( a_to_z_repeat_n)
2335
- . find ( |lt| !lifetime_names. contains ( & Symbol :: intern ( & lt) ) )
2335
+ . map ( |lt| Symbol :: intern ( & lt) )
2336
+ . find ( |lt| !lifetime_names. contains ( lt) )
2336
2337
. unwrap ( ) ;
2337
2338
let msg = format ! (
2338
2339
"consider making the {} lifetime-generic with a new `{}` lifetime" ,
@@ -2359,7 +2360,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
2359
2360
introduce_suggestion. push ( ( * for_span, for_sugg) ) ;
2360
2361
for ( ( span, _) , formatter) in spans_with_counts. iter ( ) . zip ( formatters. iter ( ) ) {
2361
2362
if let Some ( formatter) = formatter {
2362
- introduce_suggestion. push ( ( * span, formatter ( & lt_name) ) ) ;
2363
+ introduce_suggestion. push ( ( * span, formatter ( lt_name) ) ) ;
2363
2364
}
2364
2365
}
2365
2366
err. multipart_suggestion_verbose (
@@ -2582,15 +2583,19 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
2582
2583
let lifetime_names: Vec < _ > = lifetime_names. iter ( ) . collect ( ) ;
2583
2584
match & lifetime_names[ ..] {
2584
2585
[ name] => {
2585
- let mut suggs: Vec < Option < Box < dyn Fn ( & str ) -> String > > > = Vec :: new ( ) ;
2586
+ let mut suggs: Vec < Option < Box < dyn Fn ( Symbol ) -> String > > > = Vec :: new ( ) ;
2586
2587
for ( snippet, ( _, count) ) in snippets. iter ( ) . zip ( spans_with_counts. iter ( ) . copied ( ) )
2587
2588
{
2588
2589
suggs. push ( match snippet. as_deref ( ) {
2589
2590
Some ( "&" ) => Some ( Box :: new ( |name| format ! ( "&{} " , name) ) ) ,
2590
2591
Some ( "'_" ) => Some ( Box :: new ( |n| n. to_string ( ) ) ) ,
2591
2592
Some ( "" ) => Some ( Box :: new ( move |n| format ! ( "{}, " , n) . repeat ( count) ) ) ,
2592
2593
Some ( "<" ) => Some ( Box :: new ( move |n| {
2593
- std:: iter:: repeat ( n) . take ( count) . collect :: < Vec < _ > > ( ) . join ( ", " )
2594
+ std:: iter:: repeat ( n)
2595
+ . take ( count)
2596
+ . map ( |n| n. to_string ( ) )
2597
+ . collect :: < Vec < _ > > ( )
2598
+ . join ( ", " )
2594
2599
} ) ) ,
2595
2600
Some ( snippet) if !snippet. ends_with ( '>' ) => Some ( Box :: new ( move |name| {
2596
2601
format ! (
@@ -2605,7 +2610,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
2605
2610
_ => None ,
2606
2611
} ) ;
2607
2612
}
2608
- suggest_existing ( err, name. as_str ( ) , suggs) ;
2613
+ suggest_existing ( err, * * name, suggs) ;
2609
2614
}
2610
2615
[ ] => {
2611
2616
let mut suggs = Vec :: new ( ) ;
0 commit comments