@@ -19,6 +19,7 @@ use rustc_span::symbol::sym;
19
19
use rustc_span:: SourceFileHashAlgorithm ;
20
20
use rustc_target:: spec:: { CodeModel , LinkerFlavor , MergeFunctions , PanicStrategy } ;
21
21
use rustc_target:: spec:: { RelocModel , RelroLevel , SanitizerSet , SplitDebuginfo , TlsModel } ;
22
+
22
23
use std:: collections:: { BTreeMap , BTreeSet } ;
23
24
use std:: iter:: FromIterator ;
24
25
use std:: num:: NonZeroUsize ;
@@ -74,6 +75,27 @@ fn mk_map<K: Ord, V>(entries: Vec<(K, V)>) -> BTreeMap<K, V> {
74
75
BTreeMap :: from_iter ( entries. into_iter ( ) )
75
76
}
76
77
78
+ fn assert_same_clone ( x : & Options ) {
79
+ assert_eq ! ( x. dep_tracking_hash( true ) , x. clone( ) . dep_tracking_hash( true ) ) ;
80
+ assert_eq ! ( x. dep_tracking_hash( false ) , x. clone( ) . dep_tracking_hash( false ) ) ;
81
+ }
82
+
83
+ fn assert_same_hash ( x : & Options , y : & Options ) {
84
+ assert_eq ! ( x. dep_tracking_hash( true ) , y. dep_tracking_hash( true ) ) ;
85
+ assert_eq ! ( x. dep_tracking_hash( false ) , y. dep_tracking_hash( false ) ) ;
86
+ // Check clone
87
+ assert_same_clone ( x) ;
88
+ assert_same_clone ( y) ;
89
+ }
90
+
91
+ fn assert_different_hash ( x : & Options , y : & Options ) {
92
+ assert_ne ! ( x. dep_tracking_hash( true ) , y. dep_tracking_hash( true ) ) ;
93
+ assert_ne ! ( x. dep_tracking_hash( false ) , y. dep_tracking_hash( false ) ) ;
94
+ // Check clone
95
+ assert_same_clone ( x) ;
96
+ assert_same_clone ( y) ;
97
+ }
98
+
77
99
// When the user supplies --test we should implicitly supply --cfg test
78
100
#[ test]
79
101
fn test_switch_implies_cfg_test ( ) {
@@ -130,14 +152,9 @@ fn test_output_types_tracking_hash_different_paths() {
130
152
v2. output_types = OutputTypes :: new ( & [ ( OutputType :: Exe , Some ( PathBuf :: from ( "/some/thing" ) ) ) ] ) ;
131
153
v3. output_types = OutputTypes :: new ( & [ ( OutputType :: Exe , None ) ] ) ;
132
154
133
- assert ! ( v1. dep_tracking_hash( ) != v2. dep_tracking_hash( ) ) ;
134
- assert ! ( v1. dep_tracking_hash( ) != v3. dep_tracking_hash( ) ) ;
135
- assert ! ( v2. dep_tracking_hash( ) != v3. dep_tracking_hash( ) ) ;
136
-
137
- // Check clone
138
- assert_eq ! ( v1. dep_tracking_hash( ) , v1. clone( ) . dep_tracking_hash( ) ) ;
139
- assert_eq ! ( v2. dep_tracking_hash( ) , v2. clone( ) . dep_tracking_hash( ) ) ;
140
- assert_eq ! ( v3. dep_tracking_hash( ) , v3. clone( ) . dep_tracking_hash( ) ) ;
155
+ assert_different_hash ( & v1, & v2) ;
156
+ assert_different_hash ( & v1, & v3) ;
157
+ assert_different_hash ( & v2, & v3) ;
141
158
}
142
159
143
160
#[ test]
@@ -155,10 +172,7 @@ fn test_output_types_tracking_hash_different_construction_order() {
155
172
( OutputType :: Exe , Some ( PathBuf :: from ( "./some/thing" ) ) ) ,
156
173
] ) ;
157
174
158
- assert_eq ! ( v1. dep_tracking_hash( ) , v2. dep_tracking_hash( ) ) ;
159
-
160
- // Check clone
161
- assert_eq ! ( v1. dep_tracking_hash( ) , v1. clone( ) . dep_tracking_hash( ) ) ;
175
+ assert_same_hash ( & v1, & v2) ;
162
176
}
163
177
164
178
#[ test]
@@ -182,14 +196,9 @@ fn test_externs_tracking_hash_different_construction_order() {
182
196
( String :: from( "d" ) , new_public_extern_entry( vec![ "f" , "e" ] ) ) ,
183
197
] ) ) ;
184
198
185
- assert_eq ! ( v1. dep_tracking_hash( ) , v2. dep_tracking_hash( ) ) ;
186
- assert_eq ! ( v1. dep_tracking_hash( ) , v3. dep_tracking_hash( ) ) ;
187
- assert_eq ! ( v2. dep_tracking_hash( ) , v3. dep_tracking_hash( ) ) ;
188
-
189
- // Check clone
190
- assert_eq ! ( v1. dep_tracking_hash( ) , v1. clone( ) . dep_tracking_hash( ) ) ;
191
- assert_eq ! ( v2. dep_tracking_hash( ) , v2. clone( ) . dep_tracking_hash( ) ) ;
192
- assert_eq ! ( v3. dep_tracking_hash( ) , v3. clone( ) . dep_tracking_hash( ) ) ;
199
+ assert_same_hash ( & v1, & v2) ;
200
+ assert_same_hash ( & v1, & v3) ;
201
+ assert_same_hash ( & v2, & v3) ;
193
202
}
194
203
195
204
#[ test]
@@ -219,14 +228,9 @@ fn test_lints_tracking_hash_different_values() {
219
228
( String :: from( "d" ) , Level :: Deny ) ,
220
229
] ;
221
230
222
- assert ! ( v1. dep_tracking_hash( ) != v2. dep_tracking_hash( ) ) ;
223
- assert ! ( v1. dep_tracking_hash( ) != v3. dep_tracking_hash( ) ) ;
224
- assert ! ( v2. dep_tracking_hash( ) != v3. dep_tracking_hash( ) ) ;
225
-
226
- // Check clone
227
- assert_eq ! ( v1. dep_tracking_hash( ) , v1. clone( ) . dep_tracking_hash( ) ) ;
228
- assert_eq ! ( v2. dep_tracking_hash( ) , v2. clone( ) . dep_tracking_hash( ) ) ;
229
- assert_eq ! ( v3. dep_tracking_hash( ) , v3. clone( ) . dep_tracking_hash( ) ) ;
231
+ assert_different_hash ( & v1, & v2) ;
232
+ assert_different_hash ( & v1, & v3) ;
233
+ assert_different_hash ( & v2, & v3) ;
230
234
}
231
235
232
236
#[ test]
@@ -248,11 +252,7 @@ fn test_lints_tracking_hash_different_construction_order() {
248
252
( String :: from( "d" ) , Level :: Forbid ) ,
249
253
] ;
250
254
251
- assert_eq ! ( v1. dep_tracking_hash( ) , v2. dep_tracking_hash( ) ) ;
252
-
253
- // Check clone
254
- assert_eq ! ( v1. dep_tracking_hash( ) , v1. clone( ) . dep_tracking_hash( ) ) ;
255
- assert_eq ! ( v2. dep_tracking_hash( ) , v2. clone( ) . dep_tracking_hash( ) ) ;
255
+ assert_same_hash ( & v1, & v2) ;
256
256
}
257
257
258
258
#[ test]
@@ -292,15 +292,9 @@ fn test_search_paths_tracking_hash_different_order() {
292
292
v4. search_paths . push ( SearchPath :: from_cli_opt ( "dependency=ghi" , JSON ) ) ;
293
293
v4. search_paths . push ( SearchPath :: from_cli_opt ( "framework=jkl" , JSON ) ) ;
294
294
295
- assert ! ( v1. dep_tracking_hash( ) == v2. dep_tracking_hash( ) ) ;
296
- assert ! ( v1. dep_tracking_hash( ) == v3. dep_tracking_hash( ) ) ;
297
- assert ! ( v1. dep_tracking_hash( ) == v4. dep_tracking_hash( ) ) ;
298
-
299
- // Check clone
300
- assert_eq ! ( v1. dep_tracking_hash( ) , v1. clone( ) . dep_tracking_hash( ) ) ;
301
- assert_eq ! ( v2. dep_tracking_hash( ) , v2. clone( ) . dep_tracking_hash( ) ) ;
302
- assert_eq ! ( v3. dep_tracking_hash( ) , v3. clone( ) . dep_tracking_hash( ) ) ;
303
- assert_eq ! ( v4. dep_tracking_hash( ) , v4. clone( ) . dep_tracking_hash( ) ) ;
295
+ assert_same_hash ( & v1, & v2) ;
296
+ assert_same_hash ( & v1, & v3) ;
297
+ assert_same_hash ( & v1, & v4) ;
304
298
}
305
299
306
300
#[ test]
@@ -338,15 +332,9 @@ fn test_native_libs_tracking_hash_different_values() {
338
332
( String :: from( "c" ) , None , NativeLibKind :: Unspecified ) ,
339
333
] ;
340
334
341
- assert ! ( v1. dep_tracking_hash( ) != v2. dep_tracking_hash( ) ) ;
342
- assert ! ( v1. dep_tracking_hash( ) != v3. dep_tracking_hash( ) ) ;
343
- assert ! ( v1. dep_tracking_hash( ) != v4. dep_tracking_hash( ) ) ;
344
-
345
- // Check clone
346
- assert_eq ! ( v1. dep_tracking_hash( ) , v1. clone( ) . dep_tracking_hash( ) ) ;
347
- assert_eq ! ( v2. dep_tracking_hash( ) , v2. clone( ) . dep_tracking_hash( ) ) ;
348
- assert_eq ! ( v3. dep_tracking_hash( ) , v3. clone( ) . dep_tracking_hash( ) ) ;
349
- assert_eq ! ( v4. dep_tracking_hash( ) , v4. clone( ) . dep_tracking_hash( ) ) ;
335
+ assert_different_hash ( & v1, & v2) ;
336
+ assert_different_hash ( & v1, & v3) ;
337
+ assert_different_hash ( & v1, & v4) ;
350
338
}
351
339
352
340
#[ test]
@@ -374,14 +362,9 @@ fn test_native_libs_tracking_hash_different_order() {
374
362
( String :: from( "b" ) , None , NativeLibKind :: Framework ) ,
375
363
] ;
376
364
377
- assert ! ( v1. dep_tracking_hash( ) == v2. dep_tracking_hash( ) ) ;
378
- assert ! ( v1. dep_tracking_hash( ) == v3. dep_tracking_hash( ) ) ;
379
- assert ! ( v2. dep_tracking_hash( ) == v3. dep_tracking_hash( ) ) ;
380
-
381
- // Check clone
382
- assert_eq ! ( v1. dep_tracking_hash( ) , v1. clone( ) . dep_tracking_hash( ) ) ;
383
- assert_eq ! ( v2. dep_tracking_hash( ) , v2. clone( ) . dep_tracking_hash( ) ) ;
384
- assert_eq ! ( v3. dep_tracking_hash( ) , v3. clone( ) . dep_tracking_hash( ) ) ;
365
+ assert_same_hash ( & v1, & v2) ;
366
+ assert_same_hash ( & v1, & v3) ;
367
+ assert_same_hash ( & v2, & v3) ;
385
368
}
386
369
387
370
#[ test]
@@ -393,7 +376,7 @@ fn test_codegen_options_tracking_hash() {
393
376
( $name: ident, $non_default_value: expr) => {
394
377
assert_ne!( opts. cg. $name, $non_default_value) ;
395
378
opts. cg. $name = $non_default_value;
396
- assert_eq! ( reference. dep_tracking_hash ( ) , opts. dep_tracking_hash ( ) ) ;
379
+ assert_same_hash ( & reference, & opts) ;
397
380
} ;
398
381
}
399
382
@@ -419,7 +402,7 @@ fn test_codegen_options_tracking_hash() {
419
402
opts = reference. clone( ) ;
420
403
assert_ne!( opts. cg. $name, $non_default_value) ;
421
404
opts. cg. $name = $non_default_value;
422
- assert_ne! ( reference. dep_tracking_hash ( ) , opts. dep_tracking_hash ( ) ) ;
405
+ assert_different_hash ( & reference, & opts) ;
423
406
} ;
424
407
}
425
408
@@ -456,6 +439,28 @@ fn test_codegen_options_tracking_hash() {
456
439
tracked ! ( target_feature, String :: from( "all the features, all of them" ) ) ;
457
440
}
458
441
442
+ #[ test]
443
+ fn test_top_level_options_tracked_no_crate ( ) {
444
+ let reference = Options :: default ( ) ;
445
+ let mut opts;
446
+
447
+ macro_rules! tracked {
448
+ ( $name: ident, $non_default_value: expr) => {
449
+ opts = reference. clone( ) ;
450
+ assert_ne!( opts. $name, $non_default_value) ;
451
+ opts. $name = $non_default_value;
452
+ // The crate hash should be the same
453
+ assert_eq!( reference. dep_tracking_hash( true ) , opts. dep_tracking_hash( true ) ) ;
454
+ // The incremental hash should be different
455
+ assert_ne!( reference. dep_tracking_hash( false ) , opts. dep_tracking_hash( false ) ) ;
456
+ } ;
457
+ }
458
+
459
+ // Make sure that changing a [TRACKED_NO_CRATE_HASH] option leaves the crate hash unchanged but changes the incremental hash.
460
+ // This list is in alphabetical order.
461
+ tracked ! ( remap_path_prefix, vec![ ( "/home/bors/rust" . into( ) , "src" . into( ) ) ] ) ;
462
+ }
463
+
459
464
#[ test]
460
465
fn test_debugging_options_tracking_hash ( ) {
461
466
let reference = Options :: default ( ) ;
@@ -465,7 +470,7 @@ fn test_debugging_options_tracking_hash() {
465
470
( $name: ident, $non_default_value: expr) => {
466
471
assert_ne!( opts. debugging_opts. $name, $non_default_value) ;
467
472
opts. debugging_opts. $name = $non_default_value;
468
- assert_eq! ( reference. dep_tracking_hash ( ) , opts. dep_tracking_hash ( ) ) ;
473
+ assert_same_hash ( & reference, & opts) ;
469
474
} ;
470
475
}
471
476
@@ -537,7 +542,7 @@ fn test_debugging_options_tracking_hash() {
537
542
opts = reference. clone( ) ;
538
543
assert_ne!( opts. debugging_opts. $name, $non_default_value) ;
539
544
opts. debugging_opts. $name = $non_default_value;
540
- assert_ne! ( reference. dep_tracking_hash ( ) , opts. dep_tracking_hash ( ) ) ;
545
+ assert_different_hash ( & reference, & opts) ;
541
546
} ;
542
547
}
543
548
0 commit comments