Ensure valid local_data is set for custom mir building

MIR unsafety checking requires this to be valid
This commit is contained in:
Gary Guo 2022-12-01 23:41:45 +00:00
parent f03c2aef47
commit adf1717219
2 changed files with 7 additions and 1 deletions

View File

@ -20,6 +20,7 @@
use rustc_ast::Attribute;
use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::DefId;
use rustc_hir::HirId;
use rustc_index::vec::IndexVec;
use rustc_middle::{
mir::*,
@ -33,6 +34,7 @@
pub(super) fn build_custom_mir<'tcx>(
tcx: TyCtxt<'tcx>,
did: DefId,
hir_id: HirId,
thir: &Thir<'tcx>,
expr: ExprId,
params: &IndexVec<ParamId, Param<'tcx>>,
@ -67,7 +69,10 @@ pub(super) fn build_custom_mir<'tcx>(
parent_scope: None,
inlined: None,
inlined_parent_scope: None,
local_data: ClearCrossCrate::Clear,
local_data: ClearCrossCrate::Set(SourceScopeLocalData {
lint_root: hir_id,
safety: Safety::Safe,
}),
});
body.injection_phase = Some(parse_attribute(attr));

View File

@ -487,6 +487,7 @@ fn construct_fn<'tcx>(
return custom::build_custom_mir(
tcx,
fn_def.did.to_def_id(),
fn_id,
thir,
expr,
arguments,