2019-07-26 21:54:25 +00:00
|
|
|
//@ run-pass
|
|
|
|
|
2018-09-17 09:18:35 +00:00
|
|
|
#![allow(unknown_lints)]
|
2015-10-07 22:11:25 +00:00
|
|
|
// Check that an arena (TypedArena) can carry elements whose drop
|
2015-01-05 12:26:29 +00:00
|
|
|
// methods might access borrowed data, as long as the borrowed data
|
|
|
|
// has lifetime that strictly outlives the arena itself.
|
|
|
|
//
|
2020-12-28 17:15:16 +00:00
|
|
|
// Compare against ui-fulldeps/dropck-tarena-unsound-drop.rs, which
|
2015-01-05 12:26:29 +00:00
|
|
|
// shows a similar setup, but restricts `f` so that the struct `C<'a>`
|
|
|
|
// is force-fed a lifetime equal to that of the borrowed arena.
|
|
|
|
|
|
|
|
#![allow(unstable)]
|
2015-04-27 21:10:49 +00:00
|
|
|
#![feature(rustc_private)]
|
2015-01-05 12:26:29 +00:00
|
|
|
|
2020-06-02 17:19:49 +00:00
|
|
|
extern crate rustc_arena;
|
2015-01-05 12:26:29 +00:00
|
|
|
|
2022-12-12 19:37:28 +00:00
|
|
|
// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
|
|
|
|
// files.
|
|
|
|
#[allow(unused_extern_crates)]
|
|
|
|
extern crate rustc_driver;
|
|
|
|
|
2020-06-02 17:19:49 +00:00
|
|
|
use rustc_arena::TypedArena;
|
2015-01-05 12:26:29 +00:00
|
|
|
|
|
|
|
trait HasId { fn count(&self) -> usize; }
|
|
|
|
|
|
|
|
struct CheckId<T:HasId> { v: T }
|
|
|
|
|
|
|
|
// In the code below, the impl of HasId for `&'a usize` does not
|
|
|
|
// actually access the borrowed data, but the point is that the
|
|
|
|
// interface to CheckId does not (and cannot) know that, and therefore
|
2018-11-11 13:52:36 +00:00
|
|
|
// when encountering a value V of type CheckId<S>, we must
|
2015-01-05 12:26:29 +00:00
|
|
|
// conservatively force the type S to strictly outlive V.
|
|
|
|
impl<T:HasId> Drop for CheckId<T> {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
assert!(self.v.count() > 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct C<'a> { _v: CheckId<&'a usize>, }
|
|
|
|
|
|
|
|
impl<'a> HasId for &'a usize { fn count(&self) -> usize { 1 } }
|
|
|
|
|
|
|
|
fn f<'a, 'b>(_arena: &'a TypedArena<C<'b>>) {}
|
|
|
|
|
|
|
|
fn main() {
|
2018-10-16 17:51:12 +00:00
|
|
|
let arena: TypedArena<C> = TypedArena::default();
|
2015-01-05 12:26:29 +00:00
|
|
|
f(&arena);
|
|
|
|
}
|