Skip to content

Commit eb07a6c

Browse files
committed
Add ICH test case for consts
Fixes #37000.
1 parent 5a30f0c commit eb07a6c

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

src/test/incremental/hashes/consts.rs

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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+
// must-compile-successfully
20+
// revisions: cfail1 cfail2 cfail3
21+
// compile-flags: -Z query-dep-graph
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_dirty(label="Hir", cfg="cfail2")]
34+
#[rustc_clean(label="Hir", cfg="cfail3")]
35+
#[rustc_metadata_dirty(cfg="cfail2")]
36+
#[rustc_metadata_clean(cfg="cfail3")]
37+
pub const CONST_VISIBILITY: u8 = 0;
38+
39+
40+
// Change type from i32 to u32 ------------------------------------------------
41+
#[cfg(cfail1)]
42+
const CONST_CHANGE_TYPE_1: i32 = 0;
43+
44+
#[cfg(not(cfail1))]
45+
#[rustc_dirty(label="Hir", cfg="cfail2")]
46+
#[rustc_clean(label="Hir", cfg="cfail3")]
47+
#[rustc_metadata_dirty(cfg="cfail2")]
48+
#[rustc_metadata_clean(cfg="cfail3")]
49+
const CONST_CHANGE_TYPE_1: u32 = 0;
50+
51+
52+
// Change type from Option<u32> to Option<u64> --------------------------------
53+
#[cfg(cfail1)]
54+
const CONST_CHANGE_TYPE_2: Option<u32> = None;
55+
56+
#[cfg(not(cfail1))]
57+
#[rustc_dirty(label="Hir", cfg="cfail2")]
58+
#[rustc_clean(label="Hir", cfg="cfail3")]
59+
#[rustc_metadata_dirty(cfg="cfail2")]
60+
#[rustc_metadata_clean(cfg="cfail3")]
61+
const CONST_CHANGE_TYPE_2: Option<u64> = None;
62+
63+
64+
// Change value between simple literals ---------------------------------------
65+
#[cfg(cfail1)]
66+
const CONST_CHANGE_VALUE_1: i16 = 1;
67+
68+
#[cfg(not(cfail1))]
69+
#[rustc_dirty(label="Hir", cfg="cfail2")]
70+
#[rustc_clean(label="Hir", cfg="cfail3")]
71+
#[rustc_metadata_dirty(cfg="cfail2")]
72+
#[rustc_metadata_clean(cfg="cfail3")]
73+
const CONST_CHANGE_VALUE_1: i16 = 2;
74+
75+
76+
// Change value between expressions -------------------------------------------
77+
#[cfg(cfail1)]
78+
const CONST_CHANGE_VALUE_2: i16 = 1 + 1;
79+
80+
#[cfg(not(cfail1))]
81+
#[rustc_dirty(label="Hir", cfg="cfail2")]
82+
#[rustc_clean(label="Hir", cfg="cfail3")]
83+
#[rustc_metadata_dirty(cfg="cfail2")]
84+
#[rustc_metadata_clean(cfg="cfail3")]
85+
const CONST_CHANGE_VALUE_2: i16 = 1 + 2;
86+
87+
88+
#[cfg(cfail1)]
89+
const CONST_CHANGE_VALUE_3: i16 = 2 + 3;
90+
91+
#[cfg(not(cfail1))]
92+
#[rustc_dirty(label="Hir", cfg="cfail2")]
93+
#[rustc_clean(label="Hir", cfg="cfail3")]
94+
#[rustc_metadata_dirty(cfg="cfail2")]
95+
#[rustc_metadata_clean(cfg="cfail3")]
96+
const CONST_CHANGE_VALUE_3: i16 = 2 * 3;
97+
98+
99+
#[cfg(cfail1)]
100+
const CONST_CHANGE_VALUE_4: i16 = 1 + 2 * 3;
101+
102+
#[cfg(not(cfail1))]
103+
#[rustc_dirty(label="Hir", cfg="cfail2")]
104+
#[rustc_clean(label="Hir", cfg="cfail3")]
105+
#[rustc_metadata_dirty(cfg="cfail2")]
106+
#[rustc_metadata_clean(cfg="cfail3")]
107+
const CONST_CHANGE_VALUE_4: i16 = 1 + 2 * 4;
108+
109+
110+
// Change type indirectly -----------------------------------------------------
111+
struct ReferencedType1;
112+
struct ReferencedType2;
113+
114+
mod const_change_type_indirectly {
115+
#[cfg(cfail1)]
116+
use super::ReferencedType1 as Type;
117+
118+
#[cfg(not(cfail1))]
119+
use super::ReferencedType2 as Type;
120+
121+
#[rustc_dirty(label="Hir", cfg="cfail2")]
122+
#[rustc_clean(label="Hir", cfg="cfail3")]
123+
#[rustc_metadata_dirty(cfg="cfail2")]
124+
#[rustc_metadata_clean(cfg="cfail3")]
125+
const CONST_CHANGE_TYPE_INDIRECTLY_1: Type = Type;
126+
127+
#[rustc_dirty(label="Hir", cfg="cfail2")]
128+
#[rustc_clean(label="Hir", cfg="cfail3")]
129+
#[rustc_metadata_dirty(cfg="cfail2")]
130+
#[rustc_metadata_clean(cfg="cfail3")]
131+
const CONST_CHANGE_TYPE_INDIRECTLY_2: Option<Type> = None;
132+
}

0 commit comments

Comments
 (0)