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


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

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).


The relevant code is here:

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.