@@ -2076,16 +2076,40 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
20762076 for param in params {
20772077 if let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( param. span ) {
20782078 if snippet. starts_with ( '&' ) && !snippet. starts_with ( "&'" ) {
2079- introduce_suggestion
2080- . push ( ( param. span , format ! ( "&'a {}" , & snippet[ 1 ..] ) ) ) ;
2081- } else if let Some ( stripped) = snippet. strip_prefix ( "&'_ " ) {
2082- introduce_suggestion. push ( ( param. span , format ! ( "&'a {}" , & stripped) ) ) ;
2079+ let lo = param. span . lo ( ) + BytePos ( 1 ) ;
2080+ let span = param. span . with_lo ( lo) . with_hi ( lo) ;
2081+ introduce_suggestion. push ( ( span, "'a " . to_string ( ) ) ) ;
2082+ } else if let Some ( _) = snippet. strip_prefix ( "&'_ " ) {
2083+ let lo = param. span . lo ( ) + BytePos ( 1 ) ;
2084+ let hi = lo + BytePos ( 2 ) ;
2085+ let span = param. span . with_lo ( lo) . with_hi ( hi) ;
2086+ introduce_suggestion. push ( ( span, "'a" . to_string ( ) ) ) ;
20832087 }
20842088 }
20852089 }
20862090 for ( ( span, _) , sugg) in spans_with_counts. iter ( ) . copied ( ) . zip ( suggs. iter ( ) ) {
2087- if let Some ( sugg) = sugg {
2088- introduce_suggestion. push ( ( span, sugg. to_string ( ) ) ) ;
2091+ match ( sugg, self . tcx . sess . source_map ( ) . span_to_snippet ( span) ) {
2092+ ( Some ( sugg) , Ok ( snippet) )
2093+ if snippet. starts_with ( '&' )
2094+ && !snippet. starts_with ( "&'" )
2095+ && sugg. starts_with ( "&" ) =>
2096+ {
2097+ let lo = span. lo ( ) + BytePos ( 1 ) ;
2098+ let span = span. with_lo ( lo) . with_hi ( lo) ;
2099+ introduce_suggestion. push ( ( span, sugg[ 1 ..] . to_string ( ) ) ) ;
2100+ }
2101+ ( Some ( sugg) , Ok ( snippet) )
2102+ if snippet. starts_with ( "&'_ " ) && sugg. starts_with ( "&" ) =>
2103+ {
2104+ let lo = span. lo ( ) + BytePos ( 1 ) ;
2105+ let hi = lo + BytePos ( 2 ) ;
2106+ let span = span. with_lo ( lo) . with_hi ( hi) ;
2107+ introduce_suggestion. push ( ( span, sugg[ 1 ..] . to_string ( ) ) ) ;
2108+ }
2109+ ( Some ( sugg) , _) => {
2110+ introduce_suggestion. push ( ( span, sugg. to_string ( ) ) ) ;
2111+ }
2112+ _ => { }
20892113 }
20902114 }
20912115 err. multipart_suggestion_with_style (
@@ -2159,7 +2183,8 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
21592183 for ( ( span, _) , snippet) in spans_with_counts. iter ( ) . copied ( ) . zip ( snippets. iter ( ) ) {
21602184 match snippet. as_deref ( ) {
21612185 Some ( "" ) => spans_suggs. push ( ( span, "'lifetime, " . to_string ( ) ) ) ,
2162- Some ( "&" ) => spans_suggs. push ( ( span, "&'lifetime " . to_string ( ) ) ) ,
2186+ Some ( "&" ) => spans_suggs
2187+ . push ( ( span. with_lo ( span. lo ( ) + BytePos ( 1 ) ) , "'lifetime " . to_string ( ) ) ) ,
21632188 _ => { }
21642189 }
21652190 }
0 commit comments