@@ -2076,16 +2076,40 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
2076
2076
for param in params {
2077
2077
if let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( param. span ) {
2078
2078
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 ( ) ) ) ;
2083
2087
}
2084
2088
}
2085
2089
}
2086
2090
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
+ _ => { }
2089
2113
}
2090
2114
}
2091
2115
err. multipart_suggestion_with_style (
@@ -2159,7 +2183,8 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
2159
2183
for ( ( span, _) , snippet) in spans_with_counts. iter ( ) . copied ( ) . zip ( snippets. iter ( ) ) {
2160
2184
match snippet. as_deref ( ) {
2161
2185
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 ( ) ) ) ,
2163
2188
_ => { }
2164
2189
}
2165
2190
}
0 commit comments