]> git.lizzy.rs Git - rust.git/blob - src/test/ui/generator/dropck.rs
Auto merge of #102655 - joboet:windows_tls_opt, r=ChrisDenton
[rust.git] / src / test / ui / generator / dropck.rs
1 #![feature(generators, generator_trait)]
2
3 use std::cell::RefCell;
4 use std::ops::Generator;
5 use std::pin::Pin;
6
7 fn main() {
8     let (mut gen, cell);
9     cell = Box::new(RefCell::new(0));
10     let ref_ = Box::leak(Box::new(Some(cell.borrow_mut())));
11     //~^ ERROR `*cell` does not live long enough [E0597]
12     // the upvar is the non-dropck `&mut Option<Ref<'a, i32>>`.
13     gen = || {
14         // but the generator can use it to drop a `Ref<'a, i32>`.
15         let _d = ref_.take(); //~ ERROR `ref_` does not live long enough
16         yield;
17     };
18     Pin::new(&mut gen).resume(());
19     // drops the RefCell and then the Ref, leading to use-after-free
20 }