1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Reject mixing cyclic structure and Drop when using fixed length
14 // (Compare against compile-fail/dropck_vec_cycle_checked.rs)
16 #![feature(const_atomic_usize_new)]
22 use std::sync::atomic::{AtomicUsize, Ordering};
24 static S_COUNT: AtomicUsize = AtomicUsize::new(0);
26 pub fn next_count() -> usize {
27 S_COUNT.fetch_add(1, Ordering::SeqCst) + 1
41 let c = s::next_count();
42 println!("building Id {}", c);
43 Id { orig_count: c, count: c }
45 pub fn count(&self) -> usize {
46 println!("Id::count on {} returns {}", self.orig_count, self.count);
53 println!("dropping Id {}", self.count);
60 fn count(&self) -> usize;
64 struct CheckId<T:HasId> {
68 #[allow(non_snake_case)]
69 fn CheckId<T:HasId>(t: T) -> CheckId<T> { CheckId{ v: t } }
71 impl<T:HasId> Drop for CheckId<T> {
73 assert!(self.v.count() > 0);
80 a: [CheckId<Cell<Option<&'a B<'a>>>>; 2]
83 impl<'a> HasId for Cell<Option<&'a B<'a>>> {
84 fn count(&self) -> usize {
87 Some(b) => b.id.count(),
94 B { id: Id::new(), a: [CheckId(Cell::new(None)), CheckId(Cell::new(None))] }
103 b1.a[0].v.set(Some(&b2));
104 b1.a[1].v.set(Some(&b3));
105 b2.a[0].v.set(Some(&b2));
106 b2.a[1].v.set(Some(&b3));
107 b3.a[0].v.set(Some(&b1));
108 b3.a[1].v.set(Some(&b2));
110 //~^ ERROR `b2` does not live long enough
111 //~| ERROR `b3` does not live long enough
112 //~| ERROR `b2` does not live long enough
113 //~| ERROR `b3` does not live long enough
114 //~| ERROR `b1` does not live long enough
115 //~| ERROR `b2` does not live long enough