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