]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hashes/panic_exprs.rs
Auto merge of #45953 - estebank:tab-4, r=nikomatsakis
[rust.git] / src / test / incremental / hashes / panic_exprs.rs
1 // Copyright 2016 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 // This test case tests the incremental compilation hash (ICH) implementation
12 // for exprs that can panic at runtime (e.g. because of bounds checking). For
13 // these expressions an error message containing their source location is
14 // generated, so their hash must always depend on their location in the source
15 // code, not just when debuginfo is enabled.
16
17 // The general pattern followed here is: Change one thing between rev1 and rev2
18 // and make sure that the hash has changed, then change nothing between rev2 and
19 // rev3 and make sure that the hash has not changed.
20
21 // must-compile-successfully
22 // revisions: cfail1 cfail2 cfail3
23 // compile-flags: -Z query-dep-graph -C debug-assertions
24
25 #![allow(warnings)]
26 #![feature(rustc_attrs)]
27 #![crate_type="rlib"]
28
29
30 // Indexing expression ---------------------------------------------------------
31 #[cfg(cfail1)]
32 pub fn indexing(slice: &[u8]) -> u8 {
33     slice[100]
34 }
35
36 #[cfg(not(cfail1))]
37 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
38 #[rustc_clean(cfg="cfail3")]
39 pub fn indexing(slice: &[u8]) -> u8 {
40     slice[100]
41 }
42
43
44 // Arithmetic overflow plus ----------------------------------------------------
45 #[cfg(cfail1)]
46 pub fn arithmetic_overflow_plus(val: i32) -> i32 {
47     val + 1
48 }
49
50 #[cfg(not(cfail1))]
51 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
52 #[rustc_clean(cfg="cfail3")]
53 pub fn arithmetic_overflow_plus(val: i32) -> i32 {
54     val + 1
55 }
56
57
58 // Arithmetic overflow minus ----------------------------------------------------
59 #[cfg(cfail1)]
60 pub fn arithmetic_overflow_minus(val: i32) -> i32 {
61     val - 1
62 }
63
64 #[cfg(not(cfail1))]
65 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
66 #[rustc_clean(cfg="cfail3")]
67 pub fn arithmetic_overflow_minus(val: i32) -> i32 {
68     val - 1
69 }
70
71
72 // Arithmetic overflow mult ----------------------------------------------------
73 #[cfg(cfail1)]
74 pub fn arithmetic_overflow_mult(val: i32) -> i32 {
75     val * 2
76 }
77
78 #[cfg(not(cfail1))]
79 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
80 #[rustc_clean(cfg="cfail3")]
81 pub fn arithmetic_overflow_mult(val: i32) -> i32 {
82     val * 2
83 }
84
85
86 // Arithmetic overflow negation ------------------------------------------------
87 #[cfg(cfail1)]
88 pub fn arithmetic_overflow_negation(val: i32) -> i32 {
89     -val
90 }
91
92 #[cfg(not(cfail1))]
93 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
94 #[rustc_clean(cfg="cfail3")]
95 pub fn arithmetic_overflow_negation(val: i32) -> i32 {
96     -val
97 }
98
99
100 // Division by zero ------------------------------------------------------------
101 #[cfg(cfail1)]
102 pub fn division_by_zero(val: i32) -> i32 {
103     2 / val
104 }
105
106 #[cfg(not(cfail1))]
107 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
108 #[rustc_clean(cfg="cfail3")]
109 pub fn division_by_zero(val: i32) -> i32 {
110     2 / val
111 }
112
113 // Division by zero ------------------------------------------------------------
114 #[cfg(cfail1)]
115 pub fn mod_by_zero(val: i32) -> i32 {
116     2 % val
117 }
118
119 #[cfg(not(cfail1))]
120 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
121 #[rustc_clean(cfg="cfail3")]
122 pub fn mod_by_zero(val: i32) -> i32 {
123     2 % val
124 }
125
126
127 // shift left ------------------------------------------------------------------
128 #[cfg(cfail1)]
129 pub fn shift_left(val: i32, shift: usize) -> i32 {
130     val << shift
131 }
132
133 #[cfg(not(cfail1))]
134 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
135 #[rustc_clean(cfg="cfail3")]
136 pub fn shift_left(val: i32, shift: usize) -> i32 {
137     val << shift
138 }
139
140
141 // shift right ------------------------------------------------------------------
142 #[cfg(cfail1)]
143 pub fn shift_right(val: i32, shift: usize) -> i32 {
144     val >> shift
145 }
146
147 #[cfg(not(cfail1))]
148 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
149 #[rustc_clean(cfg="cfail3")]
150 pub fn shift_right(val: i32, shift: usize) -> i32 {
151     val >> shift
152 }
153
154
155 // THE FOLLOWING ITEMS SHOULD NOT BE INFLUENCED BY THEIR SOURCE LOCATION
156
157 // bitwise ---------------------------------------------------------------------
158 #[cfg(cfail1)]
159 pub fn bitwise(val: i32) -> i32 {
160     !val & 0x101010101 | 0x45689 ^ 0x2372382
161 }
162
163 #[cfg(not(cfail1))]
164 #[rustc_clean(cfg="cfail2")]
165 #[rustc_clean(cfg="cfail3")]
166 pub fn bitwise(val: i32) -> i32 {
167     !val & 0x101010101 | 0x45689 ^ 0x2372382
168 }
169
170
171 // logical ---------------------------------------------------------------------
172 #[cfg(cfail1)]
173 pub fn logical(val1: bool, val2: bool, val3: bool) -> bool {
174     val1 && val2 || val3
175 }
176
177 #[cfg(not(cfail1))]
178 #[rustc_clean(cfg="cfail2")]
179 #[rustc_clean(cfg="cfail3")]
180 pub fn logical(val1: bool, val2: bool, val3: bool) -> bool {
181     val1 && val2 || val3
182 }