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