1 // Reject mixing cyclic structure and Drop when using TypedArena.
3 // (Compare against dropck-vec-cycle-checked.rs)
5 // (Also compare against ui-fulldeps/dropck-tarena-unsound-drop.rs,
6 // which is a reduction of this code to more directly show the reason
7 // for the error message we see here.)
9 #![feature(rustc_private)]
11 extern crate rustc_arena;
13 use rustc_arena::TypedArena;
18 use std::sync::atomic::{AtomicUsize, Ordering};
20 static S_COUNT: AtomicUsize = AtomicUsize::new(0);
22 pub fn next_count() -> usize {
23 S_COUNT.fetch_add(1, Ordering::SeqCst) + 1
37 let c = s::next_count();
38 println!("building Id {}", c);
39 Id { orig_count: c, count: c }
41 pub fn count(&self) -> usize {
42 println!("Id::count on {} returns {}", self.orig_count, self.count);
49 println!("dropping Id {}", self.count);
56 fn count(&self) -> usize;
60 struct CheckId<T:HasId> {
64 #[allow(non_snake_case)]
65 fn CheckId<T:HasId>(t: T) -> CheckId<T> { CheckId{ v: t } }
67 impl<T:HasId> Drop for CheckId<T> {
69 assert!(self.v.count() > 0);
76 v: Vec<CheckId<Cell<Option<&'a C<'a>>>>>,
79 impl<'a> HasId for Cell<Option<&'a C<'a>>> {
80 fn count(&self) -> usize {
83 Some(c) => c.id.count(),
90 C { id: Id::new(), v: Vec::new() }
94 fn f<'a>(arena: &'a TypedArena<C<'a>>) {
95 let c1 = arena.alloc(C::new());
96 let c2 = arena.alloc(C::new());
97 let c3 = arena.alloc(C::new());
99 c1.v.push(CheckId(Cell::new(None)));
100 c1.v.push(CheckId(Cell::new(None)));
101 c2.v.push(CheckId(Cell::new(None)));
102 c2.v.push(CheckId(Cell::new(None)));
103 c3.v.push(CheckId(Cell::new(None)));
104 c3.v.push(CheckId(Cell::new(None)));
106 c1.v[0].v.set(Some(c2));
107 c1.v[1].v.set(Some(c3));
108 c2.v[0].v.set(Some(c2));
109 c2.v[1].v.set(Some(c3));
110 c3.v[0].v.set(Some(c1));
111 c3.v[1].v.set(Some(c2));
115 let arena = TypedArena::default();
117 } //~^ ERROR `arena` does not live long enough