]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_interface/src/tests.rs
New upstream version 1.60.0+dfsg1
[rustc.git] / compiler / rustc_interface / src / tests.rs
CommitLineData
e74abb32
XL
1use crate::interface::parse_cfgspecs;
2
dfeec247
XL
3use rustc_data_structures::fx::FxHashSet;
4use rustc_errors::{emitter::HumanReadableErrorType, registry, ColorConfig};
cdc7bbd5 5use rustc_session::config::InstrumentCoverage;
f9f354fc 6use rustc_session::config::Strip;
ba9703b0 7use rustc_session::config::{build_configuration, build_session_options, to_crate_config};
3c0e092e
XL
8use rustc_session::config::{
9 rustc_optgroups, ErrorOutputType, ExternLocation, LocationDetail, Options, Passes,
10};
f035d41b 11use rustc_session::config::{
5099ac24
FG
12 BranchProtection, Externs, OutputType, OutputTypes, PAuthKey, PacRet, SymbolManglingVersion,
13 WasiExecModel,
f035d41b 14};
5099ac24 15use rustc_session::config::{CFGuard, ExternEntry, LinkerPluginLto, LtoCli, SwitchWithOptPath};
ba9703b0
XL
16use rustc_session::lint::Level;
17use rustc_session::search_paths::SearchPath;
17df50a5 18use rustc_session::utils::{CanonicalizedPath, NativeLib, NativeLibKind};
f9f354fc 19use rustc_session::{build_session, getopts, DiagnosticOutput, Session};
dfeec247
XL
20use rustc_span::edition::{Edition, DEFAULT_EDITION};
21use rustc_span::symbol::sym;
f9f354fc
XL
22use rustc_span::SourceFileHashAlgorithm;
23use rustc_target::spec::{CodeModel, LinkerFlavor, MergeFunctions, PanicStrategy};
3c0e092e
XL
24use rustc_target::spec::{
25 RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel,
26};
cdc7bbd5 27
dc9dc135
XL
28use std::collections::{BTreeMap, BTreeSet};
29use std::iter::FromIterator;
6a06907d 30use std::num::NonZeroUsize;
5869c6ff 31use std::path::{Path, PathBuf};
e74abb32 32
60c5eb7d
XL
33type CfgSpecs = FxHashSet<(String, Option<String>)>;
34
35fn build_session_options_and_crate_config(matches: getopts::Matches) -> (Options, CfgSpecs) {
36 let sessopts = build_session_options(&matches);
37 let cfg = parse_cfgspecs(matches.opt_strs("cfg"));
38 (sessopts, cfg)
39}
40
41fn mk_session(matches: getopts::Matches) -> (Session, CfgSpecs) {
42 let registry = registry::Registry::new(&[]);
43 let (sessopts, cfg) = build_session_options_and_crate_config(matches);
f9f354fc
XL
44 let sess = build_session(
45 sessopts,
46 None,
47 registry,
48 DiagnosticOutput::Default,
49 Default::default(),
50 None,
1b1a35ee 51 None,
f9f354fc 52 );
60c5eb7d 53 (sess, cfg)
e74abb32
XL
54}
55
56fn new_public_extern_entry<S, I>(locations: I) -> ExternEntry
57where
58 S: Into<String>,
60c5eb7d 59 I: IntoIterator<Item = S>,
e74abb32 60{
5869c6ff
XL
61 let locations: BTreeSet<CanonicalizedPath> =
62 locations.into_iter().map(|s| CanonicalizedPath::new(Path::new(&s.into()))).collect();
e74abb32
XL
63
64 ExternEntry {
60c5eb7d
XL
65 location: ExternLocation::ExactPaths(locations),
66 is_private_dep: false,
67 add_prelude: true,
dc9dc135
XL
68 }
69}
70
71fn optgroups() -> getopts::Options {
72 let mut opts = getopts::Options::new();
e74abb32 73 for group in rustc_optgroups() {
dc9dc135
XL
74 (group.apply)(&mut opts);
75 }
76 return opts;
77}
78
79fn mk_map<K: Ord, V>(entries: Vec<(K, V)>) -> BTreeMap<K, V> {
80 BTreeMap::from_iter(entries.into_iter())
81}
82
cdc7bbd5
XL
83fn assert_same_clone(x: &Options) {
84 assert_eq!(x.dep_tracking_hash(true), x.clone().dep_tracking_hash(true));
85 assert_eq!(x.dep_tracking_hash(false), x.clone().dep_tracking_hash(false));
86}
87
88fn assert_same_hash(x: &Options, y: &Options) {
89 assert_eq!(x.dep_tracking_hash(true), y.dep_tracking_hash(true));
90 assert_eq!(x.dep_tracking_hash(false), y.dep_tracking_hash(false));
91 // Check clone
92 assert_same_clone(x);
93 assert_same_clone(y);
94}
95
96fn assert_different_hash(x: &Options, y: &Options) {
97 assert_ne!(x.dep_tracking_hash(true), y.dep_tracking_hash(true));
98 assert_ne!(x.dep_tracking_hash(false), y.dep_tracking_hash(false));
99 // Check clone
100 assert_same_clone(x);
101 assert_same_clone(y);
102}
103
136023e0
XL
104fn assert_non_crate_hash_different(x: &Options, y: &Options) {
105 assert_eq!(x.dep_tracking_hash(true), y.dep_tracking_hash(true));
106 assert_ne!(x.dep_tracking_hash(false), y.dep_tracking_hash(false));
107 // Check clone
108 assert_same_clone(x);
109 assert_same_clone(y);
110}
111
dc9dc135
XL
112// When the user supplies --test we should implicitly supply --cfg test
113#[test]
114fn test_switch_implies_cfg_test() {
136023e0 115 rustc_span::create_default_session_globals_then(|| {
60c5eb7d
XL
116 let matches = optgroups().parse(&["--test".to_string()]).unwrap();
117 let (sess, cfg) = mk_session(matches);
dc9dc135
XL
118 let cfg = build_configuration(&sess, to_crate_config(cfg));
119 assert!(cfg.contains(&(sym::test, None)));
120 });
121}
122
60c5eb7d 123// When the user supplies --test and --cfg test, don't implicitly add another --cfg test
dc9dc135
XL
124#[test]
125fn test_switch_implies_cfg_test_unless_cfg_test() {
136023e0 126 rustc_span::create_default_session_globals_then(|| {
60c5eb7d
XL
127 let matches = optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]).unwrap();
128 let (sess, cfg) = mk_session(matches);
dc9dc135
XL
129 let cfg = build_configuration(&sess, to_crate_config(cfg));
130 let mut test_items = cfg.iter().filter(|&&(name, _)| name == sym::test);
131 assert!(test_items.next().is_some());
132 assert!(test_items.next().is_none());
133 });
134}
135
136#[test]
137fn test_can_print_warnings() {
136023e0 138 rustc_span::create_default_session_globals_then(|| {
dc9dc135 139 let matches = optgroups().parse(&["-Awarnings".to_string()]).unwrap();
60c5eb7d 140 let (sess, _) = mk_session(matches);
e1599b0c 141 assert!(!sess.diagnostic().can_emit_warnings());
dc9dc135
XL
142 });
143
136023e0 144 rustc_span::create_default_session_globals_then(|| {
dfeec247
XL
145 let matches =
146 optgroups().parse(&["-Awarnings".to_string(), "-Dwarnings".to_string()]).unwrap();
60c5eb7d 147 let (sess, _) = mk_session(matches);
e1599b0c 148 assert!(sess.diagnostic().can_emit_warnings());
dc9dc135
XL
149 });
150
136023e0 151 rustc_span::create_default_session_globals_then(|| {
dc9dc135 152 let matches = optgroups().parse(&["-Adead_code".to_string()]).unwrap();
60c5eb7d 153 let (sess, _) = mk_session(matches);
e1599b0c 154 assert!(sess.diagnostic().can_emit_warnings());
dc9dc135
XL
155 });
156}
157
158#[test]
159fn test_output_types_tracking_hash_different_paths() {
160 let mut v1 = Options::default();
161 let mut v2 = Options::default();
162 let mut v3 = Options::default();
163
dfeec247
XL
164 v1.output_types = OutputTypes::new(&[(OutputType::Exe, Some(PathBuf::from("./some/thing")))]);
165 v2.output_types = OutputTypes::new(&[(OutputType::Exe, Some(PathBuf::from("/some/thing")))]);
dc9dc135
XL
166 v3.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
167
136023e0
XL
168 assert_non_crate_hash_different(&v1, &v2);
169 assert_non_crate_hash_different(&v1, &v3);
170 assert_non_crate_hash_different(&v2, &v3);
dc9dc135
XL
171}
172
173#[test]
174fn test_output_types_tracking_hash_different_construction_order() {
175 let mut v1 = Options::default();
176 let mut v2 = Options::default();
177
178 v1.output_types = OutputTypes::new(&[
179 (OutputType::Exe, Some(PathBuf::from("./some/thing"))),
180 (OutputType::Bitcode, Some(PathBuf::from("./some/thing.bc"))),
181 ]);
182
183 v2.output_types = OutputTypes::new(&[
184 (OutputType::Bitcode, Some(PathBuf::from("./some/thing.bc"))),
185 (OutputType::Exe, Some(PathBuf::from("./some/thing"))),
186 ]);
187
cdc7bbd5 188 assert_same_hash(&v1, &v2);
dc9dc135
XL
189}
190
191#[test]
192fn test_externs_tracking_hash_different_construction_order() {
193 let mut v1 = Options::default();
194 let mut v2 = Options::default();
195 let mut v3 = Options::default();
196
197 v1.externs = Externs::new(mk_map(vec![
dfeec247
XL
198 (String::from("a"), new_public_extern_entry(vec!["b", "c"])),
199 (String::from("d"), new_public_extern_entry(vec!["e", "f"])),
dc9dc135
XL
200 ]));
201
202 v2.externs = Externs::new(mk_map(vec![
dfeec247
XL
203 (String::from("d"), new_public_extern_entry(vec!["e", "f"])),
204 (String::from("a"), new_public_extern_entry(vec!["b", "c"])),
dc9dc135
XL
205 ]));
206
207 v3.externs = Externs::new(mk_map(vec![
dfeec247
XL
208 (String::from("a"), new_public_extern_entry(vec!["b", "c"])),
209 (String::from("d"), new_public_extern_entry(vec!["f", "e"])),
dc9dc135
XL
210 ]));
211
cdc7bbd5
XL
212 assert_same_hash(&v1, &v2);
213 assert_same_hash(&v1, &v3);
214 assert_same_hash(&v2, &v3);
dc9dc135
XL
215}
216
217#[test]
218fn test_lints_tracking_hash_different_values() {
219 let mut v1 = Options::default();
220 let mut v2 = Options::default();
221 let mut v3 = Options::default();
222
223 v1.lint_opts = vec![
dfeec247
XL
224 (String::from("a"), Level::Allow),
225 (String::from("b"), Level::Warn),
226 (String::from("c"), Level::Deny),
227 (String::from("d"), Level::Forbid),
dc9dc135
XL
228 ];
229
230 v2.lint_opts = vec![
dfeec247
XL
231 (String::from("a"), Level::Allow),
232 (String::from("b"), Level::Warn),
233 (String::from("X"), Level::Deny),
234 (String::from("d"), Level::Forbid),
dc9dc135
XL
235 ];
236
237 v3.lint_opts = vec![
dfeec247
XL
238 (String::from("a"), Level::Allow),
239 (String::from("b"), Level::Warn),
240 (String::from("c"), Level::Forbid),
241 (String::from("d"), Level::Deny),
dc9dc135
XL
242 ];
243
136023e0
XL
244 assert_non_crate_hash_different(&v1, &v2);
245 assert_non_crate_hash_different(&v1, &v3);
246 assert_non_crate_hash_different(&v2, &v3);
dc9dc135
XL
247}
248
249#[test]
250fn test_lints_tracking_hash_different_construction_order() {
251 let mut v1 = Options::default();
252 let mut v2 = Options::default();
253
254 v1.lint_opts = vec![
dfeec247
XL
255 (String::from("a"), Level::Allow),
256 (String::from("b"), Level::Warn),
257 (String::from("c"), Level::Deny),
258 (String::from("d"), Level::Forbid),
dc9dc135
XL
259 ];
260
261 v2.lint_opts = vec![
dfeec247
XL
262 (String::from("a"), Level::Allow),
263 (String::from("c"), Level::Deny),
264 (String::from("b"), Level::Warn),
265 (String::from("d"), Level::Forbid),
dc9dc135
XL
266 ];
267
17df50a5 268 // The hash should be order-dependent
136023e0
XL
269 assert_non_crate_hash_different(&v1, &v2);
270}
271
272#[test]
273fn test_lint_cap_hash_different() {
274 let mut v1 = Options::default();
275 let mut v2 = Options::default();
276 let v3 = Options::default();
277
278 v1.lint_cap = Some(Level::Forbid);
279 v2.lint_cap = Some(Level::Allow);
280
281 assert_non_crate_hash_different(&v1, &v2);
282 assert_non_crate_hash_different(&v1, &v3);
283 assert_non_crate_hash_different(&v2, &v3);
dc9dc135
XL
284}
285
286#[test]
287fn test_search_paths_tracking_hash_different_order() {
288 let mut v1 = Options::default();
289 let mut v2 = Options::default();
290 let mut v3 = Options::default();
291 let mut v4 = Options::default();
292
e74abb32 293 const JSON: ErrorOutputType = ErrorOutputType::Json {
dc9dc135 294 pretty: false,
e74abb32 295 json_rendered: HumanReadableErrorType::Default(ColorConfig::Never),
dc9dc135
XL
296 };
297
298 // Reference
dfeec247
XL
299 v1.search_paths.push(SearchPath::from_cli_opt("native=abc", JSON));
300 v1.search_paths.push(SearchPath::from_cli_opt("crate=def", JSON));
301 v1.search_paths.push(SearchPath::from_cli_opt("dependency=ghi", JSON));
302 v1.search_paths.push(SearchPath::from_cli_opt("framework=jkl", JSON));
303 v1.search_paths.push(SearchPath::from_cli_opt("all=mno", JSON));
304
305 v2.search_paths.push(SearchPath::from_cli_opt("native=abc", JSON));
306 v2.search_paths.push(SearchPath::from_cli_opt("dependency=ghi", JSON));
307 v2.search_paths.push(SearchPath::from_cli_opt("crate=def", JSON));
308 v2.search_paths.push(SearchPath::from_cli_opt("framework=jkl", JSON));
309 v2.search_paths.push(SearchPath::from_cli_opt("all=mno", JSON));
310
311 v3.search_paths.push(SearchPath::from_cli_opt("crate=def", JSON));
312 v3.search_paths.push(SearchPath::from_cli_opt("framework=jkl", JSON));
313 v3.search_paths.push(SearchPath::from_cli_opt("native=abc", JSON));
314 v3.search_paths.push(SearchPath::from_cli_opt("dependency=ghi", JSON));
315 v3.search_paths.push(SearchPath::from_cli_opt("all=mno", JSON));
316
317 v4.search_paths.push(SearchPath::from_cli_opt("all=mno", JSON));
318 v4.search_paths.push(SearchPath::from_cli_opt("native=abc", JSON));
319 v4.search_paths.push(SearchPath::from_cli_opt("crate=def", JSON));
320 v4.search_paths.push(SearchPath::from_cli_opt("dependency=ghi", JSON));
321 v4.search_paths.push(SearchPath::from_cli_opt("framework=jkl", JSON));
dc9dc135 322
cdc7bbd5
XL
323 assert_same_hash(&v1, &v2);
324 assert_same_hash(&v1, &v3);
325 assert_same_hash(&v1, &v4);
dc9dc135
XL
326}
327
328#[test]
329fn test_native_libs_tracking_hash_different_values() {
330 let mut v1 = Options::default();
331 let mut v2 = Options::default();
332 let mut v3 = Options::default();
333 let mut v4 = Options::default();
17df50a5 334 let mut v5 = Options::default();
dc9dc135
XL
335
336 // Reference
337 v1.libs = vec![
17df50a5
XL
338 NativeLib {
339 name: String::from("a"),
340 new_name: None,
341 kind: NativeLibKind::Static { bundle: None, whole_archive: None },
342 verbatim: None,
343 },
344 NativeLib {
345 name: String::from("b"),
346 new_name: None,
347 kind: NativeLibKind::Framework { as_needed: None },
348 verbatim: None,
349 },
350 NativeLib {
351 name: String::from("c"),
352 new_name: None,
353 kind: NativeLibKind::Unspecified,
354 verbatim: None,
355 },
dc9dc135
XL
356 ];
357
358 // Change label
359 v2.libs = vec![
17df50a5
XL
360 NativeLib {
361 name: String::from("a"),
362 new_name: None,
363 kind: NativeLibKind::Static { bundle: None, whole_archive: None },
364 verbatim: None,
365 },
366 NativeLib {
367 name: String::from("X"),
368 new_name: None,
369 kind: NativeLibKind::Framework { as_needed: None },
370 verbatim: None,
371 },
372 NativeLib {
373 name: String::from("c"),
374 new_name: None,
375 kind: NativeLibKind::Unspecified,
376 verbatim: None,
377 },
dc9dc135
XL
378 ];
379
380 // Change kind
381 v3.libs = vec![
17df50a5
XL
382 NativeLib {
383 name: String::from("a"),
384 new_name: None,
385 kind: NativeLibKind::Static { bundle: None, whole_archive: None },
386 verbatim: None,
387 },
388 NativeLib {
389 name: String::from("b"),
390 new_name: None,
391 kind: NativeLibKind::Static { bundle: None, whole_archive: None },
392 verbatim: None,
393 },
394 NativeLib {
395 name: String::from("c"),
396 new_name: None,
397 kind: NativeLibKind::Unspecified,
398 verbatim: None,
399 },
dc9dc135
XL
400 ];
401
402 // Change new-name
403 v4.libs = vec![
17df50a5
XL
404 NativeLib {
405 name: String::from("a"),
406 new_name: None,
407 kind: NativeLibKind::Static { bundle: None, whole_archive: None },
408 verbatim: None,
409 },
410 NativeLib {
411 name: String::from("b"),
412 new_name: Some(String::from("X")),
413 kind: NativeLibKind::Framework { as_needed: None },
414 verbatim: None,
415 },
416 NativeLib {
417 name: String::from("c"),
418 new_name: None,
419 kind: NativeLibKind::Unspecified,
420 verbatim: None,
421 },
422 ];
423
424 // Change verbatim
425 v5.libs = vec![
426 NativeLib {
427 name: String::from("a"),
428 new_name: None,
429 kind: NativeLibKind::Static { bundle: None, whole_archive: None },
430 verbatim: None,
431 },
432 NativeLib {
433 name: String::from("b"),
434 new_name: None,
435 kind: NativeLibKind::Framework { as_needed: None },
436 verbatim: Some(true),
437 },
438 NativeLib {
439 name: String::from("c"),
440 new_name: None,
441 kind: NativeLibKind::Unspecified,
442 verbatim: None,
443 },
dc9dc135
XL
444 ];
445
cdc7bbd5
XL
446 assert_different_hash(&v1, &v2);
447 assert_different_hash(&v1, &v3);
448 assert_different_hash(&v1, &v4);
17df50a5 449 assert_different_hash(&v1, &v5);
dc9dc135
XL
450}
451
452#[test]
453fn test_native_libs_tracking_hash_different_order() {
454 let mut v1 = Options::default();
455 let mut v2 = Options::default();
456 let mut v3 = Options::default();
457
458 // Reference
459 v1.libs = vec![
17df50a5
XL
460 NativeLib {
461 name: String::from("a"),
462 new_name: None,
463 kind: NativeLibKind::Static { bundle: None, whole_archive: None },
464 verbatim: None,
465 },
466 NativeLib {
467 name: String::from("b"),
468 new_name: None,
469 kind: NativeLibKind::Framework { as_needed: None },
470 verbatim: None,
471 },
472 NativeLib {
473 name: String::from("c"),
474 new_name: None,
475 kind: NativeLibKind::Unspecified,
476 verbatim: None,
477 },
dc9dc135
XL
478 ];
479
480 v2.libs = vec![
17df50a5
XL
481 NativeLib {
482 name: String::from("b"),
483 new_name: None,
484 kind: NativeLibKind::Framework { as_needed: None },
485 verbatim: None,
486 },
487 NativeLib {
488 name: String::from("a"),
489 new_name: None,
490 kind: NativeLibKind::Static { bundle: None, whole_archive: None },
491 verbatim: None,
492 },
493 NativeLib {
494 name: String::from("c"),
495 new_name: None,
496 kind: NativeLibKind::Unspecified,
497 verbatim: None,
498 },
dc9dc135
XL
499 ];
500
501 v3.libs = vec![
17df50a5
XL
502 NativeLib {
503 name: String::from("c"),
504 new_name: None,
505 kind: NativeLibKind::Unspecified,
506 verbatim: None,
507 },
508 NativeLib {
509 name: String::from("a"),
510 new_name: None,
511 kind: NativeLibKind::Static { bundle: None, whole_archive: None },
512 verbatim: None,
513 },
514 NativeLib {
515 name: String::from("b"),
516 new_name: None,
517 kind: NativeLibKind::Framework { as_needed: None },
518 verbatim: None,
519 },
dc9dc135
XL
520 ];
521
17df50a5
XL
522 // The hash should be order-dependent
523 assert_different_hash(&v1, &v2);
524 assert_different_hash(&v1, &v3);
525 assert_different_hash(&v2, &v3);
dc9dc135
XL
526}
527
528#[test]
529fn test_codegen_options_tracking_hash() {
530 let reference = Options::default();
531 let mut opts = Options::default();
532
f9f354fc
XL
533 macro_rules! untracked {
534 ($name: ident, $non_default_value: expr) => {
cdc7bbd5 535 assert_ne!(opts.cg.$name, $non_default_value);
f9f354fc 536 opts.cg.$name = $non_default_value;
cdc7bbd5 537 assert_same_hash(&reference, &opts);
f9f354fc
XL
538 };
539 }
dc9dc135 540
f9f354fc
XL
541 // Make sure that changing an [UNTRACKED] option leaves the hash unchanged.
542 // This list is in alphabetical order.
543 untracked!(ar, String::from("abc"));
544 untracked!(codegen_units, Some(42));
545 untracked!(default_linker_libraries, true);
546 untracked!(extra_filename, String::from("extra-filename"));
547 untracked!(incremental, Some(String::from("abc")));
548 // `link_arg` is omitted because it just forwards to `link_args`.
549 untracked!(link_args, vec![String::from("abc"), String::from("def")]);
1b1a35ee 550 untracked!(link_self_contained, Some(true));
f9f354fc
XL
551 untracked!(linker, Some(PathBuf::from("linker")));
552 untracked!(linker_flavor, Some(LinkerFlavor::Gcc));
553 untracked!(no_stack_check, true);
554 untracked!(remark, Passes::Some(vec![String::from("pass1"), String::from("pass2")]));
555 untracked!(rpath, true);
556 untracked!(save_temps, true);
3c0e092e 557 untracked!(strip, Strip::Debuginfo);
f9f354fc
XL
558
559 macro_rules! tracked {
560 ($name: ident, $non_default_value: expr) => {
561 opts = reference.clone();
cdc7bbd5 562 assert_ne!(opts.cg.$name, $non_default_value);
f9f354fc 563 opts.cg.$name = $non_default_value;
cdc7bbd5 564 assert_different_hash(&reference, &opts);
f9f354fc
XL
565 };
566 }
dc9dc135 567
f9f354fc
XL
568 // Make sure that changing a [TRACKED] option changes the hash.
569 // This list is in alphabetical order.
570 tracked!(code_model, Some(CodeModel::Large));
3dfed10e 571 tracked!(control_flow_guard, CFGuard::Checks);
f9f354fc
XL
572 tracked!(debug_assertions, Some(true));
573 tracked!(debuginfo, 0xdeadbeef);
574 tracked!(embed_bitcode, false);
575 tracked!(force_frame_pointers, Some(false));
576 tracked!(force_unwind_tables, Some(true));
577 tracked!(inline_threshold, Some(0xf007ba11));
5099ac24 578 tracked!(instrument_coverage, Some(InstrumentCoverage::All));
f9f354fc 579 tracked!(linker_plugin_lto, LinkerPluginLto::LinkerPluginAuto);
cdc7bbd5 580 tracked!(link_dead_code, Some(true));
f9f354fc
XL
581 tracked!(llvm_args, vec![String::from("1"), String::from("2")]);
582 tracked!(lto, LtoCli::Fat);
583 tracked!(metadata, vec![String::from("A"), String::from("B")]);
584 tracked!(no_prepopulate_passes, true);
585 tracked!(no_redzone, Some(true));
586 tracked!(no_vectorize_loops, true);
587 tracked!(no_vectorize_slp, true);
588 tracked!(opt_level, "3".to_string());
589 tracked!(overflow_checks, Some(true));
590 tracked!(panic, Some(PanicStrategy::Abort));
591 tracked!(passes, vec![String::from("1"), String::from("2")]);
592 tracked!(prefer_dynamic, true);
593 tracked!(profile_generate, SwitchWithOptPath::Enabled(None));
594 tracked!(profile_use, Some(PathBuf::from("abc")));
595 tracked!(relocation_model, Some(RelocModel::Pic));
596 tracked!(soft_float, true);
5869c6ff 597 tracked!(split_debuginfo, Some(SplitDebuginfo::Packed));
a2a8927a 598 tracked!(symbol_mangling_version, Some(SymbolManglingVersion::V0));
f9f354fc
XL
599 tracked!(target_cpu, Some(String::from("abc")));
600 tracked!(target_feature, String::from("all the features, all of them"));
dc9dc135
XL
601}
602
cdc7bbd5
XL
603#[test]
604fn test_top_level_options_tracked_no_crate() {
605 let reference = Options::default();
606 let mut opts;
607
608 macro_rules! tracked {
609 ($name: ident, $non_default_value: expr) => {
610 opts = reference.clone();
611 assert_ne!(opts.$name, $non_default_value);
612 opts.$name = $non_default_value;
613 // The crate hash should be the same
614 assert_eq!(reference.dep_tracking_hash(true), opts.dep_tracking_hash(true));
615 // The incremental hash should be different
616 assert_ne!(reference.dep_tracking_hash(false), opts.dep_tracking_hash(false));
617 };
618 }
619
620 // Make sure that changing a [TRACKED_NO_CRATE_HASH] option leaves the crate hash unchanged but changes the incremental hash.
621 // This list is in alphabetical order.
622 tracked!(remap_path_prefix, vec![("/home/bors/rust".into(), "src".into())]);
623 tracked!(
624 real_rust_source_base_dir,
625 Some("/home/bors/rust/.rustup/toolchains/nightly/lib/rustlib/src/rust".into())
626 );
627}
628
dc9dc135
XL
629#[test]
630fn test_debugging_options_tracking_hash() {
631 let reference = Options::default();
632 let mut opts = Options::default();
633
f9f354fc
XL
634 macro_rules! untracked {
635 ($name: ident, $non_default_value: expr) => {
cdc7bbd5 636 assert_ne!(opts.debugging_opts.$name, $non_default_value);
f9f354fc 637 opts.debugging_opts.$name = $non_default_value;
cdc7bbd5 638 assert_same_hash(&reference, &opts);
f9f354fc
XL
639 };
640 }
641
642 // Make sure that changing an [UNTRACKED] option leaves the hash unchanged.
643 // This list is in alphabetical order.
3c0e092e 644 untracked!(assert_incr_state, Some(String::from("loaded")));
f9f354fc
XL
645 untracked!(ast_json, true);
646 untracked!(ast_json_noexpand, true);
647 untracked!(borrowck, String::from("other"));
cdc7bbd5 648 untracked!(deduplicate_diagnostics, false);
f9f354fc 649 untracked!(dep_tasks, true);
5099ac24 650 untracked!(dlltool, Some(PathBuf::from("custom_dlltool.exe")));
f9f354fc
XL
651 untracked!(dont_buffer_diagnostics, true);
652 untracked!(dump_dep_graph, true);
653 untracked!(dump_mir, Some(String::from("abc")));
654 untracked!(dump_mir_dataflow, true);
655 untracked!(dump_mir_dir, String::from("abc"));
656 untracked!(dump_mir_exclude_pass_number, true);
657 untracked!(dump_mir_graphviz, true);
658 untracked!(emit_stack_sizes, true);
136023e0 659 untracked!(future_incompat_test, true);
f9f354fc
XL
660 untracked!(hir_stats, true);
661 untracked!(identify_regions, true);
662 untracked!(incremental_ignore_spans, true);
663 untracked!(incremental_info, true);
664 untracked!(incremental_verify_ich, true);
665 untracked!(input_stats, true);
666 untracked!(keep_hygiene_data, true);
667 untracked!(link_native_libraries, false);
668 untracked!(llvm_time_trace, true);
669 untracked!(ls, true);
670 untracked!(macro_backtrace, true);
671 untracked!(meta_stats, true);
672 untracked!(nll_facts, true);
673 untracked!(no_analysis, true);
674 untracked!(no_interleave_lints, true);
675 untracked!(no_leak_check, true);
676 untracked!(no_parallel_llvm, true);
677 untracked!(parse_only, true);
678 untracked!(perf_stats, true);
f9f354fc
XL
679 // `pre_link_arg` is omitted because it just forwards to `pre_link_args`.
680 untracked!(pre_link_args, vec![String::from("abc"), String::from("def")]);
136023e0 681 untracked!(profile_closures, true);
f9f354fc
XL
682 untracked!(print_llvm_passes, true);
683 untracked!(print_mono_items, Some(String::from("abc")));
f9f354fc 684 untracked!(print_type_sizes, true);
1b1a35ee 685 untracked!(proc_macro_backtrace, true);
f9f354fc 686 untracked!(query_dep_graph, true);
f9f354fc
XL
687 untracked!(save_analysis, true);
688 untracked!(self_profile, SwitchWithOptPath::Enabled(None));
689 untracked!(self_profile_events, Some(vec![String::new()]));
f035d41b 690 untracked!(span_debug, true);
f9f354fc 691 untracked!(span_free_formats, true);
3c0e092e 692 untracked!(temps_dir, Some(String::from("abc")));
f9f354fc
XL
693 untracked!(terminal_width, Some(80));
694 untracked!(threads, 99);
695 untracked!(time, true);
696 untracked!(time_llvm_passes, true);
697 untracked!(time_passes, true);
698 untracked!(trace_macros, true);
1b1a35ee 699 untracked!(trim_diagnostic_paths, false);
f9f354fc
XL
700 untracked!(ui_testing, true);
701 untracked!(unpretty, Some("expanded".to_string()));
702 untracked!(unstable_options, true);
703 untracked!(validate_mir, true);
704 untracked!(verbose, true);
705
706 macro_rules! tracked {
707 ($name: ident, $non_default_value: expr) => {
708 opts = reference.clone();
cdc7bbd5 709 assert_ne!(opts.debugging_opts.$name, $non_default_value);
f9f354fc 710 opts.debugging_opts.$name = $non_default_value;
cdc7bbd5 711 assert_different_hash(&reference, &opts);
f9f354fc
XL
712 };
713 }
714
715 // Make sure that changing a [TRACKED] option changes the hash.
716 // This list is in alphabetical order.
717 tracked!(allow_features, Some(vec![String::from("lang_items")]));
718 tracked!(always_encode_mir, true);
719 tracked!(asm_comments, true);
3c0e092e 720 tracked!(assume_incomplete_release, true);
f9f354fc 721 tracked!(binary_dep_depinfo, true);
5099ac24
FG
722 tracked!(
723 branch_protection,
724 Some(BranchProtection {
725 bti: true,
726 pac_ret: Some(PacRet { leaf: true, key: PAuthKey::B })
727 })
728 );
f9f354fc
XL
729 tracked!(chalk, true);
730 tracked!(codegen_backend, Some("abc".to_string()));
731 tracked!(crate_attr, vec!["abc".to_string()]);
c295e0f8 732 tracked!(debug_info_for_profiling, true);
f9f354fc
XL
733 tracked!(debug_macros, true);
734 tracked!(dep_info_omit_d_target, true);
5099ac24 735 tracked!(drop_tracking, true);
f9f354fc 736 tracked!(dual_proc_macros, true);
fc512014 737 tracked!(fewer_names, Some(true));
f9f354fc
XL
738 tracked!(force_unstable_if_unmarked, true);
739 tracked!(fuel, Some(("abc".to_string(), 99)));
29967ef6 740 tracked!(function_sections, Some(false));
f9f354fc
XL
741 tracked!(human_readable_cgu_names, true);
742 tracked!(inline_in_all_cgus, Some(true));
6a06907d 743 tracked!(inline_mir, Some(true));
6a06907d 744 tracked!(inline_mir_hint_threshold, Some(123));
3c0e092e 745 tracked!(inline_mir_threshold, Some(123));
cdc7bbd5 746 tracked!(instrument_coverage, Some(InstrumentCoverage::All));
f9f354fc
XL
747 tracked!(instrument_mcount, true);
748 tracked!(link_only, true);
136023e0 749 tracked!(llvm_plugins, vec![String::from("plugin_name")]);
3c0e092e 750 tracked!(location_detail, LocationDetail { file: true, line: false, column: false });
f9f354fc
XL
751 tracked!(merge_functions, Some(MergeFunctions::Disabled));
752 tracked!(mir_emit_retag, true);
6a06907d 753 tracked!(mir_opt_level, Some(4));
94222f64 754 tracked!(move_size_limit, Some(4096));
cdc7bbd5 755 tracked!(mutable_noalias, Some(true));
17df50a5 756 tracked!(new_llvm_pass_manager, Some(true));
f9f354fc
XL
757 tracked!(no_generate_arange_section, true);
758 tracked!(no_link, true);
3c0e092e 759 tracked!(no_unique_section_names, true);
94222f64 760 tracked!(no_profiler_runtime, true);
f9f354fc
XL
761 tracked!(osx_rpath_install_name, true);
762 tracked!(panic_abort_tests, true);
c295e0f8 763 tracked!(panic_in_drop, PanicStrategy::Abort);
94222f64 764 tracked!(partially_uninit_const_threshold, Some(123));
3c0e092e 765 tracked!(pick_stable_methods_before_any_unstable, false);
f9f354fc 766 tracked!(plt, Some(true));
fc512014 767 tracked!(polonius, true);
1b1a35ee 768 tracked!(precise_enum_drop_elaboration, false);
f9f354fc
XL
769 tracked!(print_fuel, Some("abc".to_string()));
770 tracked!(profile, true);
771 tracked!(profile_emit, Some(PathBuf::from("abc")));
94222f64 772 tracked!(profiler_runtime, "abc".to_string());
c295e0f8 773 tracked!(profile_sample_use, Some(PathBuf::from("abc")));
29967ef6 774 tracked!(relax_elf_relocations, Some(true));
f9f354fc 775 tracked!(relro_level, Some(RelroLevel::Full));
c295e0f8 776 tracked!(remap_cwd_prefix, Some(PathBuf::from("abc")));
f9f354fc 777 tracked!(report_delayed_bugs, true);
f035d41b 778 tracked!(sanitizer, SanitizerSet::ADDRESS);
f9f354fc 779 tracked!(sanitizer_memory_track_origins, 2);
f035d41b 780 tracked!(sanitizer_recover, SanitizerSet::ADDRESS);
f9f354fc
XL
781 tracked!(saturating_float_casts, Some(true));
782 tracked!(share_generics, Some(true));
783 tracked!(show_span, Some(String::from("abc")));
3c0e092e 784 tracked!(simulate_remapped_rust_src_base, Some(PathBuf::from("/rustc/abc")));
f9f354fc 785 tracked!(src_hash_algorithm, Some(SourceFileHashAlgorithm::Sha1));
3c0e092e 786 tracked!(stack_protector, StackProtector::All);
fc512014 787 tracked!(symbol_mangling_version, Some(SymbolManglingVersion::V0));
f9f354fc
XL
788 tracked!(teach, true);
789 tracked!(thinlto, Some(true));
17df50a5 790 tracked!(thir_unsafeck, true);
f9f354fc 791 tracked!(tls_model, Some(TlsModel::GeneralDynamic));
fc512014 792 tracked!(trap_unreachable, Some(false));
6a06907d 793 tracked!(treat_err_as_bug, NonZeroUsize::new(1));
3c0e092e 794 tracked!(tune_cpu, Some(String::from("abc")));
f9f354fc
XL
795 tracked!(unleash_the_miri_inside_of_you, true);
796 tracked!(use_ctors_section, Some(true));
797 tracked!(verify_llvm_ir, true);
5869c6ff 798 tracked!(wasi_exec_model, Some(WasiExecModel::Reactor));
136023e0
XL
799
800 macro_rules! tracked_no_crate_hash {
801 ($name: ident, $non_default_value: expr) => {
802 opts = reference.clone();
803 assert_ne!(opts.debugging_opts.$name, $non_default_value);
804 opts.debugging_opts.$name = $non_default_value;
805 assert_non_crate_hash_different(&reference, &opts);
806 };
807 }
808 tracked_no_crate_hash!(no_codegen, true);
dc9dc135
XL
809}
810
811#[test]
812fn test_edition_parsing() {
813 // test default edition
814 let options = Options::default();
815 assert!(options.edition == DEFAULT_EDITION);
816
dfeec247 817 let matches = optgroups().parse(&["--edition=2018".to_string()]).unwrap();
60c5eb7d 818 let (sessopts, _) = build_session_options_and_crate_config(matches);
dc9dc135
XL
819 assert!(sessopts.edition == Edition::Edition2018)
820}