]> git.lizzy.rs Git - rust.git/blob - tests/ui/nll/issue-31567.rs
Rollup merge of #106397 - compiler-errors:new-solver-impl-wc, r=lcnr
[rust.git] / tests / ui / nll / issue-31567.rs
1 // Regression test for #31567: cached results of projections were
2 // causing region relations not to be enforced at all the places where
3 // they have to be enforced.
4
5 struct VecWrapper<'a>(&'a mut S);
6
7 struct S(Box<u32>);
8
9 fn get_dangling<'a>(v: VecWrapper<'a>) -> &'a u32 {
10     let s_inner: &'a S = &*v.0; //~ ERROR borrow may still be in use when destructor runs [E0713]
11     &s_inner.0
12 }
13
14 impl<'a> Drop for VecWrapper<'a> {
15     fn drop(&mut self) {
16         *self.0 = S(Box::new(0));
17     }
18 }
19
20 fn main() {
21     let mut s = S(Box::new(11));
22     let vw = VecWrapper(&mut s);
23     let dangling = get_dangling(vw);
24     println!("{}", dangling);
25 }