]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/basic_assignment.rs
Auto merge of #54240 - csmoe:nonzero_from, r=alexcrichton
[rust.git] / src / test / mir-opt / basic_assignment.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 // this tests move up progration, which is not yet implemented
12 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
13 // file at the top-level directory of this distribution and at
14 // http://rust-lang.org/COPYRIGHT.
15 //
16 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
17 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
18 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
19 // option. This file may not be copied, modified, or distributed
20 // except according to those terms.
21
22 // Check codegen for assignments (`a = b`) where the left-hand-side is
23 // not yet initialized. Assignments tend to be absent in simple code,
24 // so subtle breakage in them can leave a quite hard-to-find trail of
25 // destruction.
26
27 // ignore-tidy-linelength
28
29 fn main() {
30     let nodrop_x = false;
31     let nodrop_y;
32
33     // Since boolean does not require drop, this can be a simple
34     // assignment:
35     nodrop_y = nodrop_x;
36
37     let drop_x : Option<Box<u32>> = None;
38     let drop_y;
39
40     // Since the type of `drop_y` has drop, we generate a `replace`
41     // terminator:
42     drop_y = drop_x;
43 }
44
45 // END RUST SOURCE
46 // START rustc.main.SimplifyCfg-initial.after.mir
47 //    bb0: {
48 //        StorageLive(_1);
49 //        _1 = const false;
50 //        FakeRead(ForLet, _1);
51 //        StorageLive(_2);
52 //        StorageLive(_3);
53 //        _3 = _1;
54 //        _2 = move _3;
55 //        StorageDead(_3);
56 //        StorageLive(_4);
57 //        _4 = std::option::Option<std::boxed::Box<u32>>::None;
58 //        AscribeUserType(_4, o, Canonical { variables: [], value: std::option::Option<std::boxed::Box<u32>> });
59 //        FakeRead(ForLet, _4);
60 //        StorageLive(_5);
61 //        StorageLive(_6);
62 //        _6 = move _4;
63 //        replace(_5 <- move _6) -> [return: bb2, unwind: bb5];
64 //    }
65 //    ...
66 //    bb2: {
67 //        drop(_6) -> [return: bb6, unwind: bb4];
68 //    }
69 //    ...
70 //    bb5: {
71 //        drop(_6) -> bb4;
72 //    }
73 // END rustc.main.SimplifyCfg-initial.after.mir