Closed
Description
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
}