]> git.proxmox.com Git - rustc.git/blame - src/test/compile-fail/issue28498-reject-ex1.rs
New upstream version 1.13.0+dfsg1
[rustc.git] / src / test / compile-fail / issue28498-reject-ex1.rs
CommitLineData
b039eaaf
SL
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.
4//
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.
10
11// Example taken from RFC 1238 text
12
13// https://github.com/rust-lang/rfcs/blob/master/text/1238-nonparametric-dropck.md
14// #examples-of-code-that-will-start-to-be-rejected
15
16// Compare against test/run-pass/issue28498-must-work-ex2.rs
17
18use std::cell::Cell;
19
20struct Concrete<'a>(u32, Cell<Option<&'a Concrete<'a>>>);
21
22struct Foo<T> { data: Vec<T> }
23
24fn 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).
28 //
29 // (We don't have specialization yet, but we want to allow for it
30 // in the future.)
31}
32
33impl<T> Drop for Foo<T> {
34 fn drop(&mut self) {
35 potentially_specialized_wrt_t(&self.data[0])
36 }
37}
38
39fn main() {
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)));
43
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
48}