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
48 // let _2: S<'36_0rs>;
51 // let mut _3: std::cell::Cell<std::option::Option<&'36_0rs S<'36_0rs>>>;
52 // let mut _4: std::option::Option<&'36_0rs S<'36_0rs>>;
54 // let mut _6: &'17s std::cell::Cell<std::option::Option<&'36_0rs S<'36_0rs>>>;
55 // let mut _7: std::option::Option<&'36_0rs S<'36_0rs>>;
56 // let mut _8: &'36_0rs S<'36_0rs>;
57 // let mut _9: &'36_0rs S<'36_0rs>;
62 // let mut _14: &'34s std::cell::Cell<std::option::Option<&'36_0rs S<'36_0rs>>>;
63 // let mut _15: std::option::Option<&'36_0rs S<'36_0rs>>;
64 // let mut _16: &'36_0rs S<'36_0rs>;
65 // let mut _17: &'36_0rs S<'36_0rs>;
70 // falseUnwind -> [real: bb2, cleanup: bb3];
76 // _4 = std::option::Option<&'36_0rs S<'36_0rs>>::None;
77 // _3 = const <std::cell::Cell<T>>::new(move _4) -> [return: bb4, unwind: bb3];
84 // _2 = S<'36_0rs> { r: move _3 };
87 // _6 = &'17s (_2.0: std::cell::Cell<std::option::Option<&'36_0rs S<'36_0rs>>>);
92 // _8 = &'36_0rs (*_9);
93 // _7 = std::option::Option<&'36_0rs S<'36_0rs>>::Some(move _8,);
95 // _5 = const <std::cell::Cell<T>>::set(move _6, move _7) -> [return: bb5, unwind: bb3];
103 // _11 = const query() -> [return: bb6, unwind: bb3];
106 // switchInt(move _11) -> [false: bb8, otherwise: bb7];
111 // EndRegion('36_0rs);
119 // _14 = &'34s (_2.0: std::cell::Cell<std::option::Option<&'36_0rs S<'36_0rs>>>);
123 // _17 = &'36_0rs _2;
124 // _16 = &'36_0rs (*_17);
125 // _15 = std::option::Option<&'36_0rs S<'36_0rs>>::Some(move _16,);
127 // _13 = const <std::cell::Cell<T>>::set(move _14, move _15) -> [return: bb9, unwind: bb3];
135 // EndRegion('36_0rs);
140 // END rustc.main.SimplifyCfg-qualify-consts.after.mir