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