- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.I-compiletimeIssue: Problems and improvements with respect to compile times.Issue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
The const prop pass handles propagation into temporaries correctly but doesn't propagate temporaries into user defined variables.
fn main() {
  let x = 2 + 2;
}currently compiles to the following MIR:
fn  main() -> () {
    let mut _0: ();
    let _1: i32;
    let mut _2: (i32, bool);
    scope 1 {
    }
    bb0: {
        StorageLive(_1);
        (_2.0: i32) = const 4i32;
        (_2.1: bool) = const false;
        _1 = move (_2.0: i32);
        StorageDead(_1);
        return;
    }
}
but should ideally compile to:
fn  main() -> () {
    let mut _0: ();
    let _1: i32;
    scope 1 {
    }
    bb0: {
        StorageLive(_1);
        _1 = const 4i32;
        StorageDead(_1);
        return;
    }
}
Metadata
Metadata
Assignees
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.I-compiletimeIssue: Problems and improvements with respect to compile times.Issue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.