Skip to content

Commit 2ac93ab

Browse files
committed
Assert that we do not load HIR for things we do not have HIR checks for
1 parent 6040db6 commit 2ac93ab

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
@@ -929,6 +929,8 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
929929
}));
930930
check_variances_for_type_defn(tcx, def_id);
931931
}
932+
// Doesn't have any hir based checks
933+
return res;
932934
}
933935
DefKind::ForeignMod => {
934936
let it = tcx.hir_expect_item(def_id);
@@ -991,6 +993,8 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
991993
_ => (),
992994
}
993995
}
996+
// Doesn't have any hir based checks
997+
return res;
994998
}
995999
DefKind::Closure => {
9961000
// This is guaranteed to be called by metadata encoding,
@@ -1066,10 +1070,14 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
10661070
return res;
10671071
}
10681072

1069-
// Only `Node::Item` and `Node::ForeignItem` still have HIR based
1070-
// checks. Returning early here does not miss any checks and
1071-
// avoids this query from having a direct dependency edge on the HIR
1072-
DefKind::AnonConst | DefKind::InlineConst => return res,
1073+
// These have no wf checks
1074+
DefKind::AnonConst
1075+
| DefKind::InlineConst
1076+
| DefKind::ExternCrate
1077+
| DefKind::Macro(..)
1078+
| DefKind::Use
1079+
| DefKind::GlobalAsm
1080+
| DefKind::Mod => return res,
10731081
_ => {}
10741082
}
10751083
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
@@ -292,7 +292,8 @@ pub(super) fn check_item<'tcx>(
292292
hir::ItemKind::Struct(..) => check_type_defn(tcx, item, false),
293293
hir::ItemKind::Union(..) => check_type_defn(tcx, item, true),
294294
hir::ItemKind::Enum(..) => check_type_defn(tcx, item, true),
295-
_ => Ok(()),
295+
// Note: do not add new entries to this match. Instead add all new logic in `check_item_type`
296+
_ => span_bug!(item.span, "should have been handled by the type based wf check: {item:?}"),
296297
}
297298
}
298299

0 commit comments

Comments
 (0)