1 // Reject mixing cyclic structure and Drop when using Vec.
3 // (Compare against ui/span/dropck_arr_cycle_checked.rs)
9 use std::sync::atomic::{AtomicUsize, Ordering};
11 static S_COUNT: AtomicUsize = AtomicUsize::new(0);
13 pub fn next_count() -> usize {
14 S_COUNT.fetch_add(1, Ordering::SeqCst) + 1
28 let c = s::next_count();
29 println!("building Id {}", c);
30 Id { orig_count: c, count: c }
32 pub fn count(&self) -> usize {
33 println!("Id::count on {} returns {}", self.orig_count, self.count);
40 println!("dropping Id {}", self.count);
47 fn count(&self) -> usize;
51 struct CheckId<T:HasId> {
55 #[allow(non_snake_case)]
56 fn CheckId<T:HasId>(t: T) -> CheckId<T> { CheckId{ v: t } }
58 impl<T:HasId> Drop for CheckId<T> {
60 assert!(self.v.count() > 0);
67 v: Vec<CheckId<Cell<Option<&'a C<'a>>>>>,
70 impl<'a> HasId for Cell<Option<&'a C<'a>>> {
71 fn count(&self) -> usize {
74 Some(c) => c.id.count(),
81 C { id: Id::new(), v: Vec::new() }
86 let (mut c1, mut c2, mut c3);
91 c1.v.push(CheckId(Cell::new(None)));
92 c1.v.push(CheckId(Cell::new(None)));
93 c2.v.push(CheckId(Cell::new(None)));
94 c2.v.push(CheckId(Cell::new(None)));
95 c3.v.push(CheckId(Cell::new(None)));
96 c3.v.push(CheckId(Cell::new(None)));
98 c1.v[0].v.set(Some(&c2));
99 //~^ ERROR `c2` does not live long enough
100 c1.v[1].v.set(Some(&c3));
101 //~^ ERROR `c3` does not live long enough
102 c2.v[0].v.set(Some(&c2));
103 c2.v[1].v.set(Some(&c3));
104 c3.v[0].v.set(Some(&c1));
105 //~^ ERROR `c1` does not live long enough
106 c3.v[1].v.set(Some(&c2));