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