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.
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.
11 // compile-flags: -Z identify_regions -Z span_free_formats -Z emit-end-regions
12 // ignore-tidy-linelength
14 // This test models a scenario with a cyclic reference. Rust obviously
15 // needs to handle such cases.
17 // The interesting part about this test is that such case shows that
18 // one cannot generally force all references to be dead before you hit
19 // their EndRegion; at least, not without breaking the more important
20 // property that all borrowed storage locations have their regions
21 // ended strictly before their StorageDeads. (This test was inspired
22 // by discussion on Issue #43481.)
27 r: Cell<Option<&'a S<'a>>>,
32 let x = S { r: Cell::new(None) };
39 fn query() -> bool { true }
42 // START rustc.main.SimplifyCfg-qualify-consts.after.mir
46 // let _2: S<'35_0rs>;
50 // let mut _3: std::cell::Cell<std::option::Option<&'35_0rs S<'35_0rs>>>;
51 // let mut _4: std::option::Option<&'35_0rs S<'35_0rs>>;
53 // let mut _6: &'16s std::cell::Cell<std::option::Option<&'35_0rs S<'35_0rs>>>;
54 // let mut _7: std::option::Option<&'35_0rs S<'35_0rs>>;
55 // let mut _8: &'35_0rs S<'35_0rs>;
56 // let mut _9: &'35_0rs S<'35_0rs>;
61 // let mut _14: &'33s std::cell::Cell<std::option::Option<&'35_0rs S<'35_0rs>>>;
62 // let mut _15: std::option::Option<&'35_0rs S<'35_0rs>>;
63 // let mut _16: &'35_0rs S<'35_0rs>;
64 // let mut _17: &'35_0rs S<'35_0rs>;
73 // _4 = std::option::Option<&'35_0rs S<'35_0rs>>::None;
74 // _3 = const <std::cell::Cell<T>>::new(move _4) -> [return: bb3, unwind: bb2];
81 // _2 = S<'35_0rs> { r: move _3 };
84 // _6 = &'16s (_2.0: std::cell::Cell<std::option::Option<&'35_0rs S<'35_0rs>>>);
89 // _8 = &'35_0rs (*_9);
90 // _7 = std::option::Option<&'35_0rs S<'35_0rs>>::Some(move _8,);
92 // _5 = const <std::cell::Cell<T>>::set(move _6, move _7) -> [return: bb4, unwind: bb2];
100 // _11 = const query() -> [return: bb5, unwind: bb2];
103 // switchInt(move _11) -> [0u8: bb7, otherwise: bb6];
108 // EndRegion('35_0rs);
116 // _14 = &'33s (_2.0: std::cell::Cell<std::option::Option<&'35_0rs S<'35_0rs>>>);
120 // _17 = &'35_0rs _2;
121 // _16 = &'35_0rs (*_17);
122 // _15 = std::option::Option<&'35_0rs S<'35_0rs>>::Some(move _16,);
124 // _13 = const <std::cell::Cell<T>>::set(move _14, move _15) -> [return: bb8, unwind: bb2];
132 // EndRegion('35_0rs);
137 // END rustc.main.SimplifyCfg-qualify-consts.after.mir