]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hashes/statics.rs
Rollup merge of #46518 - partim:asref-borrow-doc, r=dtolnay
[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 -Zincremental-ignore-spans
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 pub static STATIC_VISIBILITY: u8 = 0;
38
39
40 // Change static mutability ---------------------------------------------------
41 #[cfg(cfail1)]
42 static STATIC_MUTABILITY: u8 = 0;
43
44 #[cfg(not(cfail1))]
45 #[rustc_clean(cfg="cfail2", except="Hir,HirBody")]
46 #[rustc_clean(cfg="cfail3")]
47 static mut STATIC_MUTABILITY: u8 = 0;
48
49
50 // Add linkage attribute ------------------------------------------------------
51 #[cfg(cfail1)]
52 static STATIC_LINKAGE: u8 = 0;
53
54 #[cfg(not(cfail1))]
55 #[rustc_clean(cfg="cfail2", except="Hir,HirBody")]
56 #[rustc_clean(cfg="cfail3")]
57 #[linkage="weak_odr"]
58 static STATIC_LINKAGE: u8 = 0;
59
60
61 // Add no_mangle attribute ----------------------------------------------------
62 #[cfg(cfail1)]
63 static STATIC_NO_MANGLE: u8 = 0;
64
65 #[cfg(not(cfail1))]
66 #[rustc_clean(cfg="cfail2", except="Hir,HirBody")]
67 #[rustc_clean(cfg="cfail3")]
68 #[no_mangle]
69 static STATIC_NO_MANGLE: u8 = 0;
70
71
72 // Add thread_local attribute -------------------------------------------------
73 #[cfg(cfail1)]
74 static STATIC_THREAD_LOCAL: u8 = 0;
75
76 #[cfg(not(cfail1))]
77 #[rustc_clean(cfg="cfail2", except="Hir,HirBody")]
78 #[rustc_clean(cfg="cfail3")]
79 #[thread_local]
80 static STATIC_THREAD_LOCAL: u8 = 0;
81
82
83 // Change type from i16 to u64 ------------------------------------------------
84 #[cfg(cfail1)]
85 static STATIC_CHANGE_TYPE_1: i16 = 0;
86
87 #[cfg(not(cfail1))]
88 #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")]
89 #[rustc_clean(cfg="cfail3")]
90 static STATIC_CHANGE_TYPE_1: u64 = 0;
91
92
93 // Change type from Option<i8> to Option<u16> ---------------------------------
94 #[cfg(cfail1)]
95 static STATIC_CHANGE_TYPE_2: Option<i8> = None;
96
97 #[cfg(not(cfail1))]
98 #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")]
99 #[rustc_clean(cfg="cfail3")]
100 static STATIC_CHANGE_TYPE_2: Option<u16> = None;
101
102
103 // Change value between simple literals ---------------------------------------
104 #[rustc_clean(cfg="cfail2", except="HirBody")]
105 #[rustc_clean(cfg="cfail3")]
106 static STATIC_CHANGE_VALUE_1: i16 = {
107     #[cfg(cfail1)]
108     { 1 }
109
110     #[cfg(not(cfail1))]
111     { 2 }
112 };
113
114
115 // Change value between expressions -------------------------------------------
116 #[rustc_clean(cfg="cfail2", except="HirBody")]
117 #[rustc_clean(cfg="cfail3")]
118 static STATIC_CHANGE_VALUE_2: i16 = {
119     #[cfg(cfail1)]
120     { 1 + 1 }
121
122     #[cfg(not(cfail1))]
123     { 1 + 2 }
124 };
125
126 #[rustc_clean(cfg="cfail2", except="HirBody")]
127 #[rustc_clean(cfg="cfail3")]
128 static STATIC_CHANGE_VALUE_3: i16 = {
129     #[cfg(cfail1)]
130     { 2 + 3 }
131
132     #[cfg(not(cfail1))]
133     { 2 * 3 }
134 };
135
136 #[rustc_clean(cfg="cfail2", except="HirBody")]
137 #[rustc_clean(cfg="cfail3")]
138 static STATIC_CHANGE_VALUE_4: i16 = {
139     #[cfg(cfail1)]
140     { 1 + 2 * 3 }
141
142     #[cfg(not(cfail1))]
143     { 1 + 2 * 4 }
144 };
145
146
147 // Change type indirectly -----------------------------------------------------
148 struct ReferencedType1;
149 struct ReferencedType2;
150
151 mod static_change_type_indirectly {
152     #[cfg(cfail1)]
153     use super::ReferencedType1 as Type;
154
155     #[cfg(not(cfail1))]
156     use super::ReferencedType2 as Type;
157
158     #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")]
159     #[rustc_clean(cfg="cfail3")]
160     static STATIC_CHANGE_TYPE_INDIRECTLY_1: Type = Type;
161
162     #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")]
163     #[rustc_clean(cfg="cfail3")]
164     static STATIC_CHANGE_TYPE_INDIRECTLY_2: Option<Type> = None;
165 }