Skip to content

Commit 9061538

Browse files
committed
k
1 parent 187acab commit 9061538

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

compiler/rustc_mir/src/transform/simplify_try.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,13 @@ fn optimization_applies<'tcx>(
367367
}
368368

369369
impl<'tcx> MirPass<'tcx> for SimplifyArmIdentity {
370-
fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
370+
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
371371
// FIXME(77359): This optimization can result in unsoundness.
372372
if !tcx.sess.opts.debugging_opts.unsound_mir_opts {
373373
return;
374374
}
375375

376-
trace!("running SimplifyArmIdentity on {:?}", source);
376+
trace!("running SimplifyArmIdentity on {:?}", body.source);
377377
let source = body.source;
378378
let local_uses = LocalUseCounter::get_local_uses(body);
379379
let (basic_blocks, local_decls, debug_info) =

compiler/rustc_mir_build/src/build/mod.rs

+26-12
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ crate fn mir_built<'tcx>(
2929
return tcx.mir_built(def);
3030
}
3131

32-
let mut body = mir_build(tcx, def);
33-
if def.const_param_did.is_some() {
34-
assert!(matches!(body.source.instance, ty::InstanceDef::Item(_)));
35-
body.source = MirSource::from_instance(ty::InstanceDef::Item(def.to_global()));
36-
}
32+
let body = mir_build(tcx, def);
3733

3834
tcx.alloc_steal_mir(body)
3935
}
@@ -302,7 +298,7 @@ struct Builder<'a, 'tcx> {
302298
hir: Cx<'a, 'tcx>,
303299
cfg: CFG<'tcx>,
304300

305-
def_id: DefId,
301+
def: ty::WithOptConstParam<DefId>,
306302
fn_span: Span,
307303
arg_count: usize,
308304
generator_kind: Option<GeneratorKind>,
@@ -604,7 +600,7 @@ where
604600

605601
let mut builder = Builder::new(
606602
hir,
607-
fn_def_id.to_def_id(),
603+
ty::WithOptConstParam::unknown(fn_def_id.to_def_id()),
608604
span_with_body,
609605
arguments.len(),
610606
safety,
@@ -685,7 +681,16 @@ fn construct_const<'a, 'tcx>(
685681
let owner_id = tcx.hir().body_owner(body_id);
686682
let def_id = tcx.hir().local_def_id(owner_id);
687683
let span = tcx.hir().span(owner_id);
688-
let mut builder = Builder::new(hir, def_id.to_def_id(), span, 0, Safety::Safe, const_ty, const_ty_span, None);
684+
let mut builder = Builder::new(
685+
hir,
686+
ty::WithOptConstParam::unknown(def_id.to_def_id()),
687+
span,
688+
0,
689+
Safety::Safe,
690+
const_ty,
691+
const_ty_span,
692+
None
693+
);
689694

690695
let mut block = START_BLOCK;
691696
let ast_expr = &tcx.hir().body(body_id).value;
@@ -732,7 +737,16 @@ fn construct_error<'a, 'tcx>(hir: Cx<'a, 'tcx>, body_id: hir::BodyId) -> Body<'t
732737
hir::BodyOwnerKind::Const => 0,
733738
hir::BodyOwnerKind::Static(_) => 0,
734739
};
735-
let mut builder = Builder::new(hir, def_id.to_def_id(), span, num_params, Safety::Safe, ty, span, None);
740+
let mut builder = Builder::new(
741+
hir,
742+
ty::WithOptConstParam::unknown(def_id.to_def_id()),
743+
span,
744+
num_params,
745+
Safety::Safe,
746+
ty,
747+
span,
748+
None
749+
);
736750
let source_info = builder.source_info(span);
737751
// Some MIR passes will expect the number of parameters to match the
738752
// function declaration.
@@ -750,7 +764,7 @@ fn construct_error<'a, 'tcx>(hir: Cx<'a, 'tcx>, body_id: hir::BodyId) -> Body<'t
750764
impl<'a, 'tcx> Builder<'a, 'tcx> {
751765
fn new(
752766
hir: Cx<'a, 'tcx>,
753-
def_id: DefId,
767+
def: ty::WithOptConstParam<DefId>,
754768
span: Span,
755769
arg_count: usize,
756770
safety: Safety,
@@ -761,7 +775,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
761775
let lint_level = LintLevel::Explicit(hir.root_lint_level);
762776
let mut builder = Builder {
763777
hir,
764-
def_id,
778+
def,
765779
cfg: CFG { basic_blocks: IndexVec::new() },
766780
fn_span: span,
767781
arg_count,
@@ -802,7 +816,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
802816
}
803817

804818
Body::new(
805-
MirSource::item(self.def_id),
819+
MirSource::from_instance(ty::InstanceDef::Item(self.def)),
806820
self.cfg.basic_blocks,
807821
self.source_scopes,
808822
self.local_decls,

0 commit comments

Comments
 (0)