Skip to content

Commit 324d950

Browse files
committed
Assert that we do not load HIR for things we do not have HIR checks for
1 parent ae099c2 commit 324d950

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,8 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
928928
}));
929929
check_variances_for_type_defn(tcx, def_id);
930930
}
931+
// Doesn't have any hir based checks
932+
return res;
931933
}
932934
DefKind::ForeignMod => {
933935
let it = tcx.hir_expect_item(def_id);
@@ -990,6 +992,8 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
990992
_ => (),
991993
}
992994
}
995+
// Doesn't have any hir based checks
996+
return res;
993997
}
994998
DefKind::Closure => {
995999
// This is guaranteed to be called by metadata encoding,
@@ -1065,10 +1069,14 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
10651069
return res;
10661070
}
10671071

1068-
// Only `Node::Item` and `Node::ForeignItem` still have HIR based
1069-
// checks. Returning early here does not miss any checks and
1070-
// avoids this query from having a direct dependency edge on the HIR
1071-
DefKind::AnonConst | DefKind::InlineConst => return res,
1072+
// These have no wf checks
1073+
DefKind::AnonConst
1074+
| DefKind::InlineConst
1075+
| DefKind::ExternCrate
1076+
| DefKind::Macro(..)
1077+
| DefKind::Use
1078+
| DefKind::GlobalAsm
1079+
| DefKind::Mod => return res,
10721080
_ => {}
10731081
}
10741082
let node = tcx.hir_node_by_def_id(def_id);

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ pub(super) fn check_item<'tcx>(
293293
hir::ItemKind::Struct(..) => check_type_defn(tcx, item, false),
294294
hir::ItemKind::Union(..) => check_type_defn(tcx, item, true),
295295
hir::ItemKind::Enum(..) => check_type_defn(tcx, item, true),
296-
_ => Ok(()),
296+
// Note: do not add new entries to this match. Instead add all new logic in `check_item_type`
297+
_ => span_bug!(item.span, "should have been handled by the type based wf check: {item:?}"),
297298
}
298299
}
299300

0 commit comments

Comments
 (0)