Skip to content

Commit f9725d5

Browse files
committed
Replace NotFound lifetime kind with a delayed bug
1 parent 80adf96 commit f9725d5

File tree

3 files changed

+30
-33
lines changed

3 files changed

+30
-33
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,30 +1931,33 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19311931
source: LifetimeSource,
19321932
syntax: LifetimeSyntax,
19331933
) -> &'hir hir::Lifetime {
1934-
let res =
1935-
self.resolver.get_lifetime_res(id).map_or(
1936-
hir::LifetimeKind::NotFound,
1937-
|res| match res {
1938-
LifetimeRes::Param { param, .. } => hir::LifetimeKind::Param(param),
1939-
LifetimeRes::Fresh { param, .. } => {
1940-
assert_eq!(ident.name, kw::UnderscoreLifetime);
1941-
let param = self.local_def_id(param);
1942-
hir::LifetimeKind::Param(param)
1943-
}
1944-
LifetimeRes::Infer => {
1945-
assert_eq!(ident.name, kw::UnderscoreLifetime);
1946-
hir::LifetimeKind::Infer
1947-
}
1948-
LifetimeRes::Static { .. } => {
1949-
assert!(matches!(ident.name, kw::StaticLifetime | kw::UnderscoreLifetime));
1950-
hir::LifetimeKind::Static
1951-
}
1952-
LifetimeRes::Error(guar) => hir::LifetimeKind::Error(guar),
1953-
LifetimeRes::ElidedAnchor { .. } => {
1954-
panic!("Unexpected `ElidedAnchar` {:?} at {:?}", ident, ident.span);
1955-
}
1956-
},
1957-
);
1934+
let res = self.resolver.get_lifetime_res(id).map_or_else(
1935+
|| {
1936+
hir::LifetimeKind::Error(
1937+
self.tcx.dcx().span_delayed_bug(ident.span, "unresolved lifetime"),
1938+
)
1939+
},
1940+
|res| match res {
1941+
LifetimeRes::Param { param, .. } => hir::LifetimeKind::Param(param),
1942+
LifetimeRes::Fresh { param, .. } => {
1943+
assert_eq!(ident.name, kw::UnderscoreLifetime);
1944+
let param = self.local_def_id(param);
1945+
hir::LifetimeKind::Param(param)
1946+
}
1947+
LifetimeRes::Infer => {
1948+
assert_eq!(ident.name, kw::UnderscoreLifetime);
1949+
hir::LifetimeKind::Infer
1950+
}
1951+
LifetimeRes::Static { .. } => {
1952+
assert!(matches!(ident.name, kw::StaticLifetime | kw::UnderscoreLifetime));
1953+
hir::LifetimeKind::Static
1954+
}
1955+
LifetimeRes::Error(guar) => hir::LifetimeKind::Error(guar),
1956+
LifetimeRes::ElidedAnchor { .. } => {
1957+
panic!("Unexpected `ElidedAnchar` {:?} at {:?}", ident, ident.span);
1958+
}
1959+
},
1960+
);
19581961

19591962
debug!(?res);
19601963
self.arena.alloc(hir::Lifetime::new(

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ pub enum LifetimeKind {
239239
/// Indicates an error during lowering (usually `'_` in wrong place)
240240
/// that was already reported.
241241
Error(ErrorGuaranteed),
242-
NotFound,
243242

244243
/// User wrote an anonymous lifetime, either `'_` or nothing (which gets
245244
/// converted to `'_`). The semantics of this lifetime should be inferred
@@ -259,10 +258,7 @@ impl LifetimeKind {
259258
// -- but this is because, as far as the code in the compiler is
260259
// concerned -- `Fresh` variants act equivalently to "some fresh name".
261260
// They correspond to early-bound regions on an impl, in other words.
262-
LifetimeKind::Error(..)
263-
| LifetimeKind::NotFound
264-
| LifetimeKind::Param(..)
265-
| LifetimeKind::Static => false,
261+
LifetimeKind::Error(..) | LifetimeKind::Param(..) | LifetimeKind::Static => false,
266262
}
267263
}
268264
}

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
663663
LifetimeKind::Param(def_id) => {
664664
self.resolve_lifetime_ref(def_id, lt);
665665
}
666-
LifetimeKind::Error(..) | LifetimeKind::NotFound => {}
666+
LifetimeKind::Error(..) => {}
667667
LifetimeKind::ImplicitObjectLifetimeDefault
668668
| LifetimeKind::Infer
669669
| LifetimeKind::Static => {
@@ -804,7 +804,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
804804
// If the user wrote an explicit name, use that.
805805
self.visit_lifetime(&*lifetime);
806806
}
807-
LifetimeKind::Error(..) | LifetimeKind::NotFound => {}
807+
LifetimeKind::Error(..) => {}
808808
}
809809
}
810810
hir::TyKind::Ref(lifetime_ref, ref mt) => {
@@ -891,8 +891,6 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
891891
hir::LifetimeKind::Param(param_def_id) => {
892892
self.resolve_lifetime_ref(param_def_id, lifetime_ref)
893893
}
894-
// Just ignore `lifetime_ref` if it couldn't be resolved
895-
hir::LifetimeKind::NotFound => {}
896894
// Keep track of lifetimes about which errors have already been reported
897895
hir::LifetimeKind::Error(guar) => {
898896
self.insert_lifetime(lifetime_ref, ResolvedArg::Error(guar))

0 commit comments

Comments
 (0)