Skip to content

[MIR] bounds-checked indexing creates broken MIR #31482

Closed
@arielb1

Description

@arielb1

The first fruit of my MIR type-checking work:

pub fn cbk(x: usize) -> usize {
    [0][x]
}

Generated MIR:

fn(arg0: usize) -> usize {
    let var0: usize; // x
    let mut tmp0: usize;
    let mut tmp1: [usize; 1];
    let mut tmp2: ();
    let mut tmp3: usize;
    let mut tmp4: usize;
    let mut tmp5: bool;
    let mut tmp6: (&'static str, u32);
    let mut tmp7: &(&'static str, u32);

    bb0: {
        var0 = arg0;
        tmp1 = [const 0];
        tmp3 = var0;
        tmp4 = Len(tmp1);
        tmp5 = Lt(tmp3, tmp4);
        if(tmp5) -> [true: bb2, false: bb3];
    }

    bb1: {
        return;
    }

    bb2: {
        tmp0 = tmp1[tmp3];
        return = tmp0;
        goto -> bb1;
    }

    bb3: {
        tmp6 = (const "panic.rs", const 7);
        tmp7 = &mut tmp6; //~ ERROR &mut and late-bound region!
        core::panicking::panic_bounds_check(tmp7, tmp3, tmp4);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions