Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIR borrowck: spurious storagedead in constants #46522

Closed
arielb1 opened this issue Dec 5, 2017 · 1 comment
Closed

MIR borrowck: spurious storagedead in constants #46522

arielb1 opened this issue Dec 5, 2017 · 1 comment
Labels
T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Milestone

Comments

@arielb1
Copy link
Contributor

arielb1 commented Dec 5, 2017

For the issue-44373 run-pass test:

// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

struct Foo(bool);

struct Container(&'static [&'static Foo]);

static FOO: Foo = Foo(true);
static CONTAINER: Container = Container(&[&FOO]);

fn main() {}

The generated MIR for CONTAINER contains a StorageDead that should make the code illegal (and with MIR borrowck, makes it illegal):

static CONTAINER: Container = {
    let mut _0: Container;               // return place
    let mut _1: &[&Foo];
    let mut _2: &[&Foo; 1];
    let mut _3: &[&Foo; 1];
    let mut _4: [&Foo; 1];
    let mut _5: &Foo;
    let mut _6: &Foo;

    bb0: {                              
        StorageLive(_1);                 // bb0[0]: scope 0 at src/main.rs:16:41: 16:48
        StorageLive(_2);                 // bb0[1]: scope 0 at src/main.rs:16:41: 16:48
        StorageLive(_3);                 // bb0[2]: scope 0 at src/main.rs:16:41: 16:48
        StorageLive(_4);                 // bb0[3]: scope 0 at src/main.rs:16:42: 16:48
        StorageLive(_5);                 // bb0[4]: scope 0 at src/main.rs:16:43: 16:47
        StorageLive(_6);                 // bb0[5]: scope 0 at src/main.rs:16:43: 16:47
        _6 = &(FOO: Foo);                // bb0[6]: scope 0 at src/main.rs:16:43: 16:47
        _5 = _6;                         // bb0[7]: scope 0 at src/main.rs:16:43: 16:47
        _4 = [move _5];                  // bb0[8]: scope 0 at src/main.rs:16:42: 16:48
        _3 = &_4; // <- _4 is borrowed here and escapes:
        _2 = _3;                         // bb0[10]: scope 0 at src/main.rs:16:41: 16:48
        _1 = move _2 as &[&Foo] (Unsize); // bb0[11]: scope 0 at src/main.rs:16:41: 16:48
        _0 = Container::{{constructor}}(move _1,); // bb0[12]: scope 0 at src/main.rs:16:31: 16:49
        StorageDead(_3);                 // bb0[13]: scope 0 at src/main.rs:16:49: 16:49
        StorageDead(_4); // <- BUT, _4 is killed here
        StorageDead(_6);                 // bb0[15]: scope 0 at src/main.rs:16:49: 16:49
        return;                          // bb0[16]: scope 0 at src/main.rs:16:1: 16:50
    }
@arielb1 arielb1 added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-compiler-nll labels Dec 5, 2017
@arielb1 arielb1 added this to the NLL prototype milestone Dec 5, 2017
@arielb1
Copy link
Contributor Author

arielb1 commented Dec 5, 2017

cc @eddyb

bors added a commit that referenced this issue Dec 6, 2017
rustc_mir: promote references of statics from other statics.

Fixes #46522 by also allowing `STATIC_REF` in MIR const-qualification, not just AST rvalue promotion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

1 participant