3 #![allow(unknown_lints)]
4 // Check that an arena (TypedArena) can carry elements whose drop
5 // methods might access borrowed data, as long as the borrowed data
6 // has lifetime that strictly outlives the arena itself.
8 // Compare against ui-fulldeps/dropck-tarena-unsound-drop.rs, which
9 // shows a similar setup, but restricts `f` so that the struct `C<'a>`
10 // is force-fed a lifetime equal to that of the borrowed arena.
13 #![feature(rustc_private)]
15 extern crate rustc_arena
;
17 // Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
19 #[allow(unused_extern_crates)]
20 extern crate rustc_driver
;
22 use rustc_arena
::TypedArena
;
24 trait HasId { fn count(&self) -> usize; }
26 struct CheckId
<T
:HasId
> { v: T }
28 // In the code below, the impl of HasId for `&'a usize` does not
29 // actually access the borrowed data, but the point is that the
30 // interface to CheckId does not (and cannot) know that, and therefore
31 // when encountering a value V of type CheckId<S>, we must
32 // conservatively force the type S to strictly outlive V.
33 impl<T
:HasId
> Drop
for CheckId
<T
> {
35 assert
!(self.v
.count() > 0);
39 struct C
<'a
> { _v: CheckId<&'a usize>, }
41 impl<'a
> HasId
for &'a
usize { fn count(&self) -> usize { 1 }
}
43 fn f
<'a
, 'b
>(_arena
: &'a TypedArena
<C
<'b
>>) {}
46 let arena
: TypedArena
<C
> = TypedArena
::default();