@@ -184,84 +184,74 @@ fn msg_span_from_named_region<'tcx>(
184
184
region : ty:: Region < ' tcx > ,
185
185
alt_span : Option < Span > ,
186
186
) -> ( String , Option < Span > ) {
187
- match * region {
188
- ty:: ReEarlyBound ( _) | ty:: ReFree ( _) => {
189
- let ( msg, span) = msg_span_from_early_bound_and_free_regions ( tcx, region) ;
190
- ( msg, Some ( span) )
191
- }
192
- ty:: ReStatic => ( "the static lifetime" . to_owned ( ) , alt_span) ,
193
- ty:: RePlaceholder ( ty:: PlaceholderRegion {
194
- bound : ty:: BoundRegion { kind : ty:: BoundRegionKind :: BrNamed ( def_id, name) , .. } ,
195
- ..
196
- } ) => ( format ! ( "the lifetime `{name}` as defined here" ) , Some ( tcx. def_span ( def_id) ) ) ,
197
- ty:: RePlaceholder ( ty:: PlaceholderRegion {
198
- bound : ty:: BoundRegion { kind : ty:: BoundRegionKind :: BrAnon ( Some ( span) ) , .. } ,
199
- ..
200
- } ) => ( format ! ( "the anonymous lifetime defined here" ) , Some ( span) ) ,
201
- ty:: RePlaceholder ( ty:: PlaceholderRegion {
202
- bound : ty:: BoundRegion { kind : ty:: BoundRegionKind :: BrAnon ( None ) , .. } ,
203
- ..
204
- } ) => ( format ! ( "an anonymous lifetime" ) , None ) ,
205
- _ => bug ! ( "{:?}" , region) ,
206
- }
207
- }
208
-
209
- fn msg_span_from_early_bound_and_free_regions < ' tcx > (
210
- tcx : TyCtxt < ' tcx > ,
211
- region : ty:: Region < ' tcx > ,
212
- ) -> ( String , Span ) {
213
- let scope = region. free_region_binding_scope ( tcx) . expect_local ( ) ;
214
187
match * region {
215
188
ty:: ReEarlyBound ( ref br) => {
216
- let mut sp = tcx. def_span ( scope ) ;
217
- if let Some ( param) =
189
+ let scope = region . free_region_binding_scope ( tcx) . expect_local ( ) ;
190
+ let span = if let Some ( param) =
218
191
tcx. hir ( ) . get_generics ( scope) . and_then ( |generics| generics. get_named ( br. name ) )
219
192
{
220
- sp = param. span ;
221
- }
193
+ param. span
194
+ } else {
195
+ tcx. def_span ( scope)
196
+ } ;
222
197
let text = if br. has_name ( ) {
223
198
format ! ( "the lifetime `{}` as defined here" , br. name)
224
199
} else {
225
200
"the anonymous lifetime as defined here" . to_string ( )
226
201
} ;
227
- ( text, sp )
202
+ ( text, Some ( span ) )
228
203
}
229
204
ty:: ReFree ( ref fr) => {
230
205
if !fr. bound_region . is_named ( )
231
206
&& let Some ( ( ty, _) ) = find_anon_type ( tcx, region, & fr. bound_region )
232
207
{
233
- ( "the anonymous lifetime defined here" . to_string ( ) , ty. span )
208
+ ( "the anonymous lifetime defined here" . to_string ( ) , Some ( ty. span ) )
234
209
} else {
210
+ let scope = region. free_region_binding_scope ( tcx) . expect_local ( ) ;
235
211
match fr. bound_region {
236
212
ty:: BoundRegionKind :: BrNamed ( _, name) => {
237
- let mut sp = tcx. def_span ( scope) ;
238
- if let Some ( param) =
213
+ let span = if let Some ( param) =
239
214
tcx. hir ( ) . get_generics ( scope) . and_then ( |generics| generics. get_named ( name) )
240
215
{
241
- sp = param. span ;
242
- }
216
+ param. span
217
+ } else {
218
+ tcx. def_span ( scope)
219
+ } ;
243
220
let text = if name == kw:: UnderscoreLifetime {
244
221
"the anonymous lifetime as defined here" . to_string ( )
245
222
} else {
246
223
format ! ( "the lifetime `{}` as defined here" , name)
247
224
} ;
248
- ( text, sp )
225
+ ( text, Some ( span ) )
249
226
}
250
227
ty:: BrAnon ( span) => (
251
228
"the anonymous lifetime as defined here" . to_string ( ) ,
252
- match span {
229
+ Some ( match span {
253
230
Some ( span) => span,
254
231
None => tcx. def_span ( scope)
255
- }
232
+ } )
256
233
) ,
257
234
_ => (
258
235
format ! ( "the lifetime `{}` as defined here" , region) ,
259
- tcx. def_span ( scope) ,
236
+ Some ( tcx. def_span ( scope) ) ,
260
237
) ,
261
238
}
262
239
}
263
240
}
264
- _ => bug ! ( ) ,
241
+ ty:: ReStatic => ( "the static lifetime" . to_owned ( ) , alt_span) ,
242
+ ty:: RePlaceholder ( ty:: PlaceholderRegion {
243
+ bound : ty:: BoundRegion { kind : ty:: BoundRegionKind :: BrNamed ( def_id, name) , .. } ,
244
+ ..
245
+ } ) => ( format ! ( "the lifetime `{name}` as defined here" ) , Some ( tcx. def_span ( def_id) ) ) ,
246
+ ty:: RePlaceholder ( ty:: PlaceholderRegion {
247
+ bound : ty:: BoundRegion { kind : ty:: BoundRegionKind :: BrAnon ( Some ( span) ) , .. } ,
248
+ ..
249
+ } ) => ( format ! ( "the anonymous lifetime defined here" ) , Some ( span) ) ,
250
+ ty:: RePlaceholder ( ty:: PlaceholderRegion {
251
+ bound : ty:: BoundRegion { kind : ty:: BoundRegionKind :: BrAnon ( None ) , .. } ,
252
+ ..
253
+ } ) => ( format ! ( "an anonymous lifetime" ) , None ) ,
254
+ _ => bug ! ( "{:?}" , region) ,
265
255
}
266
256
}
267
257
0 commit comments