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