1 // Reject mixing cyclic structure and Drop when using fixed length
4 // (Compare against ui/span/dropck_vec_cycle_checked.rs)
12 use std::sync::atomic::{AtomicUsize, Ordering};
14 static S_COUNT: AtomicUsize = AtomicUsize::new(0);
16 pub fn next_count() -> usize {
17 S_COUNT.fetch_add(1, Ordering::SeqCst) + 1
31 let c = s::next_count();
32 println!("building Id {}", c);
33 Id { orig_count: c, count: c }
35 pub fn count(&self) -> usize {
36 println!("Id::count on {} returns {}", self.orig_count, self.count);
43 println!("dropping Id {}", self.count);
50 fn count(&self) -> usize;
54 struct CheckId<T:HasId> {
58 #[allow(non_snake_case)]
59 fn CheckId<T:HasId>(t: T) -> CheckId<T> { CheckId{ v: t } }
61 impl<T:HasId> Drop for CheckId<T> {
63 assert!(self.v.count() > 0);
70 a: [CheckId<Cell<Option<&'a B<'a>>>>; 2]
73 impl<'a> HasId for Cell<Option<&'a B<'a>>> {
74 fn count(&self) -> usize {
77 Some(b) => b.id.count(),
84 B { id: Id::new(), a: [CheckId(Cell::new(None)), CheckId(Cell::new(None))] }
93 b1.a[0].v.set(Some(&b2));
94 //~^ ERROR `b2` does not live long enough
95 b1.a[1].v.set(Some(&b3));
96 //~^ ERROR `b3` does not live long enough
97 b2.a[0].v.set(Some(&b2));
98 b2.a[1].v.set(Some(&b3));
99 b3.a[0].v.set(Some(&b1));
100 //~^ ERROR `b1` does not live long enough
101 b3.a[1].v.set(Some(&b2));