# Why is \_2 definitely initialized after switchInt(move \_2)?

**URL:** <https://internals.rust-lang.org/t/why-is-2-definitely-initialized-after-switchint-move-2/6760>\
**Category:** compiler\
**Created:** [February 15, 2018, 1:33pm UTC](https://internals.rust-lang.org/t/why-is-2-definitely-initialized-after-switchint-move-2/6760 "2018-02-15T13:33:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fpoli](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/fpoli/32/3784_2.png) [@fpoli](https://internals.rust-lang.org/u/fpoli)\
**Post date:** [February 15, 2018, 1:33pm UTC](https://internals.rust-lang.org/t/why-is-2-definitely-initialized-after-switchint-move-2/6760/1 "2018-02-15T13:33:11Z")

</div>

Hi! I’m playing with the dataflow analysis of `librustc_mir` by running it on the following example:

```rust
fn main() {
    let cond: bool = true;

    if cond { // switchInt(move _2)
        // here _2 is still definitely initialised.
    } else {
        // here _2 is still definitely initialised.
    }
    // StorageDead(_2)
}

```

The generated MIR contains a terminator `switchInt(move _2)`. I expected `_2` to be tracked as “definitely uninitialized” after that move. However, the effect of this terminator does not add `_2` (of type bool) to the “maybe uninitialized” gen set (nor to the “maybe initialized” kill set). In other words, it seems to me that `_2` remains “definitely initialized” after the branch.

Is this intended? Is the `switchInt(move _2)` really a move of `_2`?

(I use a compiler driver plugin to obtain the MIR with `optimized_mir(..)`, then I call `mir_borrowck(..)` on it and I inspect the `state: Flows` variable in `do_mir_borrowck(..)` to check the result of the dataflow analysis).

---

<div class="post-metadata">

**Author:** ![arielb1](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/arielb1/32/3044_2.png) [@arielb1](https://internals.rust-lang.org/u/arielb1)\
**Post date:** [February 15, 2018, 1:49pm UTC](https://internals.rust-lang.org/t/why-is-2-definitely-initialized-after-switchint-move-2/6760/2 "2018-02-15T13:49:06Z")

</div>

The relevant code is here:

> <https://github.com/rust-lang/rust/blob/c83fa5d91c3b16459ab7b87c48ed18bd059a23af/src/librustc_mir/dataflow/move_paths/builder.rs#L358>

This looks like just a bug - the code hasn’t been updated from when `move` did not exist. Feel free to open a PR that does a `gather_operand` there like `TerminatorKind::Yield`.

---

<div class="post-metadata">

**Author:** ![fpoli](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/fpoli/32/3784_2.png) [@fpoli](https://internals.rust-lang.org/u/fpoli)\
**Post date:** [February 15, 2018, 2:24pm UTC](https://internals.rust-lang.org/t/why-is-2-definitely-initialized-after-switchint-move-2/6760/3 "2018-02-15T14:24:22Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 25, 2019, 8:29am UTC](https://internals.rust-lang.org/t/why-is-2-definitely-initialized-after-switchint-move-2/6760/4 "2019-03-25T08:29:39Z")

</div>

Closed on March 25, 2019, 8:29am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
