]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue28498-ugeh-ex1.rs
Auto merge of #28816 - petrochenkov:unistruct, r=nrc
[rust.git] / src / test / run-pass / issue28498-ugeh-ex1.rs
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 //     #example-of-the-unguarded-escape-hatch
15
16 #![feature(dropck_parametricity)]
17 use std::cell::Cell;
18
19 struct Concrete<'a>(u32, Cell<Option<&'a Concrete<'a>>>);
20
21 struct Foo<T> { data: Vec<T> }
22
23 impl<T> Drop for Foo<T> {
24     // Below is the UGEH attribute
25     #[unsafe_destructor_blind_to_params]
26     fn drop(&mut self) { }
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     foo.data[1].1.set(Some(&foo.data[0]));
36 }
37