@@ -205,12 +205,39 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
205
205
def : Option < & ty:: GenericParamDef > ,
206
206
) -> ty:: Region < ' tcx > {
207
207
let tcx = self . tcx ( ) ;
208
+
209
+ let r = if let Some ( rl) = tcx. named_region ( lifetime. hir_id ) {
210
+ self . ast_region_to_region_inner ( rl)
211
+ } else {
212
+ self . re_infer ( def, lifetime. span ) . unwrap_or_else ( || {
213
+ debug ! ( ?lifetime, "unelided lifetime in signature" ) ;
214
+
215
+ // This indicates an illegal lifetime
216
+ // elision. `resolve_lifetime` should have
217
+ // reported an error in this case -- but if
218
+ // not, let's error out.
219
+ tcx. sess . delay_span_bug ( lifetime. span , "unelided lifetime in signature" ) ;
220
+
221
+ // Supply some dummy value. We don't have an
222
+ // `re_error`, annoyingly, so use `'static`.
223
+ tcx. lifetimes . re_static
224
+ } )
225
+ } ;
226
+
227
+ debug ! ( "ast_region_to_region(lifetime={:?}) yields {:?}" , lifetime, r) ;
228
+
229
+ r
230
+ }
231
+
232
+ #[ tracing:: instrument( level = "debug" , skip( self ) ) ]
233
+ fn ast_region_to_region_inner ( & self , lifetime : rl:: Region ) -> ty:: Region < ' tcx > {
234
+ let tcx = self . tcx ( ) ;
208
235
let lifetime_name = |def_id| tcx. hir ( ) . name ( tcx. hir ( ) . local_def_id_to_hir_id ( def_id) ) ;
209
236
210
- let r = match tcx . named_region ( lifetime. hir_id ) {
211
- Some ( rl:: Region :: Static ) => tcx. lifetimes . re_static ,
237
+ let r = match lifetime {
238
+ rl:: Region :: Static => tcx. lifetimes . re_static ,
212
239
213
- Some ( rl:: Region :: LateBound ( debruijn, index, def_id) ) => {
240
+ rl:: Region :: LateBound ( debruijn, index, def_id) => {
214
241
let name = lifetime_name ( def_id. expect_local ( ) ) ;
215
242
let br = ty:: BoundRegion {
216
243
var : ty:: BoundVar :: from_u32 ( index) ,
@@ -219,20 +246,20 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
219
246
tcx. mk_region ( ty:: ReLateBound ( debruijn, br) )
220
247
}
221
248
222
- Some ( rl:: Region :: LateBoundAnon ( debruijn, index, anon_index) ) => {
249
+ rl:: Region :: LateBoundAnon ( debruijn, index, anon_index) => {
223
250
let br = ty:: BoundRegion {
224
251
var : ty:: BoundVar :: from_u32 ( index) ,
225
252
kind : ty:: BrAnon ( anon_index) ,
226
253
} ;
227
254
tcx. mk_region ( ty:: ReLateBound ( debruijn, br) )
228
255
}
229
256
230
- Some ( rl:: Region :: EarlyBound ( index, id) ) => {
257
+ rl:: Region :: EarlyBound ( index, id) => {
231
258
let name = lifetime_name ( id. expect_local ( ) ) ;
232
259
tcx. mk_region ( ty:: ReEarlyBound ( ty:: EarlyBoundRegion { def_id : id, index, name } ) )
233
260
}
234
261
235
- Some ( rl:: Region :: Free ( scope, id) ) => {
262
+ rl:: Region :: Free ( scope, id) => {
236
263
let name = lifetime_name ( id. expect_local ( ) ) ;
237
264
tcx. mk_region ( ty:: ReFree ( ty:: FreeRegion {
238
265
scope,
@@ -241,22 +268,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
241
268
242
269
// (*) -- not late-bound, won't change
243
270
}
244
-
245
- None => {
246
- self . re_infer ( def, lifetime. span ) . unwrap_or_else ( || {
247
- debug ! ( ?lifetime, "unelided lifetime in signature" ) ;
248
-
249
- // This indicates an illegal lifetime
250
- // elision. `resolve_lifetime` should have
251
- // reported an error in this case -- but if
252
- // not, let's error out.
253
- tcx. sess . delay_span_bug ( lifetime. span , "unelided lifetime in signature" ) ;
254
-
255
- // Supply some dummy value. We don't have an
256
- // `re_error`, annoyingly, so use `'static`.
257
- tcx. lifetimes . re_static
258
- } )
259
- }
260
271
} ;
261
272
262
273
debug ! ( "ast_region_to_region(lifetime={:?}) yields {:?}" , lifetime, r) ;
0 commit comments