Skip to main content

rustc_mir_dataflow/impls/
initialized.rs

1use std::assert_matches;
2
3use rustc_abi::VariantIdx;
4use rustc_index::Idx;
5use rustc_index::bit_set::{DenseBitSet, MixedBitSet};
6use rustc_middle::bug;
7use rustc_middle::mir::{self, Body, CallReturnPlaces, Location, TerminatorEdges};
8use rustc_middle::ty::{self, TyCtxt};
9use smallvec::SmallVec;
10use tracing::{debug, instrument};
11
12use crate::drop_flag_effects::{DropFlagState, InactiveVariants};
13use crate::move_paths::{HasMoveData, InitIndex, InitKind, LookupResult, MoveData, MovePathIndex};
14use crate::{
15    Analysis, GenKill, MaybeReachable, SwitchTargetIndex, drop_flag_effects,
16    drop_flag_effects_for_function_entry, drop_flag_effects_for_location, on_all_children_bits,
17    on_lookup_result_bits,
18};
19
20// Used by both `MaybeInitializedPlaces` and `MaybeUninitializedPlaces`.
21pub struct MaybePlacesSwitchIntData<'tcx> {
22    enum_place: mir::Place<'tcx>,
23
24    // Variant indices targeted by the SwitchInt. For example, if you have:
25    // ```
26    // enum E { A = 1, B = 3, C = 5, D = 7 }
27    // ```
28    // and a `SwitchInt(A -> bb1, C -> bb2, _ -> bb3)`, this vec will contain `[0, 2]` because
29    // those are the variant indices for `A` and `C`.
30    variants: SmallVec<[VariantIdx; 4]>,
31}
32
33impl<'tcx> MaybePlacesSwitchIntData<'tcx> {
34    fn new(
35        tcx: TyCtxt<'tcx>,
36        body: &Body<'tcx>,
37        block: mir::BasicBlock,
38        targets: &mir::SwitchTargets,
39        discr: &mir::Operand<'tcx>,
40    ) -> Option<Self> {
41        let Some(discr) = discr.place() else { return None };
42
43        // Inspect a `SwitchInt`-terminated basic block to see if the condition of that `SwitchInt`
44        // is an enum discriminant.
45        //
46        // We expect such blocks to have a call to `discriminant` as their last statement like so:
47        // ```text
48        // ...
49        // _42 = discriminant(_1)
50        // SwitchInt(_42, ..)
51        // ```
52        // If the basic block matches this pattern, this function gathers the place corresponding
53        // to the enum (`_1` in the example above) as well as the discriminants.
54        let block_data = &body[block];
55        for statement in block_data.statements.iter().rev() {
56            match statement.kind {
57                mir::StatementKind::Assign((lhs, mir::Rvalue::Discriminant(enum_place)))
58                    if lhs == discr =>
59                {
60                    match enum_place.ty(body, tcx).ty.kind() {
61                        ty::Adt(enum_def, _) => {
62                            // The value of each discriminant, in AdtDef order.
63                            let discriminant_vals: SmallVec<[u128; 4]> =
64                                enum_def.discriminants(tcx).map(|(_, discr)| discr.val).collect();
65                            let mut i = 0;
66
67                            // For each value in the SwitchInt, find the VariantIdx for the variant
68                            // with that value. This works because `discriminant_vals` and
69                            // `targets.all_values()` are guaranteed to list variants in the same
70                            // order. (If that ever changes we will get out-of-bounds panics here.)
71                            let variants = targets
72                                .all_values()
73                                .iter()
74                                .map(|value| {
75                                    loop {
76                                        if discriminant_vals[i] == value.get() {
77                                            return VariantIdx::new(i);
78                                        }
79                                        i += 1;
80                                    }
81                                })
82                                .collect();
83
84                            return Some(MaybePlacesSwitchIntData { enum_place, variants });
85                        }
86
87                        // `Rvalue::Discriminant` is also used to get the active yield point for a
88                        // coroutine, but we do not need edge-specific effects in that case. This
89                        // may change in the future.
90                        ty::Coroutine(..) => break,
91
92                        t => ::rustc_middle::util::bug::bug_fmt(format_args!("`discriminant` called on unexpected type {0:?}",
        t))bug!("`discriminant` called on unexpected type {:?}", t),
93                    }
94                }
95                mir::StatementKind::Coverage(_) => continue,
96                _ => break,
97            }
98        }
99        None
100    }
101}
102
103/// `MaybeInitializedPlaces` tracks all places that might be
104/// initialized upon reaching a particular point in the control flow
105/// for a function.
106///
107/// For example, in code like the following, we have corresponding
108/// dataflow information shown in the right-hand comments.
109///
110/// ```rust
111/// struct S;
112/// #[rustfmt::skip]
113/// fn foo(p: bool) {                           // maybe-init:
114///                                             // {p}
115///     let a = S; let mut b = S; let c; let d; // {p, a, b}
116///
117///     if p {
118///         drop(a);                            // {p,    b}
119///         b = S;                              // {p,    b}
120///
121///     } else {
122///         drop(b);                            // {p, a}
123///         d = S;                              // {p, a,       d}
124///
125///     }                                       // {p, a, b,    d}
126///
127///     c = S;                                  // {p, a, b, c, d}
128/// }
129/// ```
130///
131/// To determine whether a place is *definitely* initialized at a
132/// particular control-flow point, one can take the set-complement
133/// of the data from `MaybeUninitializedPlaces` at the corresponding
134/// control-flow point.
135///
136/// Similarly, at a given `drop` statement, the set-intersection
137/// between this data and `MaybeUninitializedPlaces` yields the set of
138/// places that would require a dynamic drop-flag at that statement.
139pub struct MaybeInitializedPlaces<'a, 'tcx> {
140    tcx: TyCtxt<'tcx>,
141    body: &'a Body<'tcx>,
142    move_data: &'a MoveData<'tcx>,
143    exclude_inactive_in_otherwise: bool,
144    skip_unreachable_unwind: bool,
145}
146
147impl<'a, 'tcx> MaybeInitializedPlaces<'a, 'tcx> {
148    pub fn new(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, move_data: &'a MoveData<'tcx>) -> Self {
149        MaybeInitializedPlaces {
150            tcx,
151            body,
152            move_data,
153            exclude_inactive_in_otherwise: false,
154            skip_unreachable_unwind: false,
155        }
156    }
157
158    /// Ensures definitely inactive variants are excluded from the set of initialized places for
159    /// blocks reached through an `otherwise` edge.
160    pub fn exclude_inactive_in_otherwise(mut self) -> Self {
161        self.exclude_inactive_in_otherwise = true;
162        self
163    }
164
165    pub fn skipping_unreachable_unwind(mut self) -> Self {
166        self.skip_unreachable_unwind = true;
167        self
168    }
169
170    pub fn is_unwind_dead(
171        &self,
172        place: mir::Place<'tcx>,
173        state: &<Self as Analysis<'tcx>>::Domain,
174    ) -> bool {
175        if let LookupResult::Exact(path) = self.move_data().rev_lookup.find(place.as_ref()) {
176            let mut maybe_live = false;
177            on_all_children_bits(self.move_data(), path, |child| {
178                maybe_live |= state.contains(child);
179            });
180            !maybe_live
181        } else {
182            false
183        }
184    }
185}
186
187impl<'a, 'tcx> HasMoveData<'tcx> for MaybeInitializedPlaces<'a, 'tcx> {
188    fn move_data(&self) -> &MoveData<'tcx> {
189        self.move_data
190    }
191}
192
193/// `MaybeUninitializedPlaces` tracks all places that might be
194/// uninitialized upon reaching a particular point in the control flow
195/// for a function.
196///
197/// For example, in code like the following, we have corresponding
198/// dataflow information shown in the right-hand comments.
199///
200/// ```rust
201/// struct S;
202/// #[rustfmt::skip]
203/// fn foo(p: bool) {                           // maybe-uninit:
204///                                             // {a, b, c, d}
205///     let a = S; let mut b = S; let c; let d; // {      c, d}
206///
207///     if p {
208///         drop(a);                            // {a,    c, d}
209///         b = S;                              // {a,    c, d}
210///
211///     } else {
212///         drop(b);                            // {   b, c, d}
213///         d = S;                              // {   b, c   }
214///
215///     }                                       // {a, b, c, d}
216///
217///     c = S;                                  // {a, b,    d}
218/// }
219/// ```
220///
221/// To determine whether a place is *definitely* uninitialized at a
222/// particular control-flow point, one can take the set-complement
223/// of the data from `MaybeInitializedPlaces` at the corresponding
224/// control-flow point.
225///
226/// Similarly, at a given `drop` statement, the set-intersection
227/// between this data and `MaybeInitializedPlaces` yields the set of
228/// places that would require a dynamic drop-flag at that statement.
229pub struct MaybeUninitializedPlaces<'a, 'tcx> {
230    tcx: TyCtxt<'tcx>,
231    body: &'a Body<'tcx>,
232    move_data: &'a MoveData<'tcx>,
233
234    mark_inactive_variants_as_uninit: bool,
235    include_inactive_in_otherwise: bool,
236    skip_unreachable_unwind: DenseBitSet<mir::BasicBlock>,
237}
238
239impl<'a, 'tcx> MaybeUninitializedPlaces<'a, 'tcx> {
240    pub fn new(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, move_data: &'a MoveData<'tcx>) -> Self {
241        MaybeUninitializedPlaces {
242            tcx,
243            body,
244            move_data,
245            mark_inactive_variants_as_uninit: false,
246            include_inactive_in_otherwise: false,
247            skip_unreachable_unwind: DenseBitSet::new_empty(body.basic_blocks.len()),
248        }
249    }
250
251    /// Causes inactive enum variants to be marked as "maybe uninitialized" after a switch on an
252    /// enum discriminant.
253    ///
254    /// This is correct in a vacuum but is not the default because it causes problems in the borrow
255    /// checker, where this information gets propagated along `FakeEdge`s.
256    pub fn mark_inactive_variants_as_uninit(mut self) -> Self {
257        self.mark_inactive_variants_as_uninit = true;
258        self
259    }
260
261    /// Ensures definitely inactive variants are included in the set of uninitialized places for
262    /// blocks reached through an `otherwise` edge.
263    pub fn include_inactive_in_otherwise(mut self) -> Self {
264        self.include_inactive_in_otherwise = true;
265        self
266    }
267
268    pub fn skipping_unreachable_unwind(
269        mut self,
270        unreachable_unwind: DenseBitSet<mir::BasicBlock>,
271    ) -> Self {
272        self.skip_unreachable_unwind = unreachable_unwind;
273        self
274    }
275}
276
277impl<'tcx> HasMoveData<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
278    fn move_data(&self) -> &MoveData<'tcx> {
279        self.move_data
280    }
281}
282
283/// `EverInitializedPlaces` tracks all initializations that may have occurred
284/// upon reaching a particular point in the control flow for a function,
285/// without an intervening `StorageDead`.
286///
287/// This dataflow is used to determine if an immutable local variable may
288/// be assigned to.
289///
290/// For example, in code like the following, we have corresponding
291/// dataflow information shown in the right-hand comments. Underscored indices
292/// are used to distinguish between multiple initializations of the same local
293/// variable, e.g. `b_0` and `b_1`.
294///
295/// ```rust
296/// struct S;
297/// #[rustfmt::skip]
298/// fn foo(p: bool) {                           // ever-init:
299///                                             // {p,                  }
300///     let a = S; let mut b = S; let c; let d; // {p, a, b_0,          }
301///
302///     if p {
303///         drop(a);                            // {p, a, b_0,          }
304///         b = S;                              // {p, a, b_0, b_1,     }
305///
306///     } else {
307///         drop(b);                            // {p, a, b_0, b_1,     }
308///         d = S;                              // {p, a, b_0, b_1,    d}
309///
310///     }                                       // {p, a, b_0, b_1,    d}
311///
312///     c = S;                                  // {p, a, b_0, b_1, c, d}
313/// }
314/// ```
315pub struct EverInitializedPlaces<'a, 'tcx> {
316    body: &'a Body<'tcx>,
317    move_data: &'a MoveData<'tcx>,
318}
319
320impl<'a, 'tcx> EverInitializedPlaces<'a, 'tcx> {
321    pub fn new(body: &'a Body<'tcx>, move_data: &'a MoveData<'tcx>) -> Self {
322        EverInitializedPlaces { body, move_data }
323    }
324}
325
326impl<'tcx> HasMoveData<'tcx> for EverInitializedPlaces<'_, 'tcx> {
327    fn move_data(&self) -> &MoveData<'tcx> {
328        self.move_data
329    }
330}
331
332impl<'a, 'tcx> MaybeInitializedPlaces<'a, 'tcx> {
333    fn update_bits(
334        state: &mut <Self as Analysis<'tcx>>::Domain,
335        path: MovePathIndex,
336        dfstate: DropFlagState,
337    ) {
338        match dfstate {
339            DropFlagState::Absent => state.kill(path),
340            DropFlagState::Present => state.gen_(path),
341        }
342    }
343}
344
345impl<'tcx> MaybeUninitializedPlaces<'_, 'tcx> {
346    fn update_bits(
347        state: &mut <Self as Analysis<'tcx>>::Domain,
348        path: MovePathIndex,
349        dfstate: DropFlagState,
350    ) {
351        match dfstate {
352            DropFlagState::Absent => state.gen_(path),
353            DropFlagState::Present => state.kill(path),
354        }
355    }
356}
357
358impl<'tcx> Analysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
359    /// There can be many more `MovePathIndex` than there are locals in a MIR body.
360    /// We use a mixed bitset to avoid paying too high a memory footprint.
361    type Domain = MaybeReachable<MixedBitSet<MovePathIndex>>;
362
363    type SwitchIntData = MaybePlacesSwitchIntData<'tcx>;
364
365    const NAME: &'static str = "maybe_init";
366
367    fn bottom_value(&self, _: &mir::Body<'tcx>) -> Self::Domain {
368        // bottom = uninitialized
369        MaybeReachable::Unreachable
370    }
371
372    fn initialize_start_block(&self, _: &mir::Body<'tcx>, state: &mut Self::Domain) {
373        *state =
374            MaybeReachable::Reachable(MixedBitSet::new_empty(self.move_data().move_paths.len()));
375        drop_flag_effects_for_function_entry(self.body, self.move_data, |path, s| {
376            if !(s == DropFlagState::Present) {
    ::core::panicking::panic("assertion failed: s == DropFlagState::Present")
};assert!(s == DropFlagState::Present);
377            state.gen_(path);
378        });
379    }
380
381    fn apply_primary_statement_effect(
382        &self,
383        state: &mut Self::Domain,
384        statement: &mir::Statement<'tcx>,
385        location: Location,
386    ) {
387        drop_flag_effects_for_location(self.body, self.move_data, location, |path, s| {
388            Self::update_bits(state, path, s)
389        });
390
391        // Mark all places as "maybe init" if they are mutably borrowed. See #90752.
392        if self.tcx.sess.opts.unstable_opts.precise_enum_drop_elaboration
393            && let Some((_, rvalue)) = statement.kind.as_assign()
394            && let mir::Rvalue::Ref(_, mir::BorrowKind::Mut { .. }, place)
395                // FIXME: Does `&raw const foo` allow mutation? See #90413.
396                | mir::Rvalue::RawPtr(_, place) = rvalue
397            && let LookupResult::Exact(mpi) = self.move_data().rev_lookup.find(place.as_ref())
398        {
399            on_all_children_bits(self.move_data(), mpi, |child| {
400                state.gen_(child);
401            })
402        }
403    }
404
405    fn apply_primary_terminator_effect<'mir>(
406        &self,
407        state: &mut Self::Domain,
408        terminator: &'mir mir::Terminator<'tcx>,
409        location: Location,
410    ) -> TerminatorEdges<'mir, 'tcx> {
411        // Note: `edges` must be computed first because `drop_flag_effects_for_location` can change
412        // the result of `is_unwind_dead`.
413        let mut edges = terminator.edges();
414        if self.skip_unreachable_unwind
415            && let mir::TerminatorKind::Drop { target, unwind, place, replace: _, drop: _ } =
416                terminator.kind
417            && #[allow(non_exhaustive_omitted_patterns)] match unwind {
    mir::UnwindAction::Cleanup(_) => true,
    _ => false,
}matches!(unwind, mir::UnwindAction::Cleanup(_))
418            && self.is_unwind_dead(place, state)
419        {
420            edges = TerminatorEdges::Single(target);
421        }
422        drop_flag_effects_for_location(self.body, self.move_data, location, |path, s| {
423            Self::update_bits(state, path, s)
424        });
425        edges
426    }
427
428    fn apply_call_return_effect(
429        &self,
430        state: &mut Self::Domain,
431        _block: mir::BasicBlock,
432        return_places: CallReturnPlaces<'_, 'tcx>,
433    ) {
434        return_places.for_each(|place| {
435            // when a call returns successfully, that means we need to set
436            // the bits for that dest_place to 1 (initialized).
437            on_lookup_result_bits(
438                self.move_data(),
439                self.move_data().rev_lookup.find(place.as_ref()),
440                |mpi| {
441                    state.gen_(mpi);
442                },
443            );
444        });
445    }
446
447    fn get_switch_int_data(
448        &self,
449        block: mir::BasicBlock,
450        targets: &mir::SwitchTargets,
451        discr: &mir::Operand<'tcx>,
452    ) -> Option<Self::SwitchIntData> {
453        if !self.tcx.sess.opts.unstable_opts.precise_enum_drop_elaboration {
454            return None;
455        }
456
457        MaybePlacesSwitchIntData::new(self.tcx, self.body, block, targets, discr)
458    }
459
460    fn apply_switch_int_edge_effect(
461        &self,
462        state: &mut Self::Domain,
463        data: &mut Self::SwitchIntData,
464        target_idx: SwitchTargetIndex,
465    ) {
466        let inactive_variants = match target_idx {
467            SwitchTargetIndex::Normal(target_idx) => {
468                InactiveVariants::Active(data.variants[target_idx])
469            }
470            SwitchTargetIndex::Otherwise if self.exclude_inactive_in_otherwise => {
471                InactiveVariants::Inactives(data.variants.clone())
472            }
473            _ => return,
474        };
475
476        // Kill all move paths that correspond to variants we know to be inactive along this
477        // particular outgoing edge of a `SwitchInt`.
478        drop_flag_effects::on_all_inactive_variants(
479            self.move_data,
480            data.enum_place,
481            &inactive_variants,
482            |mpi| state.kill(mpi),
483        );
484    }
485}
486
487/// There can be many more `MovePathIndex` than there are locals in a MIR body.
488/// We use a mixed bitset to avoid paying too high a memory footprint.
489pub type MaybeUninitializedPlacesDomain = MixedBitSet<MovePathIndex>;
490
491impl<'tcx> Analysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
492    type Domain = MaybeUninitializedPlacesDomain;
493
494    type SwitchIntData = MaybePlacesSwitchIntData<'tcx>;
495
496    const NAME: &'static str = "maybe_uninit";
497
498    fn bottom_value(&self, _: &mir::Body<'tcx>) -> Self::Domain {
499        // bottom = initialized (`initialize_start_block` overwrites this on first entry)
500        MixedBitSet::new_empty(self.move_data().move_paths.len())
501    }
502
503    // sets state bits for Arg places
504    fn initialize_start_block(&self, _: &mir::Body<'tcx>, state: &mut Self::Domain) {
505        // set all bits to 1 (uninit) before gathering counter-evidence
506        state.insert_all();
507
508        drop_flag_effects_for_function_entry(self.body, self.move_data, |path, s| {
509            if !(s == DropFlagState::Present) {
    ::core::panicking::panic("assertion failed: s == DropFlagState::Present")
};assert!(s == DropFlagState::Present);
510            state.remove(path);
511        });
512    }
513
514    fn apply_primary_statement_effect(
515        &self,
516        state: &mut Self::Domain,
517        _statement: &mir::Statement<'tcx>,
518        location: Location,
519    ) {
520        drop_flag_effects_for_location(self.body, self.move_data, location, |path, s| {
521            Self::update_bits(state, path, s)
522        });
523
524        // Unlike in `MaybeInitializedPlaces` above, we don't need to change the state when a
525        // mutable borrow occurs. Places cannot become uninitialized through a mutable reference.
526    }
527
528    fn apply_primary_terminator_effect<'mir>(
529        &self,
530        state: &mut Self::Domain,
531        terminator: &'mir mir::Terminator<'tcx>,
532        location: Location,
533    ) -> TerminatorEdges<'mir, 'tcx> {
534        drop_flag_effects_for_location(self.body, self.move_data, location, |path, s| {
535            Self::update_bits(state, path, s)
536        });
537        if self.skip_unreachable_unwind.contains(location.block) {
538            let mir::TerminatorKind::Drop { target, unwind, .. } = terminator.kind else { ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"))bug!() };
539            {
    match unwind {
        mir::UnwindAction::Cleanup(_) => {}
        ref left_val => {
            ::core::panicking::assert_matches_failed(left_val,
                "mir::UnwindAction::Cleanup(_)",
                ::core::option::Option::None);
        }
    }
};assert_matches!(unwind, mir::UnwindAction::Cleanup(_));
540            TerminatorEdges::Single(target)
541        } else {
542            terminator.edges()
543        }
544    }
545
546    fn apply_call_return_effect(
547        &self,
548        state: &mut Self::Domain,
549        _block: mir::BasicBlock,
550        return_places: CallReturnPlaces<'_, 'tcx>,
551    ) {
552        return_places.for_each(|place| {
553            // when a call returns successfully, that means we need to set
554            // the bits for that dest_place to 0 (initialized).
555            on_lookup_result_bits(
556                self.move_data(),
557                self.move_data().rev_lookup.find(place.as_ref()),
558                |mpi| {
559                    state.kill(mpi);
560                },
561            );
562        });
563    }
564
565    fn get_switch_int_data(
566        &self,
567        block: mir::BasicBlock,
568        targets: &mir::SwitchTargets,
569        discr: &mir::Operand<'tcx>,
570    ) -> Option<Self::SwitchIntData> {
571        if !self.tcx.sess.opts.unstable_opts.precise_enum_drop_elaboration {
572            return None;
573        }
574
575        if !self.mark_inactive_variants_as_uninit {
576            return None;
577        }
578
579        MaybePlacesSwitchIntData::new(self.tcx, self.body, block, targets, discr)
580    }
581
582    fn apply_switch_int_edge_effect(
583        &self,
584        state: &mut Self::Domain,
585        data: &mut Self::SwitchIntData,
586        target_idx: SwitchTargetIndex,
587    ) {
588        let inactive_variants = match target_idx {
589            SwitchTargetIndex::Normal(target_idx) => {
590                InactiveVariants::Active(data.variants[target_idx])
591            }
592            SwitchTargetIndex::Otherwise if self.include_inactive_in_otherwise => {
593                InactiveVariants::Inactives(data.variants.clone())
594            }
595            _ => return,
596        };
597
598        // Mark all move paths that correspond to variants other than this one as maybe
599        // uninitialized (in reality, they are *definitely* uninitialized).
600        drop_flag_effects::on_all_inactive_variants(
601            self.move_data,
602            data.enum_place,
603            &inactive_variants,
604            |mpi| state.gen_(mpi),
605        );
606    }
607}
608
609/// There can be many more `InitIndex` than there are locals in a MIR body.
610/// We use a mixed bitset to avoid paying too high a memory footprint.
611pub type EverInitializedPlacesDomain = MixedBitSet<InitIndex>;
612
613impl<'tcx> Analysis<'tcx> for EverInitializedPlaces<'_, 'tcx> {
614    type Domain = EverInitializedPlacesDomain;
615
616    const NAME: &'static str = "ever_init";
617
618    fn bottom_value(&self, _: &mir::Body<'tcx>) -> Self::Domain {
619        // bottom = no initialized variables by default
620        MixedBitSet::new_empty(self.move_data().inits.len())
621    }
622
623    fn initialize_start_block(&self, body: &mir::Body<'tcx>, state: &mut Self::Domain) {
624        for arg_init in 0..body.arg_count {
625            state.insert(InitIndex::new(arg_init));
626        }
627    }
628
629    #[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("apply_primary_statement_effect",
                                    "rustc_mir_dataflow::impls::initialized",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_dataflow/src/impls/initialized.rs"),
                                    ::tracing_core::__macro_support::Option::Some(629u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::impls::initialized"),
                                    ::tracing_core::field::FieldSet::new(&["stmt", "location"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&stmt)
                                                            as &dyn Value)),
                                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&location)
                                                            as &dyn Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let move_data = self.move_data();
            let init_path_map = &move_data.init_path_map;
            let init_loc_map = &move_data.init_loc_map;
            let rev_lookup = &move_data.rev_lookup;
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event compiler/rustc_mir_dataflow/src/impls/initialized.rs:641",
                                    "rustc_mir_dataflow::impls::initialized",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_dataflow/src/impls/initialized.rs"),
                                    ::tracing_core::__macro_support::Option::Some(641u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::impls::initialized"),
                                    ::tracing_core::field::FieldSet::new(&["message"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            let mut iter = __CALLSITE.metadata().fields().iter();
                            __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                ::tracing::__macro_support::Option::Some(&format_args!("initializes move_indexes {0:?}",
                                                                init_loc_map[location]) as &dyn Value))])
                        });
                } else { ; }
            };
            state.gen_all(init_loc_map[location].iter().copied());
            if let mir::StatementKind::StorageDead(local) = stmt.kind &&
                    let Some(move_path_index) = rev_lookup.find_local(local) {
                {
                    use ::tracing::__macro_support::Callsite as _;
                    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                        {
                            static META: ::tracing::Metadata<'static> =
                                {
                                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_mir_dataflow/src/impls/initialized.rs:649",
                                        "rustc_mir_dataflow::impls::initialized",
                                        ::tracing::Level::DEBUG,
                                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_dataflow/src/impls/initialized.rs"),
                                        ::tracing_core::__macro_support::Option::Some(649u32),
                                        ::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::impls::initialized"),
                                        ::tracing_core::field::FieldSet::new(&["message"],
                                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                        ::tracing::metadata::Kind::EVENT)
                                };
                            ::tracing::callsite::DefaultCallsite::new(&META)
                        };
                    let enabled =
                        ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            {
                                let interest = __CALLSITE.interest();
                                !interest.is_never() &&
                                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                        interest)
                            };
                    if enabled {
                        (|value_set: ::tracing::field::ValueSet|
                                    {
                                        let meta = __CALLSITE.metadata();
                                        ::tracing::Event::dispatch(meta, &value_set);
                                        ;
                                    })({
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = __CALLSITE.metadata().fields().iter();
                                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&format_args!("clears the ever initialized status of {0:?}",
                                                                    init_path_map[move_path_index]) as &dyn Value))])
                            });
                    } else { ; }
                };
                state.kill_all(init_path_map[move_path_index].iter().copied());
            }
        }
    }
}#[instrument(skip(self, state), level = "debug")]
630    fn apply_primary_statement_effect(
631        &self,
632        state: &mut Self::Domain,
633        stmt: &mir::Statement<'tcx>,
634        location: Location,
635    ) {
636        let move_data = self.move_data();
637        let init_path_map = &move_data.init_path_map;
638        let init_loc_map = &move_data.init_loc_map;
639        let rev_lookup = &move_data.rev_lookup;
640
641        debug!("initializes move_indexes {:?}", init_loc_map[location]);
642        state.gen_all(init_loc_map[location].iter().copied());
643
644        if let mir::StatementKind::StorageDead(local) = stmt.kind
645            // End inits for StorageDead, so that an immutable variable can
646            // be reinitialized on the next iteration of the loop.
647            && let Some(move_path_index) = rev_lookup.find_local(local)
648        {
649            debug!("clears the ever initialized status of {:?}", init_path_map[move_path_index]);
650            state.kill_all(init_path_map[move_path_index].iter().copied());
651        }
652    }
653
654    #[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("apply_primary_terminator_effect",
                                    "rustc_mir_dataflow::impls::initialized",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_dataflow/src/impls/initialized.rs"),
                                    ::tracing_core::__macro_support::Option::Some(654u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::impls::initialized"),
                                    ::tracing_core::field::FieldSet::new(&["location"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&location)
                                                            as &dyn Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: TerminatorEdges<'mir, 'tcx> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            let (body, move_data) = (self.body, self.move_data());
            let term = body[location.block].terminator();
            let init_loc_map = &move_data.init_loc_map;
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event compiler/rustc_mir_dataflow/src/impls/initialized.rs:664",
                                    "rustc_mir_dataflow::impls::initialized",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_dataflow/src/impls/initialized.rs"),
                                    ::tracing_core::__macro_support::Option::Some(664u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::impls::initialized"),
                                    ::tracing_core::field::FieldSet::new(&["term"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            let mut iter = __CALLSITE.metadata().fields().iter();
                            __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                ::tracing::__macro_support::Option::Some(&debug(&term) as
                                                        &dyn Value))])
                        });
                } else { ; }
            };
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event compiler/rustc_mir_dataflow/src/impls/initialized.rs:665",
                                    "rustc_mir_dataflow::impls::initialized",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_dataflow/src/impls/initialized.rs"),
                                    ::tracing_core::__macro_support::Option::Some(665u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::impls::initialized"),
                                    ::tracing_core::field::FieldSet::new(&["message"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            let mut iter = __CALLSITE.metadata().fields().iter();
                            __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                ::tracing::__macro_support::Option::Some(&format_args!("initializes move_indexes {0:?}",
                                                                init_loc_map[location]) as &dyn Value))])
                        });
                } else { ; }
            };
            state.gen_all(init_loc_map[location].iter().filter(|init_index|
                            {
                                move_data.inits[**init_index].kind !=
                                    InitKind::NonPanicPathOnly
                            }).copied());
            terminator.edges()
        }
    }
}#[instrument(skip(self, state, terminator), level = "debug")]
655    fn apply_primary_terminator_effect<'mir>(
656        &self,
657        state: &mut Self::Domain,
658        terminator: &'mir mir::Terminator<'tcx>,
659        location: Location,
660    ) -> TerminatorEdges<'mir, 'tcx> {
661        let (body, move_data) = (self.body, self.move_data());
662        let term = body[location.block].terminator();
663        let init_loc_map = &move_data.init_loc_map;
664        debug!(?term);
665        debug!("initializes move_indexes {:?}", init_loc_map[location]);
666        state.gen_all(
667            init_loc_map[location]
668                .iter()
669                .filter(|init_index| {
670                    move_data.inits[**init_index].kind != InitKind::NonPanicPathOnly
671                })
672                .copied(),
673        );
674        terminator.edges()
675    }
676
677    fn apply_call_return_effect(
678        &self,
679        state: &mut Self::Domain,
680        block: mir::BasicBlock,
681        _return_places: CallReturnPlaces<'_, 'tcx>,
682    ) {
683        let move_data = self.move_data();
684        let init_loc_map = &move_data.init_loc_map;
685
686        let call_loc = self.body.terminator_loc(block);
687        for init_index in &init_loc_map[call_loc] {
688            state.gen_(*init_index);
689        }
690    }
691}