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