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(unsafe_destructor)]
23 use std
::sync
::atomic
::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}
;
25 static S_COUNT
: AtomicUsize
= ATOMIC_USIZE_INIT
;
27 pub fn next_count() -> usize {
28 S_COUNT
.fetch_add(1, Ordering
::SeqCst
) + 1
42 let c
= s
::next_count();
43 println
!("building Id {}", c
);
44 Id { orig_count: c, count: c }
46 pub fn count(&self) -> usize {
47 println
!("Id::count on {} returns {}", self.orig_count
, self.count
);
54 println
!("dropping Id {}", self.count
);
61 fn count(&self) -> usize;
65 struct CheckId
<T
:HasId
> {
69 #[allow(non_snake_case)]
70 fn CheckId
<T
:HasId
>(t
: T
) -> CheckId
<T
> { CheckId{ v: t }
}
73 impl<T
:HasId
> Drop
for CheckId
<T
> {
75 assert
!(self.v
.count() > 0);
82 a
: [CheckId
<Cell
<Option
<&'a B
<'a
>>>>; 2]
85 impl<'a
> HasId
for Cell
<Option
<&'a B
<'a
>>> {
86 fn count(&self) -> usize {
89 Some(b
) => b
.id
.count(),
96 B { id: Id::new(), a: [CheckId(Cell::new(None)), CheckId(Cell::new(None))] }
105 b1
.a
[0].v
.set(Some(&b2
)); //~ ERROR `b2` does not live long enough
106 b1
.a
[1].v
.set(Some(&b3
)); //~ ERROR `b3` does not live long enough
107 b2
.a
[0].v
.set(Some(&b2
)); //~ ERROR `b2` does not live long enough
108 b2
.a
[1].v
.set(Some(&b3
)); //~ ERROR `b3` does not live long enough
109 b3
.a
[0].v
.set(Some(&b1
)); //~ ERROR `b1` does not live long enough
110 b3
.a
[1].v
.set(Some(&b2
)); //~ ERROR `b2` does not live long enough