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