]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_interface/src/tests.rs
Fix off by one error and add ui test.
[rust.git] / compiler / rustc_interface / src / tests.rs
1 use crate::interface::parse_cfgspecs;
2
3 use rustc_data_structures::fx::FxHashSet;
4 use rustc_errors::{emitter::HumanReadableErrorType, registry, ColorConfig};
5 use rustc_session::config::InstrumentCoverage;
6 use rustc_session::config::Strip;
7 use rustc_session::config::{build_configuration, build_session_options, to_crate_config};
8 use rustc_session::config::{
9     rustc_optgroups, ErrorOutputType, ExternLocation, LocationDetail, Options, Passes,
10 };
11 use rustc_session::config::{
12     BranchProtection, Externs, OomStrategy, OutputType, OutputTypes, PAuthKey, PacRet,
13     SymbolManglingVersion, WasiExecModel,
14 };
15 use rustc_session::config::{CFGuard, ExternEntry, LinkerPluginLto, LtoCli, SwitchWithOptPath};
16 use rustc_session::lint::Level;
17 use rustc_session::search_paths::SearchPath;
18 use rustc_session::utils::{CanonicalizedPath, NativeLib, NativeLibKind};
19 use rustc_session::{build_session, getopts, DiagnosticOutput, Session};
20 use rustc_span::edition::{Edition, DEFAULT_EDITION};
21 use rustc_span::symbol::sym;
22 use rustc_span::SourceFileHashAlgorithm;
23 use rustc_target::spec::{CodeModel, LinkerFlavor, MergeFunctions, PanicStrategy};
24 use rustc_target::spec::{
25     RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel,
26 };
27
28 use std::collections::{BTreeMap, BTreeSet};
29 use std::iter::FromIterator;
30 use std::num::NonZeroUsize;
31 use std::path::{Path, PathBuf};
32
33 type CfgSpecs = FxHashSet<(String, Option<String>)>;
34
35 fn 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
41 fn mk_session(matches: getopts::Matches) -> (Session, CfgSpecs) {
42     let registry = registry::Registry::new(&[]);
43     let (sessopts, cfg) = build_session_options_and_crate_config(matches);
44     let sess = build_session(
45         sessopts,
46         None,
47         None,
48         registry,
49         DiagnosticOutput::Default,
50         Default::default(),
51         None,
52         None,
53     );
54     (sess, cfg)
55 }
56
57 fn new_public_extern_entry<S, I>(locations: I) -> ExternEntry
58 where
59     S: Into<String>,
60     I: IntoIterator<Item = S>,
61 {
62     let locations: BTreeSet<CanonicalizedPath> =
63         locations.into_iter().map(|s| CanonicalizedPath::new(Path::new(&s.into()))).collect();
64
65     ExternEntry {
66         location: ExternLocation::ExactPaths(locations),
67         is_private_dep: false,
68         add_prelude: true,
69         nounused_dep: false,
70     }
71 }
72
73 fn optgroups() -> getopts::Options {
74     let mut opts = getopts::Options::new();
75     for group in rustc_optgroups() {
76         (group.apply)(&mut opts);
77     }
78     return opts;
79 }
80
81 fn mk_map<K: Ord, V>(entries: Vec<(K, V)>) -> BTreeMap<K, V> {
82     BTreeMap::from_iter(entries.into_iter())
83 }
84
85 fn 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
90 fn 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
98 fn 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
106 fn 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
114 // When the user supplies --test we should implicitly supply --cfg test
115 #[test]
116 fn test_switch_implies_cfg_test() {
117     rustc_span::create_default_session_globals_then(|| {
118         let matches = optgroups().parse(&["--test".to_string()]).unwrap();
119         let (sess, cfg) = mk_session(matches);
120         let cfg = build_configuration(&sess, to_crate_config(cfg));
121         assert!(cfg.contains(&(sym::test, None)));
122     });
123 }
124
125 // When the user supplies --test and --cfg test, don't implicitly add another --cfg test
126 #[test]
127 fn test_switch_implies_cfg_test_unless_cfg_test() {
128     rustc_span::create_default_session_globals_then(|| {
129         let matches = optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]).unwrap();
130         let (sess, cfg) = mk_session(matches);
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]
139 fn test_can_print_warnings() {
140     rustc_span::create_default_session_globals_then(|| {
141         let matches = optgroups().parse(&["-Awarnings".to_string()]).unwrap();
142         let (sess, _) = mk_session(matches);
143         assert!(!sess.diagnostic().can_emit_warnings());
144     });
145
146     rustc_span::create_default_session_globals_then(|| {
147         let matches =
148             optgroups().parse(&["-Awarnings".to_string(), "-Dwarnings".to_string()]).unwrap();
149         let (sess, _) = mk_session(matches);
150         assert!(sess.diagnostic().can_emit_warnings());
151     });
152
153     rustc_span::create_default_session_globals_then(|| {
154         let matches = optgroups().parse(&["-Adead_code".to_string()]).unwrap();
155         let (sess, _) = mk_session(matches);
156         assert!(sess.diagnostic().can_emit_warnings());
157     });
158 }
159
160 #[test]
161 fn 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
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")))]);
168     v3.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
169
170     assert_non_crate_hash_different(&v1, &v2);
171     assert_non_crate_hash_different(&v1, &v3);
172     assert_non_crate_hash_different(&v2, &v3);
173 }
174
175 #[test]
176 fn 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
190     assert_same_hash(&v1, &v2);
191 }
192
193 #[test]
194 fn 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![
200         (String::from("a"), new_public_extern_entry(vec!["b", "c"])),
201         (String::from("d"), new_public_extern_entry(vec!["e", "f"])),
202     ]));
203
204     v2.externs = Externs::new(mk_map(vec![
205         (String::from("d"), new_public_extern_entry(vec!["e", "f"])),
206         (String::from("a"), new_public_extern_entry(vec!["b", "c"])),
207     ]));
208
209     v3.externs = Externs::new(mk_map(vec![
210         (String::from("a"), new_public_extern_entry(vec!["b", "c"])),
211         (String::from("d"), new_public_extern_entry(vec!["f", "e"])),
212     ]));
213
214     assert_same_hash(&v1, &v2);
215     assert_same_hash(&v1, &v3);
216     assert_same_hash(&v2, &v3);
217 }
218
219 #[test]
220 fn 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![
226         (String::from("a"), Level::Allow),
227         (String::from("b"), Level::Warn),
228         (String::from("c"), Level::Deny),
229         (String::from("d"), Level::Forbid),
230     ];
231
232     v2.lint_opts = vec![
233         (String::from("a"), Level::Allow),
234         (String::from("b"), Level::Warn),
235         (String::from("X"), Level::Deny),
236         (String::from("d"), Level::Forbid),
237     ];
238
239     v3.lint_opts = vec![
240         (String::from("a"), Level::Allow),
241         (String::from("b"), Level::Warn),
242         (String::from("c"), Level::Forbid),
243         (String::from("d"), Level::Deny),
244     ];
245
246     assert_non_crate_hash_different(&v1, &v2);
247     assert_non_crate_hash_different(&v1, &v3);
248     assert_non_crate_hash_different(&v2, &v3);
249 }
250
251 #[test]
252 fn 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![
257         (String::from("a"), Level::Allow),
258         (String::from("b"), Level::Warn),
259         (String::from("c"), Level::Deny),
260         (String::from("d"), Level::Forbid),
261     ];
262
263     v2.lint_opts = vec![
264         (String::from("a"), Level::Allow),
265         (String::from("c"), Level::Deny),
266         (String::from("b"), Level::Warn),
267         (String::from("d"), Level::Forbid),
268     ];
269
270     // The hash should be order-dependent
271     assert_non_crate_hash_different(&v1, &v2);
272 }
273
274 #[test]
275 fn 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);
286 }
287
288 #[test]
289 fn 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
295     const JSON: ErrorOutputType = ErrorOutputType::Json {
296         pretty: false,
297         json_rendered: HumanReadableErrorType::Default(ColorConfig::Never),
298     };
299
300     // Reference
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));
324
325     assert_same_hash(&v1, &v2);
326     assert_same_hash(&v1, &v3);
327     assert_same_hash(&v1, &v4);
328 }
329
330 #[test]
331 fn 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();
336     let mut v5 = Options::default();
337
338     // Reference
339     v1.libs = vec![
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         },
358     ];
359
360     // Change label
361     v2.libs = vec![
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         },
380     ];
381
382     // Change kind
383     v3.libs = vec![
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         },
402     ];
403
404     // Change new-name
405     v4.libs = vec![
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         },
446     ];
447
448     assert_different_hash(&v1, &v2);
449     assert_different_hash(&v1, &v3);
450     assert_different_hash(&v1, &v4);
451     assert_different_hash(&v1, &v5);
452 }
453
454 #[test]
455 fn 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![
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         },
480     ];
481
482     v2.libs = vec![
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         },
501     ];
502
503     v3.libs = vec![
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         },
522     ];
523
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);
528 }
529
530 #[test]
531 fn test_codegen_options_tracking_hash() {
532     let reference = Options::default();
533     let mut opts = Options::default();
534
535     macro_rules! untracked {
536         ($name: ident, $non_default_value: expr) => {
537             assert_ne!(opts.cg.$name, $non_default_value);
538             opts.cg.$name = $non_default_value;
539             assert_same_hash(&reference, &opts);
540         };
541     }
542
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")]);
552     untracked!(link_self_contained, Some(true));
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);
559     untracked!(strip, Strip::Debuginfo);
560
561     macro_rules! tracked {
562         ($name: ident, $non_default_value: expr) => {
563             opts = reference.clone();
564             assert_ne!(opts.cg.$name, $non_default_value);
565             opts.cg.$name = $non_default_value;
566             assert_different_hash(&reference, &opts);
567         };
568     }
569
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));
573     tracked!(control_flow_guard, CFGuard::Checks);
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));
580     tracked!(instrument_coverage, Some(InstrumentCoverage::All));
581     tracked!(linker_plugin_lto, LinkerPluginLto::LinkerPluginAuto);
582     tracked!(link_dead_code, Some(true));
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);
599     tracked!(split_debuginfo, Some(SplitDebuginfo::Packed));
600     tracked!(symbol_mangling_version, Some(SymbolManglingVersion::V0));
601     tracked!(target_cpu, Some(String::from("abc")));
602     tracked!(target_feature, String::from("all the features, all of them"));
603 }
604
605 #[test]
606 fn 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
631 #[test]
632 fn test_unstable_options_tracking_hash() {
633     let reference = Options::default();
634     let mut opts = Options::default();
635
636     macro_rules! untracked {
637         ($name: ident, $non_default_value: expr) => {
638             assert_ne!(opts.unstable_opts.$name, $non_default_value);
639             opts.unstable_opts.$name = $non_default_value;
640             assert_same_hash(&reference, &opts);
641         };
642     }
643
644     // Make sure that changing an [UNTRACKED] option leaves the hash unchanged.
645     // This list is in alphabetical order.
646     untracked!(assert_incr_state, Some(String::from("loaded")));
647     untracked!(deduplicate_diagnostics, false);
648     untracked!(dep_tasks, true);
649     untracked!(dlltool, Some(PathBuf::from("custom_dlltool.exe")));
650     untracked!(dont_buffer_diagnostics, true);
651     untracked!(dump_dep_graph, true);
652     untracked!(dump_drop_tracking_cfg, Some("cfg.dot".to_string()));
653     untracked!(dump_mir, Some(String::from("abc")));
654     untracked!(dump_mir_dataflow, true);
655     untracked!(dump_mir_dir, String::from("abc"));
656     untracked!(dump_mir_exclude_pass_number, true);
657     untracked!(dump_mir_graphviz, true);
658     untracked!(emit_stack_sizes, true);
659     untracked!(future_incompat_test, true);
660     untracked!(hir_stats, true);
661     untracked!(identify_regions, true);
662     untracked!(incremental_ignore_spans, true);
663     untracked!(incremental_info, true);
664     untracked!(incremental_verify_ich, true);
665     untracked!(input_stats, true);
666     untracked!(keep_hygiene_data, true);
667     untracked!(link_native_libraries, false);
668     untracked!(llvm_time_trace, true);
669     untracked!(ls, true);
670     untracked!(macro_backtrace, true);
671     untracked!(meta_stats, true);
672     untracked!(nll_facts, true);
673     untracked!(no_analysis, true);
674     untracked!(no_interleave_lints, true);
675     untracked!(no_leak_check, true);
676     untracked!(no_parallel_llvm, true);
677     untracked!(parse_only, true);
678     untracked!(perf_stats, true);
679     // `pre_link_arg` is omitted because it just forwards to `pre_link_args`.
680     untracked!(pre_link_args, vec![String::from("abc"), String::from("def")]);
681     untracked!(profile_closures, true);
682     untracked!(print_llvm_passes, true);
683     untracked!(print_mono_items, Some(String::from("abc")));
684     untracked!(print_type_sizes, true);
685     untracked!(proc_macro_backtrace, true);
686     untracked!(query_dep_graph, true);
687     untracked!(save_analysis, true);
688     untracked!(self_profile, SwitchWithOptPath::Enabled(None));
689     untracked!(self_profile_events, Some(vec![String::new()]));
690     untracked!(span_debug, true);
691     untracked!(span_free_formats, true);
692     untracked!(temps_dir, Some(String::from("abc")));
693     untracked!(threads, 99);
694     untracked!(time, true);
695     untracked!(time_llvm_passes, true);
696     untracked!(time_passes, true);
697     untracked!(trace_macros, true);
698     untracked!(trim_diagnostic_paths, false);
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();
708             assert_ne!(opts.unstable_opts.$name, $non_default_value);
709             opts.unstable_opts.$name = $non_default_value;
710             assert_different_hash(&reference, &opts);
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);
719     tracked!(assume_incomplete_release, true);
720     tracked!(binary_dep_depinfo, true);
721     tracked!(
722         branch_protection,
723         Some(BranchProtection {
724             bti: true,
725             pac_ret: Some(PacRet { leaf: true, key: PAuthKey::B })
726         })
727     );
728     tracked!(chalk, true);
729     tracked!(codegen_backend, Some("abc".to_string()));
730     tracked!(crate_attr, vec!["abc".to_string()]);
731     tracked!(debug_info_for_profiling, true);
732     tracked!(debug_macros, true);
733     tracked!(dep_info_omit_d_target, true);
734     tracked!(drop_tracking, true);
735     tracked!(dual_proc_macros, true);
736     tracked!(dwarf_version, Some(5));
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!(new_llvm_pass_manager, Some(true));
758     tracked!(no_generate_arange_section, true);
759     tracked!(no_link, true);
760     tracked!(no_unique_section_names, true);
761     tracked!(no_profiler_runtime, true);
762     tracked!(oom, OomStrategy::Panic);
763     tracked!(osx_rpath_install_name, 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!(profiler_runtime, "abc".to_string());
774     tracked!(profile_sample_use, Some(PathBuf::from("abc")));
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
804     macro_rules! tracked_no_crate_hash {
805         ($name: ident, $non_default_value: expr) => {
806             opts = reference.clone();
807             assert_ne!(opts.unstable_opts.$name, $non_default_value);
808             opts.unstable_opts.$name = $non_default_value;
809             assert_non_crate_hash_different(&reference, &opts);
810         };
811     }
812     tracked_no_crate_hash!(no_codegen, true);
813 }
814
815 #[test]
816 fn test_edition_parsing() {
817     // test default edition
818     let options = Options::default();
819     assert!(options.edition == DEFAULT_EDITION);
820
821     let matches = optgroups().parse(&["--edition=2018".to_string()]).unwrap();
822     let (sessopts, _) = build_session_options_and_crate_config(matches);
823     assert!(sessopts.edition == Edition::Edition2018)
824 }