Skip to content

Commit 825f8ed

Browse files
committed
Auto merge of rust-lang#103530 - cjgillot:hir-lifetimes-direct, r=estebank
Resolve lifetimes independently for each item-like. Now that the heavy-lifting is done on the AST and during lowering, we do not need to perform HIR lifetime resolution on a full item at once. Instead, we can treat each item-like independently, and look at `generics_of` the parent exceptionally for associated items.
2 parents b0c6527 + 6c95805 commit 825f8ed

20 files changed

+224
-384
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub(super) fn enter_wf_checking_ctxt<'tcx, F>(
117117
}
118118

119119
fn check_well_formed(tcx: TyCtxt<'_>, def_id: hir::OwnerId) {
120-
let node = tcx.hir().expect_owner(def_id);
120+
let node = tcx.hir().owner(def_id);
121121
match node {
122122
hir::OwnerNode::Crate(_) => {}
123123
hir::OwnerNode::Item(item) => check_item(tcx, item),

compiler/rustc_hir_analysis/src/collect.rs

+20-21
Original file line numberDiff line numberDiff line change
@@ -644,40 +644,39 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
644644
}
645645
}
646646

647-
// Desugared from `impl Trait`, so visited by the function's return type.
648-
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
649-
origin: hir::OpaqueTyOrigin::FnReturn(..) | hir::OpaqueTyOrigin::AsyncFn(..),
650-
..
651-
}) => {}
652-
653647
// Don't call `type_of` on opaque types, since that depends on type
654648
// checking function bodies. `check_item_type` ensures that it's called
655649
// instead.
656650
hir::ItemKind::OpaqueTy(..) => {
657651
tcx.ensure().generics_of(def_id);
658652
tcx.ensure().predicates_of(def_id);
659653
tcx.ensure().explicit_item_bounds(def_id);
654+
tcx.ensure().item_bounds(def_id);
660655
}
661-
hir::ItemKind::TyAlias(..)
662-
| hir::ItemKind::Static(..)
663-
| hir::ItemKind::Const(..)
664-
| hir::ItemKind::Fn(..) => {
656+
657+
hir::ItemKind::TyAlias(..) => {
665658
tcx.ensure().generics_of(def_id);
666659
tcx.ensure().type_of(def_id);
667660
tcx.ensure().predicates_of(def_id);
668-
match it.kind {
669-
hir::ItemKind::Fn(..) => tcx.ensure().fn_sig(def_id),
670-
hir::ItemKind::OpaqueTy(..) => tcx.ensure().item_bounds(def_id),
671-
hir::ItemKind::Const(ty, ..) | hir::ItemKind::Static(ty, ..) => {
672-
if !is_suggestable_infer_ty(ty) {
673-
let mut visitor = HirPlaceholderCollector::default();
674-
visitor.visit_item(it);
675-
placeholder_type_error(tcx, None, visitor.0, false, None, it.kind.descr());
676-
}
677-
}
678-
_ => (),
661+
}
662+
663+
hir::ItemKind::Static(ty, ..) | hir::ItemKind::Const(ty, ..) => {
664+
tcx.ensure().generics_of(def_id);
665+
tcx.ensure().type_of(def_id);
666+
tcx.ensure().predicates_of(def_id);
667+
if !is_suggestable_infer_ty(ty) {
668+
let mut visitor = HirPlaceholderCollector::default();
669+
visitor.visit_item(it);
670+
placeholder_type_error(tcx, None, visitor.0, false, None, it.kind.descr());
679671
}
680672
}
673+
674+
hir::ItemKind::Fn(..) => {
675+
tcx.ensure().generics_of(def_id);
676+
tcx.ensure().type_of(def_id);
677+
tcx.ensure().predicates_of(def_id);
678+
tcx.ensure().fn_sig(def_id);
679+
}
681680
}
682681
}
683682

0 commit comments

Comments
 (0)