Skip to content

Commit eea299b

Browse files
committed
run-pass tests for RFC 1238.
Illustrates cases that worked before and must continue to work, and a case that shows how to use the `unsafe_destructor_blind_to_params` attribute (aka "the UGEH attribute") to work around cannot-assume-parametricity.
1 parent d778e57 commit eea299b

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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#examples-of-code-that-must-continue-to-work
14+
15+
use std::cell::Cell;
16+
17+
struct Concrete<'a>(u32, Cell<Option<&'a Concrete<'a>>>);
18+
19+
fn main() {
20+
let mut data = Vec::new();
21+
data.push(Concrete(0, Cell::new(None)));
22+
data.push(Concrete(0, Cell::new(None)));
23+
24+
data[0].1.set(Some(&data[1]));
25+
data[1].1.set(Some(&data[0]));
26+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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#examples-of-code-that-must-continue-to-work
14+
15+
use std::cell::Cell;
16+
17+
struct Concrete<'a>(u32, Cell<Option<&'a Concrete<'a>>>);
18+
19+
struct Foo<T> { data: Vec<T> }
20+
21+
fn main() {
22+
let mut foo = Foo { data: Vec::new() };
23+
foo.data.push(Concrete(0, Cell::new(None)));
24+
foo.data.push(Concrete(0, Cell::new(None)));
25+
26+
foo.data[0].1.set(Some(&foo.data[1]));
27+
foo.data[1].1.set(Some(&foo.data[0]));
28+
}
29+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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#example-of-the-unguarded-escape-hatch
14+
15+
#![feature(dropck_parametricity)]
16+
use std::cell::Cell;
17+
18+
struct Concrete<'a>(u32, Cell<Option<&'a Concrete<'a>>>);
19+
20+
struct Foo<T> { data: Vec<T> }
21+
22+
impl<T> Drop for Foo<T> {
23+
#[unsafe_destructor_blind_to_params] // This is the UGEH attribute
24+
fn drop(&mut self) { }
25+
}
26+
27+
fn main() {
28+
let mut foo = Foo { data: Vec::new() };
29+
foo.data.push(Concrete(0, Cell::new(None)));
30+
foo.data.push(Concrete(0, Cell::new(None)));
31+
32+
foo.data[0].1.set(Some(&foo.data[1]));
33+
foo.data[1].1.set(Some(&foo.data[0]));
34+
}
35+

0 commit comments

Comments
 (0)