]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hashes/consts.rs
Rollup merge of #49858 - dmizuk:unique-doc-hidden, r=steveklabnik
[rust.git] / src / test / incremental / hashes / consts.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 consts.
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 // compile-pass
20 // revisions: cfail1 cfail2 cfail3
21 // compile-flags: -Z query-dep-graph -Zincremental-ignore-spans
22
23 #![allow(warnings)]
24 #![feature(rustc_attrs)]
25 #![crate_type="rlib"]
26
27
28 // Change const visibility ---------------------------------------------------
29 #[cfg(cfail1)]
30 const CONST_VISIBILITY: u8 = 0;
31
32 #[cfg(not(cfail1))]
33 #[rustc_clean(cfg="cfail2", except="Hir,HirBody")]
34 #[rustc_clean(cfg="cfail3")]
35 pub const CONST_VISIBILITY: u8 = 0;
36
37
38 // Change type from i32 to u32 ------------------------------------------------
39 #[cfg(cfail1)]
40 const CONST_CHANGE_TYPE_1: i32 = 0;
41
42 #[cfg(not(cfail1))]
43 #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")]
44 #[rustc_clean(cfg="cfail3")]
45 const CONST_CHANGE_TYPE_1: u32 = 0;
46
47
48 // Change type from Option<u32> to Option<u64> --------------------------------
49 #[cfg(cfail1)]
50 const CONST_CHANGE_TYPE_2: Option<u32> = None;
51
52 #[cfg(not(cfail1))]
53 #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")]
54 #[rustc_clean(cfg="cfail3")]
55 const CONST_CHANGE_TYPE_2: Option<u64> = None;
56
57
58 // Change value between simple literals ---------------------------------------
59 #[rustc_clean(cfg="cfail2", except="HirBody")]
60 #[rustc_clean(cfg="cfail3")]
61 const CONST_CHANGE_VALUE_1: i16 = {
62     #[cfg(cfail1)]
63     { 1 }
64
65     #[cfg(not(cfail1))]
66     { 2 }
67 };
68
69
70 // Change value between expressions -------------------------------------------
71 #[rustc_clean(cfg="cfail2", except="HirBody")]
72 #[rustc_clean(cfg="cfail3")]
73 const CONST_CHANGE_VALUE_2: i16 = {
74     #[cfg(cfail1)]
75     { 1 + 1 }
76
77     #[cfg(not(cfail1))]
78     { 1 + 2 }
79 };
80
81 #[rustc_clean(cfg="cfail2", except="HirBody")]
82 #[rustc_clean(cfg="cfail3")]
83 const CONST_CHANGE_VALUE_3: i16 = {
84     #[cfg(cfail1)]
85     { 2 + 3 }
86
87     #[cfg(not(cfail1))]
88     { 2 * 3 }
89 };
90
91 #[rustc_clean(cfg="cfail2", except="HirBody")]
92 #[rustc_clean(cfg="cfail3")]
93 const CONST_CHANGE_VALUE_4: i16 = {
94     #[cfg(cfail1)]
95     { 1 + 2 * 3 }
96
97     #[cfg(not(cfail1))]
98     { 1 + 2 * 4 }
99 };
100
101
102 // Change type indirectly -----------------------------------------------------
103 struct ReferencedType1;
104 struct ReferencedType2;
105
106 mod const_change_type_indirectly {
107     #[cfg(cfail1)]
108     use super::ReferencedType1 as Type;
109
110     #[cfg(not(cfail1))]
111     use super::ReferencedType2 as Type;
112
113     #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")]
114     #[rustc_clean(cfg="cfail3")]
115     const CONST_CHANGE_TYPE_INDIRECTLY_1: Type = Type;
116
117     #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")]
118     #[rustc_clean(cfg="cfail3")]
119     const CONST_CHANGE_TYPE_INDIRECTLY_2: Option<Type> = None;
120 }