]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hashes/statics.rs
Auto merge of #45647 - nrc:rls-bugs, r=eddyb
[rust.git] / src / test / incremental / hashes / statics.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
12 // This test case tests the incremental compilation hash (ICH) implementation
13 // for statics.
14
15 // The general pattern followed here is: Change one thing between rev1 and rev2
16 // and make sure that the hash has changed, then change nothing between rev2 and
17 // rev3 and make sure that the hash has not changed.
18
19 // must-compile-successfully
20 // revisions: cfail1 cfail2 cfail3
21 // compile-flags: -Z query-dep-graph
22
23 #![allow(warnings)]
24 #![feature(rustc_attrs)]
25 #![feature(linkage)]
26 #![feature(thread_local)]
27 #![crate_type="rlib"]
28
29
30 // Change static visibility ---------------------------------------------------
31 #[cfg(cfail1)]
32 static STATIC_VISIBILITY: u8 = 0;
33
34 #[cfg(not(cfail1))]
35 #[rustc_clean(cfg="cfail2", except="Hir,HirBody")]
36 #[rustc_clean(cfg="cfail3")]
37 #[rustc_metadata_dirty(cfg="cfail2")]
38 #[rustc_metadata_clean(cfg="cfail3")]
39 pub static STATIC_VISIBILITY: u8 = 0;
40
41
42 // Change static mutability ---------------------------------------------------
43 #[cfg(cfail1)]
44 static STATIC_MUTABILITY: u8 = 0;
45
46 #[cfg(not(cfail1))]
47 #[rustc_clean(cfg="cfail2", except="Hir,HirBody")]
48 #[rustc_clean(cfg="cfail3")]
49 #[rustc_metadata_dirty(cfg="cfail2")]
50 #[rustc_metadata_clean(cfg="cfail3")]
51 static mut STATIC_MUTABILITY: u8 = 0;
52
53
54 // Add linkage attribute ------------------------------------------------------
55 #[cfg(cfail1)]
56 static STATIC_LINKAGE: u8 = 0;
57
58 #[cfg(not(cfail1))]
59 #[rustc_clean(cfg="cfail2", except="Hir,HirBody")]
60 #[rustc_clean(cfg="cfail3")]
61 #[rustc_metadata_dirty(cfg="cfail2")]
62 #[rustc_metadata_clean(cfg="cfail3")]
63 #[linkage="weak_odr"]
64 static STATIC_LINKAGE: u8 = 0;
65
66
67 // Add no_mangle attribute ----------------------------------------------------
68 #[cfg(cfail1)]
69 static STATIC_NO_MANGLE: u8 = 0;
70
71 #[cfg(not(cfail1))]
72 #[rustc_clean(cfg="cfail2", except="Hir,HirBody")]
73 #[rustc_clean(cfg="cfail3")]
74 #[rustc_metadata_dirty(cfg="cfail2")]
75 #[rustc_metadata_clean(cfg="cfail3")]
76 #[no_mangle]
77 static STATIC_NO_MANGLE: u8 = 0;
78
79
80 // Add thread_local attribute -------------------------------------------------
81 #[cfg(cfail1)]
82 static STATIC_THREAD_LOCAL: u8 = 0;
83
84 #[cfg(not(cfail1))]
85 #[rustc_clean(cfg="cfail2", except="Hir,HirBody")]
86 #[rustc_clean(cfg="cfail3")]
87 #[rustc_metadata_dirty(cfg="cfail2")]
88 #[rustc_metadata_clean(cfg="cfail3")]
89 #[thread_local]
90 static STATIC_THREAD_LOCAL: u8 = 0;
91
92
93 // Change type from i16 to u64 ------------------------------------------------
94 #[cfg(cfail1)]
95 static STATIC_CHANGE_TYPE_1: i16 = 0;
96
97 #[cfg(not(cfail1))]
98 #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")]
99 #[rustc_clean(cfg="cfail3")]
100 #[rustc_metadata_dirty(cfg="cfail2")]
101 #[rustc_metadata_clean(cfg="cfail3")]
102 static STATIC_CHANGE_TYPE_1: u64 = 0;
103
104
105 // Change type from Option<i8> to Option<u16> ---------------------------------
106 #[cfg(cfail1)]
107 static STATIC_CHANGE_TYPE_2: Option<i8> = None;
108
109 #[cfg(not(cfail1))]
110 #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")]
111 #[rustc_clean(cfg="cfail3")]
112 #[rustc_metadata_dirty(cfg="cfail2")]
113 #[rustc_metadata_clean(cfg="cfail3")]
114 static STATIC_CHANGE_TYPE_2: Option<u16> = None;
115
116
117 // Change value between simple literals ---------------------------------------
118 #[rustc_clean(cfg="cfail2", except="HirBody")]
119 #[rustc_clean(cfg="cfail3")]
120 #[rustc_metadata_clean(cfg="cfail2")]
121 #[rustc_metadata_clean(cfg="cfail3")]
122 static STATIC_CHANGE_VALUE_1: i16 = {
123     #[cfg(cfail1)]
124     { 1 }
125
126     #[cfg(not(cfail1))]
127     { 2 }
128 };
129
130
131 // Change value between expressions -------------------------------------------
132 #[rustc_clean(cfg="cfail2", except="HirBody")]
133 #[rustc_clean(cfg="cfail3")]
134 #[rustc_metadata_clean(cfg="cfail2")]
135 #[rustc_metadata_clean(cfg="cfail3")]
136 static STATIC_CHANGE_VALUE_2: i16 = {
137     #[cfg(cfail1)]
138     { 1 + 1 }
139
140     #[cfg(not(cfail1))]
141     { 1 + 2 }
142 };
143
144 #[rustc_clean(cfg="cfail2", except="HirBody")]
145 #[rustc_clean(cfg="cfail3")]
146 #[rustc_metadata_clean(cfg="cfail2")]
147 #[rustc_metadata_clean(cfg="cfail3")]
148 static STATIC_CHANGE_VALUE_3: i16 = {
149     #[cfg(cfail1)]
150     { 2 + 3 }
151
152     #[cfg(not(cfail1))]
153     { 2 * 3 }
154 };
155
156 #[rustc_clean(cfg="cfail2", except="HirBody")]
157 #[rustc_clean(cfg="cfail3")]
158 #[rustc_metadata_clean(cfg="cfail2")]
159 #[rustc_metadata_clean(cfg="cfail3")]
160 static STATIC_CHANGE_VALUE_4: i16 = {
161     #[cfg(cfail1)]
162     { 1 + 2 * 3 }
163
164     #[cfg(not(cfail1))]
165     { 1 + 2 * 4 }
166 };
167
168
169 // Change type indirectly -----------------------------------------------------
170 struct ReferencedType1;
171 struct ReferencedType2;
172
173 mod static_change_type_indirectly {
174     #[cfg(cfail1)]
175     use super::ReferencedType1 as Type;
176
177     #[cfg(not(cfail1))]
178     use super::ReferencedType2 as Type;
179
180     #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")]
181     #[rustc_clean(cfg="cfail3")]
182     #[rustc_metadata_dirty(cfg="cfail2")]
183     #[rustc_metadata_clean(cfg="cfail3")]
184     static STATIC_CHANGE_TYPE_INDIRECTLY_1: Type = Type;
185
186     #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")]
187     #[rustc_clean(cfg="cfail3")]
188     #[rustc_metadata_dirty(cfg="cfail2")]
189     #[rustc_metadata_clean(cfg="cfail3")]
190     static STATIC_CHANGE_TYPE_INDIRECTLY_2: Option<Type> = None;
191 }