Skip to content

Commit 205092e

Browse files
committed
---
yaml --- r: 55739 b: refs/heads/master c: edc1324 h: refs/heads/master i: 55737: c8e596a 55735: f3f5ef5 v: v3
1 parent e6557d0 commit 205092e

File tree

3 files changed

+132
-1
lines changed

3 files changed

+132
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 22f751f0f398c508be6966b9d6d1a498cd05baac
2+
refs/heads/master: edc1324e7e665080e6695625ba6a5ede3e32f5a8
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 79a2b2eafc3c766cecec8a5f76317693bae9ed17
55
refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Copyright 2013 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+
use core::{option, cast};
12+
13+
// Iota-reduction is a rule in the Calculus of (Co-)Inductive Constructions,
14+
// which "says that a destructor applied to an object built from a constructor
15+
// behaves as expected". -- http://coq.inria.fr/doc/Reference-Manual006.html
16+
//
17+
// It's a little more complicated here, because of pointers and regions and
18+
// trying to get assert failure messages that at least identify which case
19+
// failed.
20+
21+
enum E<T> { Thing(int, T), Nothing((), ((), ()), [i8, ..0]) }
22+
impl<T> E<T> {
23+
fn is_none(&self) -> bool {
24+
match *self {
25+
Thing(*) => false,
26+
Nothing(*) => true
27+
}
28+
}
29+
fn get_ref<'r>(&'r self) -> (int, &'r T) {
30+
match *self {
31+
Nothing(*) => fail!(fmt!("E::get_ref(Nothing::<%s>)", stringify!($T))),
32+
Thing(x, ref y) => (x, y)
33+
}
34+
}
35+
}
36+
37+
macro_rules! check_option {
38+
($e:expr: $T:ty) => {{
39+
// FIXME #6000: remove the copy
40+
check_option!(copy $e: $T, |ptr| assert!(*ptr == $e));
41+
}};
42+
($e:expr: $T:ty, |$v:ident| $chk:expr) => {{
43+
assert!(option::None::<$T>.is_none());
44+
let s_ = option::Some::<$T>($e);
45+
let $v = s_.get_ref();
46+
$chk
47+
}}
48+
}
49+
50+
macro_rules! check_fancy {
51+
($e:expr: $T:ty) => {{
52+
// FIXME #6000: remove the copy
53+
check_fancy!(copy $e: $T, |ptr| assert!(*ptr == $e));
54+
}};
55+
($e:expr: $T:ty, |$v:ident| $chk:expr) => {{
56+
assert!(Nothing::<$T>((), ((), ()), [23i8, ..0]).is_none());
57+
let t_ = Thing::<$T>(23, $e);
58+
match t_.get_ref() {
59+
(23, $v) => { $chk }
60+
_ => fail!(fmt!("Thing::<%s>(23, %s).get_ref() != (23, _)",
61+
stringify!($T), stringify!($e)))
62+
}
63+
}}
64+
}
65+
66+
macro_rules! check_type {
67+
($($a:tt)*) => {{
68+
check_option!($($a)*);
69+
check_fancy!($($a)*);
70+
}}
71+
}
72+
73+
pub fn main() {
74+
check_type!(&17: &int);
75+
check_type!(~18: ~int);
76+
check_type!(@19: @int);
77+
check_type!(~"foo": ~str);
78+
check_type!(@"bar": @str);
79+
check_type!(~[]: ~[int]);
80+
check_type!(~[20, 22]: ~[int]);
81+
check_type!(@[]: @[int]);
82+
check_type!(@[24, 26]: @[int]);
83+
let mint: uint = unsafe { cast::transmute(main) };
84+
check_type!(main: extern fn(), |pthing| {
85+
assert!(mint == unsafe { cast::transmute(*pthing) })
86+
});
87+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2013 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+
enum E<T> { Thing(int, T), Nothing((), ((), ()), [i8, ..0]) }
12+
struct S<T>(int, T);
13+
14+
// These are macros so we get useful assert messages.
15+
16+
macro_rules! check_option {
17+
($T:ty) => {
18+
assert!(sys::size_of::<Option<$T>>() == sys::size_of::<$T>());
19+
}
20+
}
21+
22+
macro_rules! check_fancy {
23+
($T:ty) => {
24+
assert!(sys::size_of::<E<$T>>() == sys::size_of::<S<$T>>());
25+
}
26+
}
27+
28+
macro_rules! check_type {
29+
($T:ty) => {{
30+
check_option!($T);
31+
check_fancy!($T);
32+
}}
33+
}
34+
35+
pub fn main() {
36+
check_type!(&'static int);
37+
check_type!(~int);
38+
check_type!(@int);
39+
check_type!(~str);
40+
check_type!(@str);
41+
check_type!(~[int]);
42+
check_type!(@[int]);
43+
check_type!(extern fn());
44+
}

0 commit comments

Comments
 (0)