]> git.proxmox.com Git - rustc.git/blob - src/test/incremental/hashes/panic_exprs.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / test / incremental / hashes / panic_exprs.rs
1 // This test case tests the incremental compilation hash (ICH) implementation
2 // for exprs that can panic at runtime (e.g., because of bounds checking). For
3 // these expressions an error message containing their source location is
4 // generated, so their hash must always depend on their location in the source
5 // code, not just when debuginfo is enabled.
6
7 // The general pattern followed here is: Change one thing between rev1 and rev2
8 // and make sure that the hash has changed, then change nothing between rev2 and
9 // rev3 and make sure that the hash has not changed.
10
11 // build-pass (FIXME(62277): could be check-pass?)
12 // revisions: cfail1 cfail2 cfail3
13 // compile-flags: -Z query-dep-graph -C debug-assertions -O
14
15 #![allow(warnings)]
16 #![feature(rustc_attrs)]
17 #![crate_type="rlib"]
18
19
20 // Indexing expression
21 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
22 #[rustc_clean(cfg="cfail3")]
23 pub fn indexing(slice: &[u8]) -> u8 {
24 #[cfg(cfail1)]
25 {
26 slice[100]
27 }
28 #[cfg(not(cfail1))]
29 {
30 slice[100]
31 }
32 }
33
34
35 // Arithmetic overflow plus
36 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
37 #[rustc_clean(cfg="cfail3")]
38 pub fn arithmetic_overflow_plus(val: i32) -> i32 {
39 #[cfg(cfail1)]
40 {
41 val + 1
42 }
43 #[cfg(not(cfail1))]
44 {
45 val + 1
46 }
47 }
48
49
50 // Arithmetic overflow minus
51 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
52 #[rustc_clean(cfg="cfail3")]
53 pub fn arithmetic_overflow_minus(val: i32) -> i32 {
54 #[cfg(cfail1)]
55 {
56 val - 1
57 }
58 #[cfg(not(cfail1))]
59 {
60 val - 1
61 }
62 }
63
64
65 // Arithmetic overflow mult
66 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
67 #[rustc_clean(cfg="cfail3")]
68 pub fn arithmetic_overflow_mult(val: i32) -> i32 {
69 #[cfg(cfail1)]
70 {
71 val * 2
72 }
73 #[cfg(not(cfail1))]
74 {
75 val * 2
76 }
77 }
78
79
80 // Arithmetic overflow negation
81 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
82 #[rustc_clean(cfg="cfail3")]
83 pub fn arithmetic_overflow_negation(val: i32) -> i32 {
84 #[cfg(cfail1)]
85 {
86 -val
87 }
88 #[cfg(not(cfail1))]
89 {
90 -val
91 }
92 }
93
94
95 // Division by zero
96 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
97 #[rustc_clean(cfg="cfail3")]
98 pub fn division_by_zero(val: i32) -> i32 {
99 #[cfg(cfail1)]
100 {
101 2 / val
102 }
103 #[cfg(not(cfail1))]
104 {
105 2 / val
106 }
107 }
108
109 // Division by zero
110 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
111 #[rustc_clean(cfg="cfail3")]
112 pub fn mod_by_zero(val: i32) -> i32 {
113 #[cfg(cfail1)]
114 {
115 2 % val
116 }
117 #[cfg(not(cfail1))]
118 {
119 2 % val
120 }
121 }
122
123
124 // shift left
125 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
126 #[rustc_clean(cfg="cfail3")]
127 pub fn shift_left(val: i32, shift: usize) -> i32 {
128 #[cfg(cfail1)]
129 {
130 val << shift
131 }
132 #[cfg(not(cfail1))]
133 {
134 val << shift
135 }
136 }
137
138
139 // shift right
140 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
141 #[rustc_clean(cfg="cfail3")]
142 pub fn shift_right(val: i32, shift: usize) -> i32 {
143 #[cfg(cfail1)]
144 {
145 val >> shift
146 }
147 #[cfg(not(cfail1))]
148 {
149 val >> shift
150 }
151 }