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