Skip to content

Commit 034975a

Browse files
Make mark_inactive_variants_as_uninit configurable
1 parent 527a685 commit 034975a

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/librustc_mir/borrow_check/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ fn do_mir_borrowck<'a, 'tcx>(
204204
let mdpe = MoveDataParamEnv { move_data, param_env };
205205

206206
let mut flow_inits = MaybeInitializedPlaces::new(tcx, &body, &mdpe)
207+
.mark_inactive_variants_as_uninit(true)
207208
.into_engine(tcx, &body, def.did.to_def_id())
208209
.iterate_to_fixpoint()
209210
.into_results_cursor(&body);

src/librustc_mir/dataflow/impls/mod.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,17 @@ pub struct MaybeInitializedPlaces<'a, 'tcx> {
7171
tcx: TyCtxt<'tcx>,
7272
body: &'a Body<'tcx>,
7373
mdpe: &'a MoveDataParamEnv<'tcx>,
74+
mark_inactive_variants_as_uninit: bool,
7475
}
7576

7677
impl<'a, 'tcx> MaybeInitializedPlaces<'a, 'tcx> {
7778
pub fn new(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'tcx>) -> Self {
78-
MaybeInitializedPlaces { tcx, body, mdpe }
79+
MaybeInitializedPlaces { tcx, body, mdpe, mark_inactive_variants_as_uninit: false }
80+
}
81+
82+
pub fn mark_inactive_variants_as_uninit(mut self, yes: bool) -> Self {
83+
self.mark_inactive_variants_as_uninit = yes;
84+
self
7985
}
8086
}
8187

@@ -138,8 +144,8 @@ impl<'a, 'tcx> MaybeUninitializedPlaces<'a, 'tcx> {
138144
///
139145
/// This is correct in a vacuum but is not the default because it causes problems in the borrow
140146
/// checker, where this information gets propagated along `FakeEdge`s.
141-
pub fn mark_inactive_variants_as_uninit(mut self) -> Self {
142-
self.mark_inactive_variants_as_uninit = true;
147+
pub fn mark_inactive_variants_as_uninit(mut self, yes: bool) -> Self {
148+
self.mark_inactive_variants_as_uninit = yes;
143149
self
144150
}
145151
}
@@ -362,6 +368,10 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
362368
_adt: &ty::AdtDef,
363369
variant: VariantIdx,
364370
) {
371+
if !self.mark_inactive_variants_as_uninit {
372+
return;
373+
}
374+
365375
// Kill all move paths that correspond to variants we know to be inactive along this
366376
// particular outgoing edge of a `SwitchInt`.
367377
drop_flag_effects::on_all_inactive_variants(

src/librustc_mir/transform/elaborate_drops.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ impl<'tcx> MirPass<'tcx> for ElaborateDrops {
4242
let dead_unwinds = find_dead_unwinds(tcx, body, def_id, &env);
4343

4444
let inits = MaybeInitializedPlaces::new(tcx, body, &env)
45+
.mark_inactive_variants_as_uninit(true)
4546
.into_engine(tcx, body, def_id)
4647
.dead_unwinds(&dead_unwinds)
4748
.iterate_to_fixpoint()
4849
.into_results_cursor(body);
4950

5051
let uninits = MaybeUninitializedPlaces::new(tcx, body, &env)
51-
.mark_inactive_variants_as_uninit()
52+
.mark_inactive_variants_as_uninit(true)
5253
.into_engine(tcx, body, def_id)
5354
.dead_unwinds(&dead_unwinds)
5455
.iterate_to_fixpoint()
@@ -82,6 +83,7 @@ fn find_dead_unwinds<'tcx>(
8283
// reach cleanup blocks, which can't have unwind edges themselves.
8384
let mut dead_unwinds = BitSet::new_empty(body.basic_blocks().len());
8485
let mut flow_inits = MaybeInitializedPlaces::new(tcx, body, &env)
86+
.mark_inactive_variants_as_uninit(true)
8587
.into_engine(tcx, body, def_id)
8688
.iterate_to_fixpoint()
8789
.into_results_cursor(body);

0 commit comments

Comments
 (0)