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