@@ -139,19 +139,6 @@ impl fmt::Display for Lifetime {
139
139
}
140
140
}
141
141
142
- pub enum LifetimeSuggestionPosition {
143
- /// The user wrote `'a` or `'_`.
144
- Normal ,
145
- /// The user wrote `&type` or `&mut type`.
146
- Ampersand ,
147
- /// The user wrote `Path` and omitted the `<'_>`.
148
- ElidedPath ,
149
- /// The user wrote `Path<T>`, and omitted the `'_,`.
150
- ElidedPathArgument ,
151
- /// The user wrote `dyn Trait` and omitted the `+ '_`.
152
- ObjectDefault ,
153
- }
154
-
155
142
impl Lifetime {
156
143
pub fn is_elided ( & self ) -> bool {
157
144
self . res . is_elided ( )
@@ -161,34 +148,28 @@ impl Lifetime {
161
148
self . ident . name == kw:: Empty || self . ident . name == kw:: UnderscoreLifetime
162
149
}
163
150
164
- pub fn suggestion_position ( & self ) -> ( LifetimeSuggestionPosition , Span ) {
151
+ pub fn suggestion ( & self , new_lifetime : & str ) -> ( Span , String ) {
152
+ debug_assert ! ( new_lifetime. starts_with( '\'' ) ) ;
153
+
165
154
if self . ident . name == kw:: Empty {
166
155
if self . ident . span . is_empty ( ) {
167
- ( LifetimeSuggestionPosition :: ElidedPathArgument , self . ident . span )
156
+ // The user wrote `Path<T>`, and omitted the `'_,`.
157
+ ( self . ident . span , format ! ( "{new_lifetime}, " ) )
168
158
} else {
169
- ( LifetimeSuggestionPosition :: ElidedPath , self . ident . span . shrink_to_hi ( ) )
159
+ // The user wrote `Path` and omitted the `<'_>`.
160
+ ( self . ident . span . shrink_to_hi ( ) , format ! ( "<{new_lifetime}>" ) )
170
161
}
171
162
} else if self . res == LifetimeName :: ImplicitObjectLifetimeDefault {
172
- ( LifetimeSuggestionPosition :: ObjectDefault , self . ident . span )
163
+ // The user wrote `dyn Trait` and omitted the `+ '_`.
164
+ ( self . ident . span , format ! ( "+ {new_lifetime}" ) )
173
165
} else if self . ident . span . is_empty ( ) {
174
- ( LifetimeSuggestionPosition :: Ampersand , self . ident . span )
166
+ // The user wrote `&type` or `&mut type`.
167
+ ( self . ident . span , format ! ( "{new_lifetime} " ) )
175
168
} else {
176
- ( LifetimeSuggestionPosition :: Normal , self . ident . span )
169
+ // The user wrote `'a` or `'_`.
170
+ ( self . ident . span , format ! ( "{new_lifetime}" ) )
177
171
}
178
172
}
179
-
180
- pub fn suggestion ( & self , new_lifetime : & str ) -> ( Span , String ) {
181
- debug_assert ! ( new_lifetime. starts_with( '\'' ) ) ;
182
- let ( pos, span) = self . suggestion_position ( ) ;
183
- let code = match pos {
184
- LifetimeSuggestionPosition :: Normal => format ! ( "{new_lifetime}" ) ,
185
- LifetimeSuggestionPosition :: Ampersand => format ! ( "{new_lifetime} " ) ,
186
- LifetimeSuggestionPosition :: ElidedPath => format ! ( "<{new_lifetime}>" ) ,
187
- LifetimeSuggestionPosition :: ElidedPathArgument => format ! ( "{new_lifetime}, " ) ,
188
- LifetimeSuggestionPosition :: ObjectDefault => format ! ( "+ {new_lifetime}" ) ,
189
- } ;
190
- ( span, code)
191
- }
192
173
}
193
174
194
175
/// A `Path` is essentially Rust's notion of a name; for instance,
0 commit comments