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