]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/borrowck-uninit-ref-chain.rs
Auto merge of #54720 - davidtwco:issue-51191, r=nikomatsakis
[rust.git] / src / test / ui / borrowck / borrowck-uninit-ref-chain.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // revisions: ast mir
12 //[mir]compile-flags: -Z borrowck=mir
13
14 struct S<X, Y> {
15     x: X,
16     y: Y,
17 }
18
19 fn main() {
20     let x: &&Box<i32>;
21     let _y = &**x; //[ast]~ ERROR use of possibly uninitialized variable: `**x` [E0381]
22                    //[mir]~^ [E0381]
23
24     let x: &&S<i32, i32>;
25     let _y = &**x; //[ast]~ ERROR use of possibly uninitialized variable: `**x` [E0381]
26                    //[mir]~^ [E0381]
27
28     let x: &&i32;
29     let _y = &**x; //[ast]~ ERROR use of possibly uninitialized variable: `**x` [E0381]
30                    //[mir]~^ [E0381]
31
32
33     let mut a: S<i32, i32>;
34     a.x = 0;
35     let _b = &a.x; //[ast]~ ERROR use of possibly uninitialized variable: `a.x` [E0381]
36                    // (deliberately *not* an error under MIR-borrowck)
37
38     let mut a: S<&&i32, &&i32>;
39     a.x = &&0;
40     let _b = &**a.x; //[ast]~ ERROR use of possibly uninitialized variable: `**a.x` [E0381]
41                      // (deliberately *not* an error under MIR-borrowck)
42
43
44     let mut a: S<i32, i32>;
45     a.x = 0;
46     let _b = &a.y; //[ast]~ ERROR use of possibly uninitialized variable: `a.y` [E0381]
47                    //[mir]~^ ERROR [E0381]
48
49     let mut a: S<&&i32, &&i32>;
50     a.x = &&0;
51     let _b = &**a.y; //[ast]~ ERROR use of possibly uninitialized variable: `**a.y` [E0381]
52                      //[mir]~^ ERROR [E0381]
53 }