1 // Check that an arena (TypedArena) cannot carry elements whose drop
2 // methods might access borrowed data of lifetime that does not
3 // strictly outlive the arena itself.
5 // Compare against run-pass/dropck_tarena_sound_drop.rs, which shows a
6 // similar setup, but loosens `f` so that the struct `C<'a>` can be
7 // fed a lifetime longer than that of the arena.
9 // (Also compare against dropck_tarena_cycle_checked.rs, from which
10 // this was reduced to better understand its error message.)
12 #![feature(rustc_private)]
14 extern crate rustc_arena
;
16 use rustc_arena
::TypedArena
;
18 trait HasId { fn count(&self) -> usize; }
20 struct CheckId
<T
:HasId
> { v: T }
22 // In the code below, the impl of HasId for `&'a usize` does not
23 // actually access the borrowed data, but the point is that the
24 // interface to CheckId does not (and cannot) know that, and therefore
25 // when encountering a value V of type CheckId<S>, we must
26 // conservatively force the type S to strictly outlive V.
27 impl<T
:HasId
> Drop
for CheckId
<T
> {
29 assert
!(self.v
.count() > 0);
33 struct C
<'a
> { v: CheckId<&'a usize>, }
35 impl<'a
> HasId
for &'a
usize { fn count(&self) -> usize { 1 }
}
37 fn f
<'a
>(_arena
: &'a TypedArena
<C
<'a
>>) {}
40 let arena
: TypedArena
<C
> = TypedArena
::default();
42 } //~^ ERROR `arena` does not live long enough