// Copyright 2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 or the MIT license // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. // Check that a arena (TypedArena) cannot carry elements whose drop // methods might access borrowed data of lifetime that does not // strictly outlive the arena itself. // // Compare against run-pass/dropck_tarena_sound_drop.rs, which shows a // similar setup, but loosens `f` so that the struct `C<'a>` can be // fed a lifetime longer than that of the arena. // // (Also compare against dropck_tarena_cycle_checked.rs, from which // this was reduced to better understand its error message.) #![allow(unstable)] #![feature(unsafe_destructor)] extern crate arena; use arena::TypedArena; trait HasId { fn count(&self) -> usize; } struct CheckId { 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 // when encountering the a value V of type CheckId, we must // conservatively force the type S to strictly outlive V. #[unsafe_destructor] impl Drop for CheckId { 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>(_arena: &'a TypedArena>) {} fn main() { let arena: TypedArena = TypedArena::new(); f(&arena); //~ ERROR `arena` does not live long enough }