Skip to content

Incorrect MIR built for loops inside expressions. #30876

@solson

Description

@solson
Test case
#![feature(rustc_attrs)]

#[rustc_mir(pretty = "foo.mir")]
fn foo() -> [String; 2] {
    [String::from("test"), loop {}]
}

fn main() {
    println!("{:?}", foo());
}
Generated MIR for foo
fn() -> [collections::string::String; 2] {
    let mut tmp0: collections::string::String;
    let mut tmp1: collections::string::String;

    bb0: {
        tmp0 = core::convert::From::from(const "test") -> [return: bb3, unwind: bb2];
    }

    bb1: {
        return;
    }

    bb2: {
        drop tmp0;
        resume;
    }

    bb3: {
        tmp1 = ();
        goto -> bb3;
    }
}

Notice how the function foo assigns an rvalue () to tmp1 which has type collections::string::String. This seems to not affect the built executable since tmp1 = () is a no-op, but MIR should probably be type-correct at this stage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions