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 // Example taken from RFC 1238 text
13 // https://github.com/rust-lang/rfcs/blob/master/text/1238-nonparametric-dropck.md
14 // #examples-of-code-that-will-start-to-be-rejected
16 // Compare against test/run-pass/issue28498-must-work-ex2.rs
20 struct Concrete<'a>(u32, Cell<Option<&'a Concrete<'a>>>);
22 struct Foo<T> { data: Vec<T> }
24 fn potentially_specialized_wrt_t<T>(t: &T) {
25 // Hypothetical code that does one thing for generic T and then is
26 // specialized for T == Concrete (and the specialized form can
27 // then access a reference held in concrete tuple).
29 // (We don't have specialization yet, but we want to allow for it
33 impl<T> Drop for Foo<T> {
35 potentially_specialized_wrt_t(&self.data[0])
40 let mut foo = Foo { data: Vec::new() };
41 foo.data.push(Concrete(0, Cell::new(None)));
42 foo.data.push(Concrete(0, Cell::new(None)));
44 foo.data[0].1.set(Some(&foo.data[1]));
45 //~^ ERROR `foo.data` does not live long enough
46 foo.data[1].1.set(Some(&foo.data[0]));
47 //~^ ERROR `foo.data` does not live long enough