Skip to content

Commit 645764a

Browse files
committed
---
yaml --- r: 146306 b: refs/heads/try2 c: de9bb97 h: refs/heads/master v: v3
1 parent 95b3f69 commit 645764a

File tree

6 files changed

+272
-8
lines changed

6 files changed

+272
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: afab3307a03c3227706b634b731363004c33a0ac
8+
refs/heads/try2: de9bb9738d8fcd95222fc0c9383953881e31d4d5
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
#[repr(u8)] //~ NOTE discriminant type specified here
12+
enum Eu8 {
13+
Au8 = 23,
14+
Bu8 = 223,
15+
Cu8 = -23, //~ ERROR discriminant value outside specified type
16+
}
17+
18+
#[repr(i8)] //~ NOTE discriminant type specified here
19+
enum Ei8 {
20+
Ai8 = 23,
21+
Bi8 = -23,
22+
Ci8 = 223, //~ ERROR discriminant value outside specified type
23+
}
24+
25+
#[repr(u16)] //~ NOTE discriminant type specified here
26+
enum Eu16 {
27+
Au16 = 23,
28+
Bu16 = 55555,
29+
Cu16 = -22333, //~ ERROR discriminant value outside specified type
30+
}
31+
32+
#[repr(i16)] //~ NOTE discriminant type specified here
33+
enum Ei16 {
34+
Ai16 = 23,
35+
Bi16 = -22333,
36+
Ci16 = 55555, //~ ERROR discriminant value outside specified type
37+
}
38+
39+
#[repr(u32)] //~ NOTE discriminant type specified here
40+
enum Eu32 {
41+
Au32 = 23,
42+
Bu32 = 3_000_000_000,
43+
Cu32 = -2_000_000_000, //~ ERROR discriminant value outside specified type
44+
}
45+
46+
#[repr(i32)] //~ NOTE discriminant type specified here
47+
enum Ei32 {
48+
Ai32 = 23,
49+
Bi32 = -2_000_000_000,
50+
Ci32 = 3_000_000_000, //~ ERROR discriminant value outside specified type
51+
}
52+
53+
// u64 currently allows negative numbers, and i64 allows numbers greater than `1<<63`. This is a
54+
// little counterintuitive, but since the discriminant can store all the bits, and extracting it
55+
// with a cast requires specifying the signedness, there is no loss of information in those cases.
56+
// This also applies to int and uint on 64-bit targets.
57+
58+
pub fn main() { }
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
#[deny(ctypes)];
12+
13+
enum Z { }
14+
enum U { A }
15+
enum B { C, D }
16+
enum T { E, F, G }
17+
18+
extern {
19+
fn zf(x: Z);
20+
fn uf(x: U);
21+
fn bf(x: B); //~ ERROR found enum type without foreign-function-safe
22+
fn tf(x: T); //~ ERROR found enum type without foreign-function-safe
23+
}
24+
25+
pub fn main() { }
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 std::mem::size_of;
12+
13+
enum Ei8 {
14+
Ai8 = -1,
15+
Bi8 = 0
16+
}
17+
18+
enum Eu8 {
19+
Au8 = 0,
20+
Bu8 = 0x80
21+
}
22+
23+
enum Ei16 {
24+
Ai16 = -1,
25+
Bi16 = 0x80
26+
}
27+
28+
enum Eu16 {
29+
Au16 = 0,
30+
Bu16 = 0x8000
31+
}
32+
33+
enum Ei32 {
34+
Ai32 = -1,
35+
Bi32 = 0x8000
36+
}
37+
38+
enum Eu32 {
39+
Au32 = 0,
40+
Bu32 = 0x8000_0000
41+
}
42+
43+
enum Ei64 {
44+
Ai64 = -1,
45+
Bi64 = 0x8000_0000
46+
}
47+
48+
enum Eu64 {
49+
Au64 = 0,
50+
Bu64 = 0x8000_0000_0000_0000
51+
}
52+
53+
pub fn main() {
54+
assert_eq!(size_of::<Ei8>(), 1);
55+
assert_eq!(size_of::<Eu8>(), 1);
56+
assert_eq!(size_of::<Ei16>(), 2);
57+
assert_eq!(size_of::<Eu16>(), 2);
58+
assert_eq!(size_of::<Ei32>(), 4);
59+
assert_eq!(size_of::<Eu32>(), 4);
60+
assert_eq!(size_of::<Ei64>(), 8);
61+
assert_eq!(size_of::<Eu64>(), 8);
62+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 std::mem::size_of;
12+
13+
#[repr(i8)]
14+
enum Ei8 {
15+
Ai8 = 0,
16+
Bi8 = 1
17+
}
18+
19+
#[repr(u8)]
20+
enum Eu8 {
21+
Au8 = 0,
22+
Bu8 = 1
23+
}
24+
25+
#[repr(i16)]
26+
enum Ei16 {
27+
Ai16 = 0,
28+
Bi16 = 1
29+
}
30+
31+
#[repr(u16)]
32+
enum Eu16 {
33+
Au16 = 0,
34+
Bu16 = 1
35+
}
36+
37+
#[repr(i32)]
38+
enum Ei32 {
39+
Ai32 = 0,
40+
Bi32 = 1
41+
}
42+
43+
#[repr(u32)]
44+
enum Eu32 {
45+
Au32 = 0,
46+
Bu32 = 1
47+
}
48+
49+
#[repr(i64)]
50+
enum Ei64 {
51+
Ai64 = 0,
52+
Bi64 = 1
53+
}
54+
55+
#[repr(u64)]
56+
enum Eu64 {
57+
Au64 = 0,
58+
Bu64 = 1
59+
}
60+
61+
#[repr(int)]
62+
enum Eint {
63+
Aint = 0,
64+
Bint = 1
65+
}
66+
67+
#[repr(uint)]
68+
enum Euint {
69+
Auint = 0,
70+
Buint = 1
71+
}
72+
73+
pub fn main() {
74+
assert_eq!(size_of::<Ei8>(), 1);
75+
assert_eq!(size_of::<Eu8>(), 1);
76+
assert_eq!(size_of::<Ei16>(), 2);
77+
assert_eq!(size_of::<Eu16>(), 2);
78+
assert_eq!(size_of::<Ei32>(), 4);
79+
assert_eq!(size_of::<Eu32>(), 4);
80+
assert_eq!(size_of::<Ei64>(), 8);
81+
assert_eq!(size_of::<Eu64>(), 8);
82+
assert_eq!(size_of::<Eint>(), size_of::<int>());
83+
assert_eq!(size_of::<Euint>(), size_of::<uint>());
84+
}

branches/try2/src/test/run-pass/enum-discrim-width-stuff.rs

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,48 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::mem;
11+
#[feature(macro_rules)];
12+
13+
macro_rules! check {
14+
($m:ident, $t:ty, $v:expr) => {{
15+
mod $m {
16+
use std::mem::size_of;
17+
enum E {
18+
V = $v,
19+
A = 0
20+
}
21+
static C: E = V;
22+
pub fn check() {
23+
assert_eq!(size_of::<E>(), size_of::<$t>());
24+
assert_eq!(V as $t, $v);
25+
assert_eq!(C as $t, $v);
26+
assert_eq!(format!("{:?}", V), ~"V");
27+
assert_eq!(format!("{:?}", C), ~"V");
28+
}
29+
}
30+
$m::check();
31+
}}
32+
}
1233

1334
pub fn main() {
14-
enum E { V = 0x1717171717171717 }
15-
static C: E = V;
16-
assert_eq!(V as u64, 0x1717171717171717u64);
17-
assert_eq!(C as u64, 0x1717171717171717u64);
18-
assert_eq!(format!("{:?}", V), ~"V");
19-
assert_eq!(format!("{:?}", C), ~"V");
35+
check!(a, u8, 0x17);
36+
check!(b, u8, 0xe8);
37+
check!(c, u16, 0x1727);
38+
check!(d, u16, 0xe8d8);
39+
check!(e, u32, 0x17273747);
40+
check!(f, u32, 0xe8d8c8b8);
41+
check!(g, u64, 0x1727374757677787u64);
42+
check!(h, u64, 0xe8d8c8b8a8988878u64);
43+
44+
check!(z, i8, 0x17);
45+
check!(y, i8, -0x17);
46+
check!(x, i16, 0x1727);
47+
check!(w, i16, -0x1727);
48+
check!(v, i32, 0x17273747);
49+
check!(u, i32, -0x17273747);
50+
check!(t, i64, 0x1727374757677787);
51+
check!(s, i64, -0x1727374757677787);
52+
53+
enum Simple { A, B }
54+
assert_eq!(std::mem::size_of::<Simple>(), 1);
2055
}

0 commit comments

Comments
 (0)