Skip to content

Commit 0ff115c

Browse files
Rollup merge of #37040 - flodiebold:hash-tests, r=michaelwoerister
Incr. comp. hash tests for consts and statics Hi, These two commits fix #37000 and #37001. r? @michaelwoerister
2 parents 97e9eac + eb07a6c commit 0ff115c

File tree

2 files changed

+317
-0
lines changed

2 files changed

+317
-0
lines changed

src/test/incremental/hashes/consts.rs

Lines changed: 132 additions & 0 deletions
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+
}
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
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_dirty(label="Hir", cfg="cfail2")]
36+
#[rustc_clean(label="Hir", 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_dirty(label="Hir", cfg="cfail2")]
48+
#[rustc_clean(label="Hir", 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_dirty(label="Hir", cfg="cfail2")]
60+
#[rustc_clean(label="Hir", 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_dirty(label="Hir", cfg="cfail2")]
73+
#[rustc_clean(label="Hir", 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_dirty(label="Hir", cfg="cfail2")]
86+
#[rustc_clean(label="Hir", 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_dirty(label="Hir", cfg="cfail2")]
99+
#[rustc_clean(label="Hir", 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_dirty(label="Hir", cfg="cfail2")]
111+
#[rustc_clean(label="Hir", 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+
#[cfg(cfail1)]
119+
static STATIC_CHANGE_VALUE_1: i16 = 1;
120+
121+
#[cfg(not(cfail1))]
122+
#[rustc_dirty(label="Hir", cfg="cfail2")]
123+
#[rustc_clean(label="Hir", cfg="cfail3")]
124+
#[rustc_metadata_dirty(cfg="cfail2")]
125+
#[rustc_metadata_clean(cfg="cfail3")]
126+
static STATIC_CHANGE_VALUE_1: i16 = 2;
127+
128+
129+
// Change value between expressions -------------------------------------------
130+
#[cfg(cfail1)]
131+
static STATIC_CHANGE_VALUE_2: i16 = 1 + 1;
132+
133+
#[cfg(not(cfail1))]
134+
#[rustc_dirty(label="Hir", cfg="cfail2")]
135+
#[rustc_clean(label="Hir", cfg="cfail3")]
136+
#[rustc_metadata_dirty(cfg="cfail2")]
137+
#[rustc_metadata_clean(cfg="cfail3")]
138+
static STATIC_CHANGE_VALUE_2: i16 = 1 + 2;
139+
140+
141+
#[cfg(cfail1)]
142+
static STATIC_CHANGE_VALUE_3: i16 = 2 + 3;
143+
144+
#[cfg(not(cfail1))]
145+
#[rustc_dirty(label="Hir", cfg="cfail2")]
146+
#[rustc_clean(label="Hir", cfg="cfail3")]
147+
#[rustc_metadata_dirty(cfg="cfail2")]
148+
#[rustc_metadata_clean(cfg="cfail3")]
149+
static STATIC_CHANGE_VALUE_3: i16 = 2 * 3;
150+
151+
152+
#[cfg(cfail1)]
153+
static STATIC_CHANGE_VALUE_4: i16 = 1 + 2 * 3;
154+
155+
#[cfg(not(cfail1))]
156+
#[rustc_dirty(label="Hir", cfg="cfail2")]
157+
#[rustc_clean(label="Hir", cfg="cfail3")]
158+
#[rustc_metadata_dirty(cfg="cfail2")]
159+
#[rustc_metadata_clean(cfg="cfail3")]
160+
static STATIC_CHANGE_VALUE_4: i16 = 1 + 2 * 4;
161+
162+
163+
// Change type indirectly -----------------------------------------------------
164+
struct ReferencedType1;
165+
struct ReferencedType2;
166+
167+
mod static_change_type_indirectly {
168+
#[cfg(cfail1)]
169+
use super::ReferencedType1 as Type;
170+
171+
#[cfg(not(cfail1))]
172+
use super::ReferencedType2 as Type;
173+
174+
#[rustc_dirty(label="Hir", cfg="cfail2")]
175+
#[rustc_clean(label="Hir", cfg="cfail3")]
176+
#[rustc_metadata_dirty(cfg="cfail2")]
177+
#[rustc_metadata_clean(cfg="cfail3")]
178+
static STATIC_CHANGE_TYPE_INDIRECTLY_1: Type = Type;
179+
180+
#[rustc_dirty(label="Hir", cfg="cfail2")]
181+
#[rustc_clean(label="Hir", cfg="cfail3")]
182+
#[rustc_metadata_dirty(cfg="cfail2")]
183+
#[rustc_metadata_clean(cfg="cfail3")]
184+
static STATIC_CHANGE_TYPE_INDIRECTLY_2: Option<Type> = None;
185+
}

0 commit comments

Comments
 (0)