]> git.proxmox.com Git - rustc.git/blob - tests/ui/generator/dropck.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / 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 }