]> git.lizzy.rs Git - rust.git/blob - src/test/ui/span/issue28498-reject-ex1.rs
Auto merge of #98051 - davidtwco:split-dwarf-stabilization, r=wesleywiser
[rust.git] / src / test / ui / span / issue28498-reject-ex1.rs
1 // Example taken from RFC 1238 text
2
3 // https://github.com/rust-lang/rfcs/blob/master/text/1238-nonparametric-dropck.md
4 //     #examples-of-code-that-will-start-to-be-rejected
5
6 // Compare against test/run-pass/issue28498-must-work-ex2.rs
7
8 use std::cell::Cell;
9
10 struct Concrete<'a>(u32, Cell<Option<&'a Concrete<'a>>>);
11
12 struct Foo<T> { data: Vec<T> }
13
14 fn potentially_specialized_wrt_t<T>(t: &T) {
15     // Hypothetical code that does one thing for generic T and then is
16     // specialized for T == Concrete (and the specialized form can
17     // then access a reference held in concrete tuple).
18     //
19     // (We don't have specialization yet, but we want to allow for it
20     // in the future.)
21 }
22
23 impl<T> Drop for Foo<T> {
24     fn drop(&mut self) {
25         potentially_specialized_wrt_t(&self.data[0])
26     }
27 }
28
29 fn main() {
30     let mut foo = Foo {  data: Vec::new() };
31     foo.data.push(Concrete(0, Cell::new(None)));
32     foo.data.push(Concrete(0, Cell::new(None)));
33
34     foo.data[0].1.set(Some(&foo.data[1]));
35     //~^ ERROR borrow may still be in use when destructor runs
36     foo.data[1].1.set(Some(&foo.data[0]));
37 }