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 // This test is a simple example of code that violates the dropck
12 // rules: it pushes `&x` and `&y` into a bag (with dtor), but the
13 // referenced data will be dropped before the bag is.
22 let mut v = Bag::new();
28 //~^ ERROR `x` does not live long enough
30 //~^ ERROR `y` does not live long enough
32 assert_eq!(v.0, [&3, &4]);
35 //`Vec<T>` is #[may_dangle] w.r.t. `T`; putting a bag over its head
36 // forces borrowck to treat dropping the bag as a potential use.
37 struct Bag<T>(Vec<T>);
38 impl<T> Drop for Bag<T> { fn drop(&mut self) { } }
41 fn new() -> Self { Bag(Vec::new()) }
42 fn push(&mut self, t: T) { self.0.push(t); }