]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/discrim-ill-typed.rs
New upstream version 1.12.0+dfsg1
[rustc.git] / src / test / compile-fail / discrim-ill-typed.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 // When explicit discriminant value has
12 // a type that does not match the representation
13 // type, rustc should fail gracefully.
14
15 // See also run-pass/discrim-explicit-23030.rs where the input types
16 // are correct.
17
18 #![allow(dead_code, unused_variables, unused_imports)]
19
20 use std::{i8,u8,i16,u16,i32,u32,i64, u64};
21
22 fn f_i8() {
23 #[repr(i8)]
24 enum A {
25 Ok = i8::MAX - 1,
26 Ok2,
27 OhNo = 0_u8,
28 //~^ ERROR E0080
29 //~| expected i8, found u8
30 }
31
32 let x = A::Ok;
33 }
34
35 fn f_u8() {
36 #[repr(u8)]
37 enum A {
38 Ok = u8::MAX - 1,
39 Ok2,
40 OhNo = 0_i8,
41 //~^ ERROR E0080
42 //~| expected u8, found i8
43 }
44
45 let x = A::Ok;
46 }
47
48 fn f_i16() {
49 #[repr(i16)]
50 enum A {
51 Ok = i16::MAX - 1,
52 Ok2,
53 OhNo = 0_u16,
54 //~^ ERROR E0080
55 //~| expected i16, found u16
56 }
57
58 let x = A::Ok;
59 }
60
61 fn f_u16() {
62 #[repr(u16)]
63 enum A {
64 Ok = u16::MAX - 1,
65 Ok2,
66 OhNo = 0_i16,
67 //~^ ERROR E0080
68 //~| expected u16, found i16
69 }
70
71 let x = A::Ok;
72 }
73
74 fn f_i32() {
75 #[repr(i32)]
76 enum A {
77 Ok = i32::MAX - 1,
78 Ok2,
79 OhNo = 0_u32,
80 //~^ ERROR E0080
81 //~| expected i32, found u32
82 }
83
84 let x = A::Ok;
85 }
86
87 fn f_u32() {
88 #[repr(u32)]
89 enum A {
90 Ok = u32::MAX - 1,
91 Ok2,
92 OhNo = 0_i32,
93 //~^ ERROR E0080
94 //~| expected u32, found i32
95 }
96
97 let x = A::Ok;
98 }
99
100 fn f_i64() {
101 #[repr(i64)]
102 enum A {
103 Ok = i64::MAX - 1,
104 Ok2,
105 OhNo = 0_u64,
106 //~^ ERROR E0080
107 //~| expected i64, found u64
108 }
109
110 let x = A::Ok;
111 }
112
113 fn f_u64() {
114 #[repr(u64)]
115 enum A {
116 Ok = u64::MAX - 1,
117 Ok2,
118 OhNo = 0_i64,
119 //~^ ERROR E0080
120 //~| expected u64, found i64
121 }
122
123 let x = A::Ok;
124 }
125
126 fn main() { }