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