]> git.lizzy.rs Git - rust.git/blob - src/librustc_interface/tests.rs
Rollup merge of #69561 - JohnTitor:clean-up-unstable-book, r=Mark-Simulacrum
[rust.git] / src / librustc_interface / tests.rs
1 extern crate getopts;
2
3 use crate::interface::parse_cfgspecs;
4
5 use rustc::lint::Level;
6 use rustc::middle::cstore;
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::{ExternEntry, LinkerPluginLto, LtoCli, SwitchWithOptPath};
10 use rustc::session::config::{Externs, OutputType, OutputTypes, SymbolManglingVersion};
11 use rustc::session::search_paths::SearchPath;
12 use rustc::session::{build_session, Session};
13 use rustc_data_structures::fx::FxHashSet;
14 use rustc_errors::{emitter::HumanReadableErrorType, registry, ColorConfig};
15 use rustc_span::edition::{Edition, DEFAULT_EDITION};
16 use rustc_span::symbol::sym;
17 use rustc_target::spec::{MergeFunctions, PanicStrategy, RelroLevel};
18 use std::collections::{BTreeMap, BTreeSet};
19 use std::iter::FromIterator;
20 use std::path::PathBuf;
21
22 type CfgSpecs = FxHashSet<(String, Option<String>)>;
23
24 fn build_session_options_and_crate_config(matches: getopts::Matches) -> (Options, CfgSpecs) {
25     let sessopts = build_session_options(&matches);
26     let cfg = parse_cfgspecs(matches.opt_strs("cfg"));
27     (sessopts, cfg)
28 }
29
30 fn mk_session(matches: getopts::Matches) -> (Session, CfgSpecs) {
31     let registry = registry::Registry::new(&[]);
32     let (sessopts, cfg) = build_session_options_and_crate_config(matches);
33     let sess = build_session(sessopts, None, registry);
34     (sess, cfg)
35 }
36
37 fn new_public_extern_entry<S, I>(locations: I) -> ExternEntry
38 where
39     S: Into<String>,
40     I: IntoIterator<Item = S>,
41 {
42     let locations: BTreeSet<_> = locations.into_iter().map(|s| s.into()).collect();
43
44     ExternEntry {
45         location: ExternLocation::ExactPaths(locations),
46         is_private_dep: false,
47         add_prelude: true,
48     }
49 }
50
51 fn optgroups() -> getopts::Options {
52     let mut opts = getopts::Options::new();
53     for group in rustc_optgroups() {
54         (group.apply)(&mut opts);
55     }
56     return opts;
57 }
58
59 fn mk_map<K: Ord, V>(entries: Vec<(K, V)>) -> BTreeMap<K, V> {
60     BTreeMap::from_iter(entries.into_iter())
61 }
62
63 // When the user supplies --test we should implicitly supply --cfg test
64 #[test]
65 fn test_switch_implies_cfg_test() {
66     rustc_ast::with_default_globals(|| {
67         let matches = optgroups().parse(&["--test".to_string()]).unwrap();
68         let (sess, cfg) = mk_session(matches);
69         let cfg = build_configuration(&sess, to_crate_config(cfg));
70         assert!(cfg.contains(&(sym::test, None)));
71     });
72 }
73
74 // When the user supplies --test and --cfg test, don't implicitly add another --cfg test
75 #[test]
76 fn test_switch_implies_cfg_test_unless_cfg_test() {
77     rustc_ast::with_default_globals(|| {
78         let matches = optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]).unwrap();
79         let (sess, cfg) = mk_session(matches);
80         let cfg = build_configuration(&sess, to_crate_config(cfg));
81         let mut test_items = cfg.iter().filter(|&&(name, _)| name == sym::test);
82         assert!(test_items.next().is_some());
83         assert!(test_items.next().is_none());
84     });
85 }
86
87 #[test]
88 fn test_can_print_warnings() {
89     rustc_ast::with_default_globals(|| {
90         let matches = optgroups().parse(&["-Awarnings".to_string()]).unwrap();
91         let (sess, _) = mk_session(matches);
92         assert!(!sess.diagnostic().can_emit_warnings());
93     });
94
95     rustc_ast::with_default_globals(|| {
96         let matches =
97             optgroups().parse(&["-Awarnings".to_string(), "-Dwarnings".to_string()]).unwrap();
98         let (sess, _) = mk_session(matches);
99         assert!(sess.diagnostic().can_emit_warnings());
100     });
101
102     rustc_ast::with_default_globals(|| {
103         let matches = optgroups().parse(&["-Adead_code".to_string()]).unwrap();
104         let (sess, _) = mk_session(matches);
105         assert!(sess.diagnostic().can_emit_warnings());
106     });
107 }
108
109 #[test]
110 fn test_output_types_tracking_hash_different_paths() {
111     let mut v1 = Options::default();
112     let mut v2 = Options::default();
113     let mut v3 = Options::default();
114
115     v1.output_types = OutputTypes::new(&[(OutputType::Exe, Some(PathBuf::from("./some/thing")))]);
116     v2.output_types = OutputTypes::new(&[(OutputType::Exe, Some(PathBuf::from("/some/thing")))]);
117     v3.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
118
119     assert!(v1.dep_tracking_hash() != v2.dep_tracking_hash());
120     assert!(v1.dep_tracking_hash() != v3.dep_tracking_hash());
121     assert!(v2.dep_tracking_hash() != v3.dep_tracking_hash());
122
123     // Check clone
124     assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
125     assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
126     assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash());
127 }
128
129 #[test]
130 fn test_output_types_tracking_hash_different_construction_order() {
131     let mut v1 = Options::default();
132     let mut v2 = Options::default();
133
134     v1.output_types = OutputTypes::new(&[
135         (OutputType::Exe, Some(PathBuf::from("./some/thing"))),
136         (OutputType::Bitcode, Some(PathBuf::from("./some/thing.bc"))),
137     ]);
138
139     v2.output_types = OutputTypes::new(&[
140         (OutputType::Bitcode, Some(PathBuf::from("./some/thing.bc"))),
141         (OutputType::Exe, Some(PathBuf::from("./some/thing"))),
142     ]);
143
144     assert_eq!(v1.dep_tracking_hash(), v2.dep_tracking_hash());
145
146     // Check clone
147     assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
148 }
149
150 #[test]
151 fn test_externs_tracking_hash_different_construction_order() {
152     let mut v1 = Options::default();
153     let mut v2 = Options::default();
154     let mut v3 = Options::default();
155
156     v1.externs = Externs::new(mk_map(vec![
157         (String::from("a"), new_public_extern_entry(vec!["b", "c"])),
158         (String::from("d"), new_public_extern_entry(vec!["e", "f"])),
159     ]));
160
161     v2.externs = Externs::new(mk_map(vec![
162         (String::from("d"), new_public_extern_entry(vec!["e", "f"])),
163         (String::from("a"), new_public_extern_entry(vec!["b", "c"])),
164     ]));
165
166     v3.externs = Externs::new(mk_map(vec![
167         (String::from("a"), new_public_extern_entry(vec!["b", "c"])),
168         (String::from("d"), new_public_extern_entry(vec!["f", "e"])),
169     ]));
170
171     assert_eq!(v1.dep_tracking_hash(), v2.dep_tracking_hash());
172     assert_eq!(v1.dep_tracking_hash(), v3.dep_tracking_hash());
173     assert_eq!(v2.dep_tracking_hash(), v3.dep_tracking_hash());
174
175     // Check clone
176     assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
177     assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
178     assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash());
179 }
180
181 #[test]
182 fn test_lints_tracking_hash_different_values() {
183     let mut v1 = Options::default();
184     let mut v2 = Options::default();
185     let mut v3 = Options::default();
186
187     v1.lint_opts = vec![
188         (String::from("a"), Level::Allow),
189         (String::from("b"), Level::Warn),
190         (String::from("c"), Level::Deny),
191         (String::from("d"), Level::Forbid),
192     ];
193
194     v2.lint_opts = vec![
195         (String::from("a"), Level::Allow),
196         (String::from("b"), Level::Warn),
197         (String::from("X"), Level::Deny),
198         (String::from("d"), Level::Forbid),
199     ];
200
201     v3.lint_opts = vec![
202         (String::from("a"), Level::Allow),
203         (String::from("b"), Level::Warn),
204         (String::from("c"), Level::Forbid),
205         (String::from("d"), Level::Deny),
206     ];
207
208     assert!(v1.dep_tracking_hash() != v2.dep_tracking_hash());
209     assert!(v1.dep_tracking_hash() != v3.dep_tracking_hash());
210     assert!(v2.dep_tracking_hash() != v3.dep_tracking_hash());
211
212     // Check clone
213     assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
214     assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
215     assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash());
216 }
217
218 #[test]
219 fn test_lints_tracking_hash_different_construction_order() {
220     let mut v1 = Options::default();
221     let mut v2 = 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("c"), Level::Deny),
233         (String::from("b"), Level::Warn),
234         (String::from("d"), Level::Forbid),
235     ];
236
237     assert_eq!(v1.dep_tracking_hash(), v2.dep_tracking_hash());
238
239     // Check clone
240     assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
241     assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
242 }
243
244 #[test]
245 fn test_search_paths_tracking_hash_different_order() {
246     let mut v1 = Options::default();
247     let mut v2 = Options::default();
248     let mut v3 = Options::default();
249     let mut v4 = Options::default();
250
251     const JSON: ErrorOutputType = ErrorOutputType::Json {
252         pretty: false,
253         json_rendered: HumanReadableErrorType::Default(ColorConfig::Never),
254     };
255
256     // Reference
257     v1.search_paths.push(SearchPath::from_cli_opt("native=abc", JSON));
258     v1.search_paths.push(SearchPath::from_cli_opt("crate=def", JSON));
259     v1.search_paths.push(SearchPath::from_cli_opt("dependency=ghi", JSON));
260     v1.search_paths.push(SearchPath::from_cli_opt("framework=jkl", JSON));
261     v1.search_paths.push(SearchPath::from_cli_opt("all=mno", JSON));
262
263     v2.search_paths.push(SearchPath::from_cli_opt("native=abc", JSON));
264     v2.search_paths.push(SearchPath::from_cli_opt("dependency=ghi", JSON));
265     v2.search_paths.push(SearchPath::from_cli_opt("crate=def", JSON));
266     v2.search_paths.push(SearchPath::from_cli_opt("framework=jkl", JSON));
267     v2.search_paths.push(SearchPath::from_cli_opt("all=mno", JSON));
268
269     v3.search_paths.push(SearchPath::from_cli_opt("crate=def", JSON));
270     v3.search_paths.push(SearchPath::from_cli_opt("framework=jkl", JSON));
271     v3.search_paths.push(SearchPath::from_cli_opt("native=abc", JSON));
272     v3.search_paths.push(SearchPath::from_cli_opt("dependency=ghi", JSON));
273     v3.search_paths.push(SearchPath::from_cli_opt("all=mno", JSON));
274
275     v4.search_paths.push(SearchPath::from_cli_opt("all=mno", JSON));
276     v4.search_paths.push(SearchPath::from_cli_opt("native=abc", JSON));
277     v4.search_paths.push(SearchPath::from_cli_opt("crate=def", JSON));
278     v4.search_paths.push(SearchPath::from_cli_opt("dependency=ghi", JSON));
279     v4.search_paths.push(SearchPath::from_cli_opt("framework=jkl", JSON));
280
281     assert!(v1.dep_tracking_hash() == v2.dep_tracking_hash());
282     assert!(v1.dep_tracking_hash() == v3.dep_tracking_hash());
283     assert!(v1.dep_tracking_hash() == v4.dep_tracking_hash());
284
285     // Check clone
286     assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
287     assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
288     assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash());
289     assert_eq!(v4.dep_tracking_hash(), v4.clone().dep_tracking_hash());
290 }
291
292 #[test]
293 fn test_native_libs_tracking_hash_different_values() {
294     let mut v1 = Options::default();
295     let mut v2 = Options::default();
296     let mut v3 = Options::default();
297     let mut v4 = Options::default();
298
299     // Reference
300     v1.libs = vec![
301         (String::from("a"), None, Some(cstore::NativeStatic)),
302         (String::from("b"), None, Some(cstore::NativeFramework)),
303         (String::from("c"), None, Some(cstore::NativeUnknown)),
304     ];
305
306     // Change label
307     v2.libs = vec![
308         (String::from("a"), None, Some(cstore::NativeStatic)),
309         (String::from("X"), None, Some(cstore::NativeFramework)),
310         (String::from("c"), None, Some(cstore::NativeUnknown)),
311     ];
312
313     // Change kind
314     v3.libs = vec![
315         (String::from("a"), None, Some(cstore::NativeStatic)),
316         (String::from("b"), None, Some(cstore::NativeStatic)),
317         (String::from("c"), None, Some(cstore::NativeUnknown)),
318     ];
319
320     // Change new-name
321     v4.libs = vec![
322         (String::from("a"), None, Some(cstore::NativeStatic)),
323         (String::from("b"), Some(String::from("X")), Some(cstore::NativeFramework)),
324         (String::from("c"), None, Some(cstore::NativeUnknown)),
325     ];
326
327     assert!(v1.dep_tracking_hash() != v2.dep_tracking_hash());
328     assert!(v1.dep_tracking_hash() != v3.dep_tracking_hash());
329     assert!(v1.dep_tracking_hash() != v4.dep_tracking_hash());
330
331     // Check clone
332     assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
333     assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
334     assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash());
335     assert_eq!(v4.dep_tracking_hash(), v4.clone().dep_tracking_hash());
336 }
337
338 #[test]
339 fn test_native_libs_tracking_hash_different_order() {
340     let mut v1 = Options::default();
341     let mut v2 = Options::default();
342     let mut v3 = Options::default();
343
344     // Reference
345     v1.libs = vec![
346         (String::from("a"), None, Some(cstore::NativeStatic)),
347         (String::from("b"), None, Some(cstore::NativeFramework)),
348         (String::from("c"), None, Some(cstore::NativeUnknown)),
349     ];
350
351     v2.libs = vec![
352         (String::from("b"), None, Some(cstore::NativeFramework)),
353         (String::from("a"), None, Some(cstore::NativeStatic)),
354         (String::from("c"), None, Some(cstore::NativeUnknown)),
355     ];
356
357     v3.libs = vec![
358         (String::from("c"), None, Some(cstore::NativeUnknown)),
359         (String::from("a"), None, Some(cstore::NativeStatic)),
360         (String::from("b"), None, Some(cstore::NativeFramework)),
361     ];
362
363     assert!(v1.dep_tracking_hash() == v2.dep_tracking_hash());
364     assert!(v1.dep_tracking_hash() == v3.dep_tracking_hash());
365     assert!(v2.dep_tracking_hash() == v3.dep_tracking_hash());
366
367     // Check clone
368     assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
369     assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
370     assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash());
371 }
372
373 #[test]
374 fn test_codegen_options_tracking_hash() {
375     let reference = Options::default();
376     let mut opts = Options::default();
377
378     // Make sure the changing an [UNTRACKED] option leaves the hash unchanged
379     opts.cg.ar = Some(String::from("abc"));
380     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
381
382     opts.cg.linker = Some(PathBuf::from("linker"));
383     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
384
385     opts.cg.link_args = Some(vec![String::from("abc"), String::from("def")]);
386     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
387
388     opts.cg.link_dead_code = true;
389     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
390
391     opts.cg.rpath = true;
392     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
393
394     opts.cg.extra_filename = String::from("extra-filename");
395     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
396
397     opts.cg.codegen_units = Some(42);
398     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
399
400     opts.cg.remark = Passes::Some(vec![String::from("pass1"), String::from("pass2")]);
401     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
402
403     opts.cg.save_temps = true;
404     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
405
406     opts.cg.incremental = Some(String::from("abc"));
407     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
408
409     // Make sure changing a [TRACKED] option changes the hash
410     opts = reference.clone();
411     opts.cg.lto = LtoCli::Fat;
412     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
413
414     opts = reference.clone();
415     opts.cg.target_cpu = Some(String::from("abc"));
416     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
417
418     opts = reference.clone();
419     opts.cg.target_feature = String::from("all the features, all of them");
420     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
421
422     opts = reference.clone();
423     opts.cg.passes = vec![String::from("1"), String::from("2")];
424     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
425
426     opts = reference.clone();
427     opts.cg.llvm_args = vec![String::from("1"), String::from("2")];
428     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
429
430     opts = reference.clone();
431     opts.cg.overflow_checks = Some(true);
432     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
433
434     opts = reference.clone();
435     opts.cg.no_prepopulate_passes = true;
436     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
437
438     opts = reference.clone();
439     opts.cg.no_vectorize_loops = true;
440     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
441
442     opts = reference.clone();
443     opts.cg.no_vectorize_slp = true;
444     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
445
446     opts = reference.clone();
447     opts.cg.soft_float = true;
448     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
449
450     opts = reference.clone();
451     opts.cg.prefer_dynamic = true;
452     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
453
454     opts = reference.clone();
455     opts.cg.no_integrated_as = true;
456     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
457
458     opts = reference.clone();
459     opts.cg.no_redzone = Some(true);
460     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
461
462     opts = reference.clone();
463     opts.cg.relocation_model = Some(String::from("relocation model"));
464     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
465
466     opts = reference.clone();
467     opts.cg.code_model = Some(String::from("code model"));
468     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
469
470     opts = reference.clone();
471     opts.debugging_opts.tls_model = Some(String::from("tls model"));
472     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
473
474     opts = reference.clone();
475     opts.cg.profile_generate = SwitchWithOptPath::Enabled(None);
476     assert_ne!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
477
478     opts = reference.clone();
479     opts.cg.profile_use = Some(PathBuf::from("abc"));
480     assert_ne!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
481
482     opts = reference.clone();
483     opts.cg.metadata = vec![String::from("A"), String::from("B")];
484     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
485
486     opts = reference.clone();
487     opts.cg.debuginfo = Some(0xdeadbeef);
488     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
489
490     opts = reference.clone();
491     opts.cg.debuginfo = Some(0xba5eba11);
492     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
493
494     opts = reference.clone();
495     opts.cg.force_frame_pointers = Some(false);
496     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
497
498     opts = reference.clone();
499     opts.cg.debug_assertions = Some(true);
500     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
501
502     opts = reference.clone();
503     opts.cg.inline_threshold = Some(0xf007ba11);
504     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
505
506     opts = reference.clone();
507     opts.cg.panic = Some(PanicStrategy::Abort);
508     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
509
510     opts = reference.clone();
511     opts.cg.linker_plugin_lto = LinkerPluginLto::LinkerPluginAuto;
512     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
513 }
514
515 #[test]
516 fn test_debugging_options_tracking_hash() {
517     let reference = Options::default();
518     let mut opts = Options::default();
519
520     // Make sure the changing an [UNTRACKED] option leaves the hash unchanged
521     opts.debugging_opts.verbose = true;
522     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
523     opts.debugging_opts.time_passes = true;
524     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
525     opts.debugging_opts.time_llvm_passes = true;
526     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
527     opts.debugging_opts.input_stats = true;
528     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
529     opts.debugging_opts.borrowck_stats = true;
530     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
531     opts.debugging_opts.meta_stats = true;
532     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
533     opts.debugging_opts.print_link_args = true;
534     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
535     opts.debugging_opts.print_llvm_passes = true;
536     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
537     opts.debugging_opts.ast_json = true;
538     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
539     opts.debugging_opts.ast_json_noexpand = true;
540     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
541     opts.debugging_opts.ls = true;
542     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
543     opts.debugging_opts.save_analysis = true;
544     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
545     opts.debugging_opts.print_region_graph = true;
546     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
547     opts.debugging_opts.parse_only = true;
548     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
549     opts.debugging_opts.incremental = Some(String::from("abc"));
550     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
551     opts.debugging_opts.dump_dep_graph = true;
552     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
553     opts.debugging_opts.query_dep_graph = true;
554     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
555     opts.debugging_opts.no_analysis = true;
556     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
557     opts.debugging_opts.unstable_options = true;
558     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
559     opts.debugging_opts.trace_macros = true;
560     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
561     opts.debugging_opts.keep_hygiene_data = true;
562     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
563     opts.debugging_opts.keep_ast = true;
564     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
565     opts.debugging_opts.print_mono_items = Some(String::from("abc"));
566     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
567     opts.debugging_opts.dump_mir = Some(String::from("abc"));
568     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
569     opts.debugging_opts.dump_mir_dir = String::from("abc");
570     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
571     opts.debugging_opts.dump_mir_graphviz = true;
572     assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
573
574     // Make sure changing a [TRACKED] option changes the hash
575     opts = reference.clone();
576     opts.debugging_opts.asm_comments = true;
577     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
578
579     opts = reference.clone();
580     opts.debugging_opts.verify_llvm_ir = true;
581     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
582
583     opts = reference.clone();
584     opts.debugging_opts.no_landing_pads = true;
585     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
586
587     opts = reference.clone();
588     opts.debugging_opts.fewer_names = true;
589     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
590
591     opts = reference.clone();
592     opts.debugging_opts.no_codegen = true;
593     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
594
595     opts = reference.clone();
596     opts.debugging_opts.treat_err_as_bug = Some(1);
597     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
598
599     opts = reference.clone();
600     opts.debugging_opts.report_delayed_bugs = true;
601     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
602
603     opts = reference.clone();
604     opts.debugging_opts.force_overflow_checks = Some(true);
605     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
606
607     opts = reference.clone();
608     opts.debugging_opts.show_span = Some(String::from("abc"));
609     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
610
611     opts = reference.clone();
612     opts.debugging_opts.mir_opt_level = 3;
613     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
614
615     opts = reference.clone();
616     opts.debugging_opts.relro_level = Some(RelroLevel::Full);
617     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
618
619     opts = reference.clone();
620     opts.debugging_opts.merge_functions = Some(MergeFunctions::Disabled);
621     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
622
623     opts = reference.clone();
624     opts.debugging_opts.allow_features = Some(vec![String::from("lang_items")]);
625     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
626
627     opts = reference.clone();
628     opts.debugging_opts.symbol_mangling_version = SymbolManglingVersion::V0;
629     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
630 }
631
632 #[test]
633 fn test_edition_parsing() {
634     // test default edition
635     let options = Options::default();
636     assert!(options.edition == DEFAULT_EDITION);
637
638     let matches = optgroups().parse(&["--edition=2018".to_string()]).unwrap();
639     let (sessopts, _) = build_session_options_and_crate_config(matches);
640     assert!(sessopts.edition == Edition::Edition2018)
641 }