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