Skip to content

Commit 75f0271

Browse files
committed
Split ast_region_to_region in two parts.
1 parent 549f25e commit 75f0271

File tree

1 file changed

+33
-22
lines changed
  • compiler/rustc_typeck/src/astconv

1 file changed

+33
-22
lines changed

compiler/rustc_typeck/src/astconv/mod.rs

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,39 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
205205
def: Option<&ty::GenericParamDef>,
206206
) -> ty::Region<'tcx> {
207207
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();
208235
let lifetime_name = |def_id| tcx.hir().name(tcx.hir().local_def_id_to_hir_id(def_id));
209236

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,
212239

213-
Some(rl::Region::LateBound(debruijn, index, def_id)) => {
240+
rl::Region::LateBound(debruijn, index, def_id) => {
214241
let name = lifetime_name(def_id.expect_local());
215242
let br = ty::BoundRegion {
216243
var: ty::BoundVar::from_u32(index),
@@ -219,20 +246,20 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
219246
tcx.mk_region(ty::ReLateBound(debruijn, br))
220247
}
221248

222-
Some(rl::Region::LateBoundAnon(debruijn, index, anon_index)) => {
249+
rl::Region::LateBoundAnon(debruijn, index, anon_index) => {
223250
let br = ty::BoundRegion {
224251
var: ty::BoundVar::from_u32(index),
225252
kind: ty::BrAnon(anon_index),
226253
};
227254
tcx.mk_region(ty::ReLateBound(debruijn, br))
228255
}
229256

230-
Some(rl::Region::EarlyBound(index, id)) => {
257+
rl::Region::EarlyBound(index, id) => {
231258
let name = lifetime_name(id.expect_local());
232259
tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { def_id: id, index, name }))
233260
}
234261

235-
Some(rl::Region::Free(scope, id)) => {
262+
rl::Region::Free(scope, id) => {
236263
let name = lifetime_name(id.expect_local());
237264
tcx.mk_region(ty::ReFree(ty::FreeRegion {
238265
scope,
@@ -241,22 +268,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
241268

242269
// (*) -- not late-bound, won't change
243270
}
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-
}
260271
};
261272

262273
debug!("ast_region_to_region(lifetime={:?}) yields {:?}", lifetime, r);

0 commit comments

Comments
 (0)