Avoid accessing HIR from MIR queries.

This commit is contained in:
Camille GILLOT 2022-03-29 23:50:01 +02:00
parent 341883d051
commit db03a2deb0
10 changed files with 35 additions and 41 deletions

View file

@ -71,8 +71,9 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
}
let def_id = body.source.def_id().expect_local();
let is_fn_like = tcx.hir().get_by_def_id(def_id).fn_kind().is_some();
let is_assoc_const = tcx.def_kind(def_id) == DefKind::AssocConst;
let def_kind = tcx.def_kind(def_id);
let is_fn_like = def_kind.is_fn_like();
let is_assoc_const = def_kind == DefKind::AssocConst;
// Only run const prop on functions, methods, closures and associated constants
if !is_fn_like && !is_assoc_const {

View file

@ -67,7 +67,7 @@ impl<'tcx> MirLint<'tcx> for ConstProp {
}
let def_id = body.source.def_id().expect_local();
let is_fn_like = tcx.hir().get_by_def_id(def_id).fn_kind().is_some();
let is_fn_like = tcx.def_kind(def_id).is_fn_like();
let is_assoc_const = tcx.def_kind(def_id) == DefKind::AssocConst;
// Only run const prop on functions, methods, closures and associated constants

View file

@ -366,7 +366,7 @@ fn mir_drops_elaborated_and_const_checked<'tcx>(
let mir_borrowck = tcx.mir_borrowck_opt_const_arg(def);
let is_fn_like = tcx.hir().get_by_def_id(def.did).fn_kind().is_some();
let is_fn_like = tcx.def_kind(def.did).is_fn_like();
if is_fn_like {
let did = def.did.to_def_id();
let def = ty::WithOptConstParam::unknown(did);

View file

@ -725,9 +725,6 @@ fn build_call_shim<'tcx>(
pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> {
debug_assert!(tcx.is_constructor(ctor_id));
let span =
tcx.hir().span_if_local(ctor_id).unwrap_or_else(|| bug!("no span for ctor {:?}", ctor_id));
let param_env = tcx.param_env(ctor_id);
// Normalize the sig.
@ -740,6 +737,8 @@ pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> {
debug!("build_ctor: ctor_id={:?} sig={:?}", ctor_id, sig);
let span = tcx.def_span(ctor_id);
let local_decls = local_decls_for_sig(&sig, span);
let source_info = SourceInfo::outermost(span);