1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! Contains infrastructure for configuring the compiler, including parsing
12 //! command line options.
14 pub use self::EntryFnType::*;
15 pub use self::CrateType::*;
16 pub use self::Passes::*;
17 pub use self::DebugInfoLevel::*;
19 use session::{early_error, early_warn, Session};
20 use session::search_paths::SearchPaths;
22 use rustc_back::{LinkerFlavor, PanicStrategy, RelroLevel};
23 use rustc_back::target::Target;
27 use syntax::ast::{self, IntTy, UintTy};
28 use syntax::codemap::FilePathMapping;
29 use syntax::parse::token;
31 use syntax::symbol::Symbol;
32 use syntax::feature_gate::UnstableFeatures;
34 use errors::{ColorConfig, FatalError, Handler};
37 use std::collections::{BTreeMap, BTreeSet};
38 use std::collections::btree_map::Iter as BTreeMapIter;
39 use std::collections::btree_map::Keys as BTreeMapKeysIter;
40 use std::collections::btree_map::Values as BTreeMapValuesIter;
43 use std::hash::Hasher;
44 use std::collections::hash_map::DefaultHasher;
45 use std::collections::HashSet;
46 use std::iter::FromIterator;
47 use std::path::PathBuf;
55 #[derive(Clone, Hash, Debug)]
63 #[derive(Clone, Copy, PartialEq, Hash)]
73 #[derive(Clone, Copy, PartialEq, Hash)]
74 pub enum DebugInfoLevel {
80 #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, PartialOrd, Ord,
81 RustcEncodable, RustcDecodable)]
94 fn is_compatible_with_codegen_units_and_single_output_file(&self) -> bool {
97 OutputType::DepInfo => true,
99 OutputType::Assembly |
100 OutputType::LlvmAssembly |
103 OutputType::Metadata => false,
107 fn shorthand(&self) -> &'static str {
109 OutputType::Bitcode => "llvm-bc",
110 OutputType::Assembly => "asm",
111 OutputType::LlvmAssembly => "llvm-ir",
112 OutputType::Mir => "mir",
113 OutputType::Object => "obj",
114 OutputType::Metadata => "metadata",
115 OutputType::Exe => "link",
116 OutputType::DepInfo => "dep-info",
120 pub fn extension(&self) -> &'static str {
122 OutputType::Bitcode => "bc",
123 OutputType::Assembly => "s",
124 OutputType::LlvmAssembly => "ll",
125 OutputType::Mir => "mir",
126 OutputType::Object => "o",
127 OutputType::Metadata => "rmeta",
128 OutputType::DepInfo => "d",
129 OutputType::Exe => "",
134 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
135 pub enum ErrorOutputType {
136 HumanReadable(ColorConfig),
140 impl Default for ErrorOutputType {
141 fn default() -> ErrorOutputType {
142 ErrorOutputType::HumanReadable(ColorConfig::Auto)
146 // Use tree-based collections to cheaply get a deterministic Hash implementation.
147 // DO NOT switch BTreeMap out for an unsorted container type! That would break
148 // dependency tracking for commandline arguments.
149 #[derive(Clone, Hash)]
150 pub struct OutputTypes(BTreeMap<OutputType, Option<PathBuf>>);
153 pub fn new(entries: &[(OutputType, Option<PathBuf>)]) -> OutputTypes {
154 OutputTypes(BTreeMap::from_iter(entries.iter()
155 .map(|&(k, ref v)| (k, v.clone()))))
158 pub fn get(&self, key: &OutputType) -> Option<&Option<PathBuf>> {
162 pub fn contains_key(&self, key: &OutputType) -> bool {
163 self.0.contains_key(key)
166 pub fn keys<'a>(&'a self) -> BTreeMapKeysIter<'a, OutputType, Option<PathBuf>> {
170 pub fn values<'a>(&'a self) -> BTreeMapValuesIter<'a, OutputType, Option<PathBuf>> {
174 // True if any of the output types require codegen or linking.
175 pub fn should_trans(&self) -> bool {
176 self.0.keys().any(|k| match *k {
177 OutputType::Bitcode |
178 OutputType::Assembly |
179 OutputType::LlvmAssembly |
182 OutputType::Exe => true,
183 OutputType::Metadata |
184 OutputType::DepInfo => false,
190 // Use tree-based collections to cheaply get a deterministic Hash implementation.
191 // DO NOT switch BTreeMap or BTreeSet out for an unsorted container type! That
192 // would break dependency tracking for commandline arguments.
193 #[derive(Clone, Hash)]
194 pub struct Externs(BTreeMap<String, BTreeSet<String>>);
197 pub fn new(data: BTreeMap<String, BTreeSet<String>>) -> Externs {
201 pub fn get(&self, key: &str) -> Option<&BTreeSet<String>> {
205 pub fn iter<'a>(&'a self) -> BTreeMapIter<'a, String, BTreeSet<String>> {
210 macro_rules! hash_option {
211 ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, [UNTRACKED]) => ({});
212 ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, [TRACKED]) => ({
213 if $sub_hashes.insert(stringify!($opt_name),
214 $opt_expr as &dep_tracking::DepTrackingHash).is_some() {
215 bug!("Duplicate key in CLI DepTrackingHash: {}", stringify!($opt_name))
221 [UNTRACKED_WITH_WARNING $warn_val:expr, $warn_text:expr, $error_format:expr]) => ({
222 if *$opt_expr == $warn_val {
223 early_warn($error_format, $warn_text)
228 macro_rules! top_level_options {
229 (pub struct Options { $(
230 $opt:ident : $t:ty [$dep_tracking_marker:ident $($warn_val:expr, $warn_text:expr)*],
238 pub fn dep_tracking_hash(&self) -> u64 {
239 let mut sub_hashes = BTreeMap::new();
244 [$dep_tracking_marker $($warn_val,
246 self.error_format)*]);
248 let mut hasher = DefaultHasher::new();
249 dep_tracking::stable_hash(sub_hashes,
258 // The top-level commandline options struct
260 // For each option, one has to specify how it behaves with regard to the
261 // dependency tracking system of incremental compilation. This is done via the
262 // square-bracketed directive after the field type. The options are:
265 // A change in the given field will cause the compiler to completely clear the
266 // incremental compilation cache before proceeding.
269 // Incremental compilation is not influenced by this option.
271 // [UNTRACKED_WITH_WARNING(val, warning)]
272 // The option is incompatible with incremental compilation in some way. If it
273 // has the value `val`, the string `warning` is emitted as a warning.
275 // If you add a new option to this struct or one of the sub-structs like
276 // CodegenOptions, think about how it influences incremental compilation. If in
277 // doubt, specify [TRACKED], which is always "correct" but might lead to
278 // unnecessary re-compilation.
281 // The crate config requested for the session, which may be combined
282 // with additional crate configurations during the compile process
283 crate_types: Vec<CrateType> [TRACKED],
284 optimize: OptLevel [TRACKED],
285 // Include the debug_assertions flag into dependency tracking, since it
286 // can influence whether overflow checks are done or not.
287 debug_assertions: bool [TRACKED],
288 debuginfo: DebugInfoLevel [TRACKED],
289 lint_opts: Vec<(String, lint::Level)> [TRACKED],
290 lint_cap: Option<lint::Level> [TRACKED],
291 describe_lints: bool [UNTRACKED],
292 output_types: OutputTypes [TRACKED],
293 // FIXME(mw): We track this for now but it actually doesn't make too
294 // much sense: The search path can stay the same while the
295 // things discovered there might have changed on disk.
296 search_paths: SearchPaths [TRACKED],
297 libs: Vec<(String, Option<String>, Option<cstore::NativeLibraryKind>)> [TRACKED],
298 maybe_sysroot: Option<PathBuf> [TRACKED],
300 target_triple: String [TRACKED],
302 test: bool [TRACKED],
303 error_format: ErrorOutputType [UNTRACKED],
305 // if Some, enable incremental compilation, using the given
306 // directory to store intermediate results
307 incremental: Option<PathBuf> [UNTRACKED],
309 debugging_opts: DebuggingOptions [TRACKED],
310 prints: Vec<PrintRequest> [UNTRACKED],
311 cg: CodegenOptions [TRACKED],
312 // FIXME(mw): We track this for now but it actually doesn't make too
313 // much sense: The value of this option can stay the same
314 // while the files they refer to might have changed on disk.
315 externs: Externs [TRACKED],
316 crate_name: Option<String> [TRACKED],
317 // An optional name to use as the crate for std during std injection,
318 // written `extern crate std = "name"`. Default to "std". Used by
319 // out-of-tree drivers.
320 alt_std_name: Option<String> [TRACKED],
321 // Indicates how the compiler should treat unstable features
322 unstable_features: UnstableFeatures [TRACKED],
324 // Indicates whether this run of the compiler is actually rustdoc. This
325 // is currently just a hack and will be removed eventually, so please
326 // try to not rely on this too much.
327 actually_rustdoc: bool [TRACKED],
331 #[derive(Copy, Clone, PartialEq, Eq, Debug)]
332 pub enum PrintRequest {
347 /// Load source from file
350 /// String that is shown in place of a filename
352 /// Anonymous source string
358 pub fn filestem(&self) -> String {
360 Input::File(ref ifile) => ifile.file_stem().unwrap()
361 .to_str().unwrap().to_string(),
362 Input::Str { .. } => "rust_out".to_string(),
368 pub struct OutputFilenames {
369 pub out_directory: PathBuf,
370 pub out_filestem: String,
371 pub single_output_file: Option<PathBuf>,
373 pub outputs: OutputTypes,
376 /// Codegen unit names generated by the numbered naming scheme will contain this
377 /// marker right before the index of the codegen unit.
378 pub const NUMBERED_CODEGEN_UNIT_MARKER: &'static str = ".cgu-";
380 impl OutputFilenames {
381 pub fn path(&self, flavor: OutputType) -> PathBuf {
382 self.outputs.get(&flavor).and_then(|p| p.to_owned())
383 .or_else(|| self.single_output_file.clone())
384 .unwrap_or_else(|| self.temp_path(flavor, None))
387 /// Get the path where a compilation artifact of the given type for the
388 /// given codegen unit should be placed on disk. If codegen_unit_name is
389 /// None, a path distinct from those of any codegen unit will be generated.
390 pub fn temp_path(&self,
392 codegen_unit_name: Option<&str>)
394 let extension = flavor.extension();
395 self.temp_path_ext(extension, codegen_unit_name)
398 /// Like temp_path, but also supports things where there is no corresponding
399 /// OutputType, like no-opt-bitcode or lto-bitcode.
400 pub fn temp_path_ext(&self,
402 codegen_unit_name: Option<&str>)
404 let base = self.out_directory.join(&self.filestem());
406 let mut extension = String::new();
408 if let Some(codegen_unit_name) = codegen_unit_name {
409 if codegen_unit_name.contains(NUMBERED_CODEGEN_UNIT_MARKER) {
410 // If we use the numbered naming scheme for modules, we don't want
411 // the files to look like <crate-name><extra>.<crate-name>.<index>.<ext>
412 // but simply <crate-name><extra>.<index>.<ext>
413 let marker_offset = codegen_unit_name.rfind(NUMBERED_CODEGEN_UNIT_MARKER)
415 let index_offset = marker_offset + NUMBERED_CODEGEN_UNIT_MARKER.len();
416 extension.push_str(&codegen_unit_name[index_offset .. ]);
418 extension.push_str(codegen_unit_name);
423 if !extension.is_empty() {
424 extension.push_str(".");
427 extension.push_str(ext);
430 let path = base.with_extension(&extension[..]);
434 pub fn with_extension(&self, extension: &str) -> PathBuf {
435 self.out_directory.join(&self.filestem()).with_extension(extension)
438 pub fn filestem(&self) -> String {
439 format!("{}{}", self.out_filestem, self.extra)
443 pub fn host_triple() -> &'static str {
444 // Get the host triple out of the build environment. This ensures that our
445 // idea of the host triple is the same as for the set of libraries we've
446 // actually built. We can't just take LLVM's host triple because they
447 // normalize all ix86 architectures to i386.
449 // Instead of grabbing the host triple (for the current host), we grab (at
450 // compile time) the target triple that this rustc is built with and
451 // calling that (at runtime) the host triple.
452 (option_env!("CFG_COMPILER_HOST_TRIPLE")).
453 expect("CFG_COMPILER_HOST_TRIPLE")
456 /// Some reasonable defaults
457 pub fn basic_options() -> Options {
459 crate_types: Vec::new(),
460 optimize: OptLevel::No,
461 debuginfo: NoDebugInfo,
462 lint_opts: Vec::new(),
464 describe_lints: false,
465 output_types: OutputTypes(BTreeMap::new()),
466 search_paths: SearchPaths::new(),
468 target_triple: host_triple().to_string(),
471 debugging_opts: basic_debugging_options(),
473 cg: basic_codegen_options(),
474 error_format: ErrorOutputType::default(),
475 externs: Externs(BTreeMap::new()),
479 unstable_features: UnstableFeatures::Disallow,
480 debug_assertions: true,
481 actually_rustdoc: false,
486 /// True if there is a reason to build the dep graph.
487 pub fn build_dep_graph(&self) -> bool {
488 self.incremental.is_some() ||
489 self.debugging_opts.dump_dep_graph ||
490 self.debugging_opts.query_dep_graph
494 pub fn enable_dep_node_debug_strs(&self) -> bool {
495 cfg!(debug_assertions) &&
496 (self.debugging_opts.query_dep_graph || self.debugging_opts.incremental_info)
499 pub fn single_codegen_unit(&self) -> bool {
500 self.incremental.is_none() ||
501 self.cg.codegen_units == 1
504 pub fn file_path_mapping(&self) -> FilePathMapping {
505 FilePathMapping::new(
506 self.debugging_opts.remap_path_prefix_from.iter().zip(
507 self.debugging_opts.remap_path_prefix_to.iter()
508 ).map(|(src, dst)| (src.clone(), dst.clone())).collect()
513 // The type of entry function, so
514 // users can have their own entry
515 // functions that don't start a
517 #[derive(Copy, Clone, PartialEq)]
518 pub enum EntryFnType {
524 #[derive(Copy, PartialEq, PartialOrd, Clone, Ord, Eq, Hash, Debug)]
534 #[derive(Clone, Hash)]
536 SomePasses(Vec<String>),
541 pub fn is_empty(&self) -> bool {
543 SomePasses(ref v) => v.is_empty(),
549 /// Declare a macro that will define all CodegenOptions/DebuggingOptions fields and parsers all
550 /// at once. The goal of this macro is to define an interface that can be
551 /// programmatically used by the option parser in order to initialize the struct
552 /// without hardcoding field names all over the place.
554 /// The goal is to invoke this macro once with the correct fields, and then this
555 /// macro generates all necessary code. The main gotcha of this macro is the
556 /// cgsetters module which is a bunch of generated code to parse an option into
557 /// its respective field in the struct. There are a few hand-written parsers for
558 /// parsing specific types of values in this module.
559 macro_rules! options {
560 ($struct_name:ident, $setter_name:ident, $defaultfn:ident,
561 $buildfn:ident, $prefix:expr, $outputname:expr,
562 $stat:ident, $mod_desc:ident, $mod_set:ident,
563 $($opt:ident : $t:ty = (
566 [$dep_tracking_marker:ident $(($dep_warn_val:expr, $dep_warn_text:expr))*],
571 pub struct $struct_name { $(pub $opt: $t),* }
573 pub fn $defaultfn() -> $struct_name {
574 $struct_name { $($opt: $init),* }
577 pub fn $buildfn(matches: &getopts::Matches, error_format: ErrorOutputType) -> $struct_name
579 let mut op = $defaultfn();
580 for option in matches.opt_strs($prefix) {
581 let mut iter = option.splitn(2, '=');
582 let key = iter.next().unwrap();
583 let value = iter.next();
584 let option_to_lookup = key.replace("-", "_");
585 let mut found = false;
586 for &(candidate, setter, opt_type_desc, _) in $stat {
587 if option_to_lookup != candidate { continue }
588 if !setter(&mut op, value) {
589 match (value, opt_type_desc) {
590 (Some(..), None) => {
591 early_error(error_format, &format!("{} option `{}` takes no \
592 value", $outputname, key))
594 (None, Some(type_desc)) => {
595 early_error(error_format, &format!("{0} option `{1}` requires \
596 {2} ({3} {1}=<value>)",
600 (Some(value), Some(type_desc)) => {
601 early_error(error_format, &format!("incorrect value `{}` for {} \
602 option `{}` - {} was expected",
606 (None, None) => bug!()
613 early_error(error_format, &format!("unknown {} option: `{}`",
620 impl<'a> dep_tracking::DepTrackingHash for $struct_name {
622 fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) {
623 let mut sub_hashes = BTreeMap::new();
628 [$dep_tracking_marker $($dep_warn_val,
632 dep_tracking::stable_hash(sub_hashes, hasher, error_format);
636 pub type $setter_name = fn(&mut $struct_name, v: Option<&str>) -> bool;
637 pub const $stat: &'static [(&'static str, $setter_name,
638 Option<&'static str>, &'static str)] =
639 &[ $( (stringify!($opt), $mod_set::$opt, $mod_desc::$parse, $desc) ),* ];
641 #[allow(non_upper_case_globals, dead_code)]
643 pub const parse_bool: Option<&'static str> = None;
644 pub const parse_opt_bool: Option<&'static str> =
645 Some("one of: `y`, `yes`, `on`, `n`, `no`, or `off`");
646 pub const parse_string: Option<&'static str> = Some("a string");
647 pub const parse_string_push: Option<&'static str> = Some("a string");
648 pub const parse_opt_string: Option<&'static str> = Some("a string");
649 pub const parse_list: Option<&'static str> = Some("a space-separated list of strings");
650 pub const parse_opt_list: Option<&'static str> = Some("a space-separated list of strings");
651 pub const parse_uint: Option<&'static str> = Some("a number");
652 pub const parse_passes: Option<&'static str> =
653 Some("a space-separated list of passes, or `all`");
654 pub const parse_opt_uint: Option<&'static str> =
656 pub const parse_panic_strategy: Option<&'static str> =
657 Some("either `panic` or `abort`");
658 pub const parse_relro_level: Option<&'static str> =
659 Some("one of: `full`, `partial`, or `off`");
660 pub const parse_sanitizer: Option<&'static str> =
661 Some("one of: `address`, `leak`, `memory` or `thread`");
662 pub const parse_linker_flavor: Option<&'static str> =
663 Some(::rustc_back::LinkerFlavor::one_of());
664 pub const parse_optimization_fuel: Option<&'static str> =
665 Some("crate=integer");
670 use super::{$struct_name, Passes, SomePasses, AllPasses, Sanitizer};
671 use rustc_back::{LinkerFlavor, PanicStrategy, RelroLevel};
674 pub fn $opt(cg: &mut $struct_name, v: Option<&str>) -> bool {
675 $parse(&mut cg.$opt, v)
679 fn parse_bool(slot: &mut bool, v: Option<&str>) -> bool {
682 None => { *slot = true; true }
686 fn parse_opt_bool(slot: &mut Option<bool>, v: Option<&str>) -> bool {
690 "n" | "no" | "off" => {
693 "y" | "yes" | "on" => {
696 _ => { return false; }
701 None => { *slot = Some(true); true }
705 fn parse_opt_string(slot: &mut Option<String>, v: Option<&str>) -> bool {
707 Some(s) => { *slot = Some(s.to_string()); true },
712 fn parse_string(slot: &mut String, v: Option<&str>) -> bool {
714 Some(s) => { *slot = s.to_string(); true },
719 fn parse_string_push(slot: &mut Vec<String>, v: Option<&str>) -> bool {
721 Some(s) => { slot.push(s.to_string()); true },
726 fn parse_list(slot: &mut Vec<String>, v: Option<&str>)
730 for s in s.split_whitespace() {
731 slot.push(s.to_string());
739 fn parse_opt_list(slot: &mut Option<Vec<String>>, v: Option<&str>)
743 let v = s.split_whitespace().map(|s| s.to_string()).collect();
751 fn parse_uint(slot: &mut usize, v: Option<&str>) -> bool {
752 match v.and_then(|s| s.parse().ok()) {
753 Some(i) => { *slot = i; true },
758 fn parse_opt_uint(slot: &mut Option<usize>, v: Option<&str>) -> bool {
760 Some(s) => { *slot = s.parse().ok(); slot.is_some() }
761 None => { *slot = None; true }
765 fn parse_passes(slot: &mut Passes, v: Option<&str>) -> bool {
772 let mut passes = vec![];
773 if parse_list(&mut passes, v) {
774 *slot = SomePasses(passes);
783 fn parse_panic_strategy(slot: &mut Option<PanicStrategy>, v: Option<&str>) -> bool {
785 Some("unwind") => *slot = Some(PanicStrategy::Unwind),
786 Some("abort") => *slot = Some(PanicStrategy::Abort),
792 fn parse_relro_level(slot: &mut Option<RelroLevel>, v: Option<&str>) -> bool {
795 match s.parse::<RelroLevel>() {
796 Ok(level) => *slot = Some(level),
805 fn parse_sanitizer(slote: &mut Option<Sanitizer>, v: Option<&str>) -> bool {
807 Some("address") => *slote = Some(Sanitizer::Address),
808 Some("leak") => *slote = Some(Sanitizer::Leak),
809 Some("memory") => *slote = Some(Sanitizer::Memory),
810 Some("thread") => *slote = Some(Sanitizer::Thread),
816 fn parse_linker_flavor(slote: &mut Option<LinkerFlavor>, v: Option<&str>) -> bool {
817 match v.and_then(LinkerFlavor::from_str) {
818 Some(lf) => *slote = Some(lf),
824 fn parse_optimization_fuel(slot: &mut Option<(String, u64)>, v: Option<&str>) -> bool {
828 let parts = s.split('=').collect::<Vec<_>>();
829 if parts.len() != 2 { return false; }
830 let crate_name = parts[0].to_string();
831 let fuel = parts[1].parse::<u64>();
832 if fuel.is_err() { return false; }
833 *slot = Some((crate_name, fuel.unwrap()));
841 options! {CodegenOptions, CodegenSetter, basic_codegen_options,
842 build_codegen_options, "C", "codegen",
843 CG_OPTIONS, cg_type_desc, cgsetters,
844 ar: Option<String> = (None, parse_opt_string, [UNTRACKED],
845 "tool to assemble archives with"),
846 linker: Option<String> = (None, parse_opt_string, [UNTRACKED],
847 "system linker to link outputs with"),
848 link_arg: Vec<String> = (vec![], parse_string_push, [UNTRACKED],
849 "a single extra argument to append to the linker invocation (can be used several times)"),
850 link_args: Option<Vec<String>> = (None, parse_opt_list, [UNTRACKED],
851 "extra arguments to append to the linker invocation (space separated)"),
852 link_dead_code: bool = (false, parse_bool, [UNTRACKED],
853 "don't let linker strip dead code (turning it on can be used for code coverage)"),
854 lto: bool = (false, parse_bool, [TRACKED],
855 "perform LLVM link-time optimizations"),
856 target_cpu: Option<String> = (None, parse_opt_string, [TRACKED],
857 "select target processor (rustc --print target-cpus for details)"),
858 target_feature: String = ("".to_string(), parse_string, [TRACKED],
859 "target specific attributes (rustc --print target-features for details)"),
860 passes: Vec<String> = (Vec::new(), parse_list, [TRACKED],
861 "a list of extra LLVM passes to run (space separated)"),
862 llvm_args: Vec<String> = (Vec::new(), parse_list, [TRACKED],
863 "a list of arguments to pass to llvm (space separated)"),
864 save_temps: bool = (false, parse_bool, [UNTRACKED_WITH_WARNING(true,
865 "`-C save-temps` might not produce all requested temporary products \
866 when incremental compilation is enabled.")],
867 "save all temporary output files during compilation"),
868 rpath: bool = (false, parse_bool, [UNTRACKED],
869 "set rpath values in libs/exes"),
870 overflow_checks: Option<bool> = (None, parse_opt_bool, [TRACKED],
871 "use overflow checks for integer arithmetic"),
872 no_prepopulate_passes: bool = (false, parse_bool, [TRACKED],
873 "don't pre-populate the pass manager with a list of passes"),
874 no_vectorize_loops: bool = (false, parse_bool, [TRACKED],
875 "don't run the loop vectorization optimization passes"),
876 no_vectorize_slp: bool = (false, parse_bool, [TRACKED],
877 "don't run LLVM's SLP vectorization pass"),
878 soft_float: bool = (false, parse_bool, [TRACKED],
879 "use soft float ABI (*eabihf targets only)"),
880 prefer_dynamic: bool = (false, parse_bool, [TRACKED],
881 "prefer dynamic linking to static linking"),
882 no_integrated_as: bool = (false, parse_bool, [TRACKED],
883 "use an external assembler rather than LLVM's integrated one"),
884 no_redzone: Option<bool> = (None, parse_opt_bool, [TRACKED],
885 "disable the use of the redzone"),
886 relocation_model: Option<String> = (None, parse_opt_string, [TRACKED],
887 "choose the relocation model to use (rustc --print relocation-models for details)"),
888 code_model: Option<String> = (None, parse_opt_string, [TRACKED],
889 "choose the code model to use (rustc --print code-models for details)"),
890 metadata: Vec<String> = (Vec::new(), parse_list, [TRACKED],
891 "metadata to mangle symbol names with"),
892 extra_filename: String = ("".to_string(), parse_string, [UNTRACKED],
893 "extra data to put in each output filename"),
894 codegen_units: usize = (1, parse_uint, [UNTRACKED],
895 "divide crate into N units to optimize in parallel"),
896 remark: Passes = (SomePasses(Vec::new()), parse_passes, [UNTRACKED],
897 "print remarks for these optimization passes (space separated, or \"all\")"),
898 no_stack_check: bool = (false, parse_bool, [UNTRACKED],
899 "the --no-stack-check flag is deprecated and does nothing"),
900 debuginfo: Option<usize> = (None, parse_opt_uint, [TRACKED],
901 "debug info emission level, 0 = no debug info, 1 = line tables only, \
902 2 = full debug info with variable and type information"),
903 opt_level: Option<String> = (None, parse_opt_string, [TRACKED],
904 "optimize with possible levels 0-3, s, or z"),
905 debug_assertions: Option<bool> = (None, parse_opt_bool, [TRACKED],
906 "explicitly enable the cfg(debug_assertions) directive"),
907 inline_threshold: Option<usize> = (None, parse_opt_uint, [TRACKED],
908 "set the inlining threshold for"),
909 panic: Option<PanicStrategy> = (None, parse_panic_strategy,
910 [TRACKED], "panic strategy to compile crate with"),
913 options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
914 build_debugging_options, "Z", "debugging",
915 DB_OPTIONS, db_type_desc, dbsetters,
916 verbose: bool = (false, parse_bool, [UNTRACKED],
917 "in general, enable more debug printouts"),
918 span_free_formats: bool = (false, parse_bool, [UNTRACKED],
919 "when debug-printing compiler state, do not include spans"), // o/w tests have closure@path
920 identify_regions: bool = (false, parse_bool, [UNTRACKED],
921 "make unnamed regions display as '# (where # is some non-ident unique id)"),
922 emit_end_regions: bool = (false, parse_bool, [UNTRACKED],
923 "emit EndRegion as part of MIR; enable transforms that solely process EndRegion"),
924 borrowck_mir: bool = (false, parse_bool, [UNTRACKED],
925 "implicitly treat functions as if they have `#[rustc_mir_borrowck]` attribute"),
926 time_passes: bool = (false, parse_bool, [UNTRACKED],
927 "measure time of each rustc pass"),
928 count_llvm_insns: bool = (false, parse_bool,
929 [UNTRACKED_WITH_WARNING(true,
930 "The output generated by `-Z count_llvm_insns` might not be reliable \
931 when used with incremental compilation")],
932 "count where LLVM instrs originate"),
933 time_llvm_passes: bool = (false, parse_bool, [UNTRACKED_WITH_WARNING(true,
934 "The output of `-Z time-llvm-passes` will only reflect timings of \
935 re-translated modules when used with incremental compilation" )],
936 "measure time of each LLVM pass"),
937 input_stats: bool = (false, parse_bool, [UNTRACKED],
938 "gather statistics about the input"),
939 trans_stats: bool = (false, parse_bool, [UNTRACKED_WITH_WARNING(true,
940 "The output of `-Z trans-stats` might not be accurate when incremental \
941 compilation is enabled")],
942 "gather trans statistics"),
943 asm_comments: bool = (false, parse_bool, [TRACKED],
944 "generate comments into the assembly (may change behavior)"),
945 no_verify: bool = (false, parse_bool, [TRACKED],
946 "skip LLVM verification"),
947 borrowck_stats: bool = (false, parse_bool, [UNTRACKED],
948 "gather borrowck statistics"),
949 no_landing_pads: bool = (false, parse_bool, [TRACKED],
950 "omit landing pads for unwinding"),
951 debug_llvm: bool = (false, parse_bool, [UNTRACKED],
952 "enable debug output from LLVM"),
953 meta_stats: bool = (false, parse_bool, [UNTRACKED],
954 "gather metadata statistics"),
955 print_link_args: bool = (false, parse_bool, [UNTRACKED],
956 "print the arguments passed to the linker"),
957 print_llvm_passes: bool = (false, parse_bool, [UNTRACKED],
958 "prints the llvm optimization passes being run"),
959 ast_json: bool = (false, parse_bool, [UNTRACKED],
960 "print the AST as JSON and halt"),
961 ast_json_noexpand: bool = (false, parse_bool, [UNTRACKED],
962 "print the pre-expansion AST as JSON and halt"),
963 ls: bool = (false, parse_bool, [UNTRACKED],
964 "list the symbols defined by a library crate"),
965 save_analysis: bool = (false, parse_bool, [UNTRACKED],
966 "write syntax and type analysis (in JSON format) information, in \
967 addition to normal output"),
968 print_move_fragments: bool = (false, parse_bool, [UNTRACKED],
969 "print out move-fragment data for every fn"),
970 flowgraph_print_loans: bool = (false, parse_bool, [UNTRACKED],
971 "include loan analysis data in --unpretty flowgraph output"),
972 flowgraph_print_moves: bool = (false, parse_bool, [UNTRACKED],
973 "include move analysis data in --unpretty flowgraph output"),
974 flowgraph_print_assigns: bool = (false, parse_bool, [UNTRACKED],
975 "include assignment analysis data in --unpretty flowgraph output"),
976 flowgraph_print_all: bool = (false, parse_bool, [UNTRACKED],
977 "include all dataflow analysis data in --unpretty flowgraph output"),
978 print_region_graph: bool = (false, parse_bool, [UNTRACKED],
979 "prints region inference graph. \
980 Use with RUST_REGION_GRAPH=help for more info"),
981 parse_only: bool = (false, parse_bool, [UNTRACKED],
982 "parse only; do not compile, assemble, or link"),
983 no_trans: bool = (false, parse_bool, [TRACKED],
984 "run all passes except translation; no output"),
985 treat_err_as_bug: bool = (false, parse_bool, [TRACKED],
986 "treat all errors that occur as bugs"),
987 continue_parse_after_error: bool = (false, parse_bool, [TRACKED],
988 "attempt to recover from parse errors (experimental)"),
989 incremental: Option<String> = (None, parse_opt_string, [UNTRACKED],
990 "enable incremental compilation (experimental)"),
991 incremental_cc: bool = (true, parse_bool, [UNTRACKED],
992 "enable cross-crate incremental compilation (even more experimental)"),
993 incremental_info: bool = (false, parse_bool, [UNTRACKED],
994 "print high-level information about incremental reuse (or the lack thereof)"),
995 incremental_dump_hash: bool = (false, parse_bool, [UNTRACKED],
996 "dump hash information in textual format to stdout"),
997 dump_dep_graph: bool = (false, parse_bool, [UNTRACKED],
998 "dump the dependency graph to $RUST_DEP_GRAPH (default: /tmp/dep_graph.gv)"),
999 query_dep_graph: bool = (false, parse_bool, [UNTRACKED],
1000 "enable queries of the dependency graph for regression testing"),
1001 profile_queries: bool = (false, parse_bool, [UNTRACKED],
1002 "trace and profile the queries of the incremental compilation framework"),
1003 profile_queries_and_keys: bool = (false, parse_bool, [UNTRACKED],
1004 "trace and profile the queries and keys of the incremental compilation framework"),
1005 no_analysis: bool = (false, parse_bool, [UNTRACKED],
1006 "parse and expand the source, but run no analysis"),
1007 extra_plugins: Vec<String> = (Vec::new(), parse_list, [TRACKED],
1008 "load extra plugins"),
1009 unstable_options: bool = (false, parse_bool, [UNTRACKED],
1010 "adds unstable command line options to rustc interface"),
1011 force_overflow_checks: Option<bool> = (None, parse_opt_bool, [TRACKED],
1012 "force overflow checks on or off"),
1013 trace_macros: bool = (false, parse_bool, [UNTRACKED],
1014 "for every macro invocation, print its name and arguments"),
1015 debug_macros: bool = (false, parse_bool, [TRACKED],
1016 "emit line numbers debug info inside macros"),
1017 enable_nonzeroing_move_hints: bool = (false, parse_bool, [TRACKED],
1018 "force nonzeroing move optimization on"),
1019 keep_hygiene_data: bool = (false, parse_bool, [UNTRACKED],
1020 "don't clear the hygiene data after analysis"),
1021 keep_ast: bool = (false, parse_bool, [UNTRACKED],
1022 "keep the AST after lowering it to HIR"),
1023 show_span: Option<String> = (None, parse_opt_string, [TRACKED],
1024 "show spans for compiler debugging (expr|pat|ty)"),
1025 print_type_sizes: bool = (false, parse_bool, [UNTRACKED],
1026 "print layout information for each type encountered"),
1027 print_trans_items: Option<String> = (None, parse_opt_string, [UNTRACKED],
1028 "print the result of the translation item collection pass"),
1029 mir_opt_level: usize = (1, parse_uint, [TRACKED],
1030 "set the MIR optimization level (0-3, default: 1)"),
1031 dump_mir: Option<String> = (None, parse_opt_string, [UNTRACKED],
1032 "dump MIR state at various points in translation"),
1033 dump_mir_dir: Option<String> = (None, parse_opt_string, [UNTRACKED],
1034 "the directory the MIR is dumped into"),
1035 dump_mir_exclude_pass_number: bool = (false, parse_bool, [UNTRACKED],
1036 "if set, exclude the pass number when dumping MIR (used in tests)"),
1037 mir_emit_validate: usize = (0, parse_uint, [TRACKED],
1038 "emit Validate MIR statements, interpreted e.g. by miri (0: do not emit; 1: if function \
1039 contains unsafe block, only validate arguments; 2: always emit full validation)"),
1040 perf_stats: bool = (false, parse_bool, [UNTRACKED],
1041 "print some performance-related statistics"),
1042 hir_stats: bool = (false, parse_bool, [UNTRACKED],
1043 "print some statistics about AST and HIR"),
1044 mir_stats: bool = (false, parse_bool, [UNTRACKED],
1045 "print some statistics about MIR"),
1046 always_encode_mir: bool = (false, parse_bool, [TRACKED],
1047 "encode MIR of all functions into the crate metadata"),
1048 osx_rpath_install_name: bool = (false, parse_bool, [TRACKED],
1049 "pass `-install_name @rpath/...` to the macOS linker"),
1050 sanitizer: Option<Sanitizer> = (None, parse_sanitizer, [TRACKED],
1052 linker_flavor: Option<LinkerFlavor> = (None, parse_linker_flavor, [UNTRACKED],
1054 fuel: Option<(String, u64)> = (None, parse_optimization_fuel, [TRACKED],
1055 "Set the optimization fuel quota for a crate."),
1056 print_fuel: Option<String> = (None, parse_opt_string, [TRACKED],
1057 "Make Rustc print the total optimization fuel used by a crate."),
1058 remap_path_prefix_from: Vec<String> = (vec![], parse_string_push, [TRACKED],
1059 "add a source pattern to the file path remapping config"),
1060 remap_path_prefix_to: Vec<String> = (vec![], parse_string_push, [TRACKED],
1061 "add a mapping target to the file path remapping config"),
1062 force_unstable_if_unmarked: bool = (false, parse_bool, [TRACKED],
1063 "force all crates to be `rustc_private` unstable"),
1064 pre_link_arg: Vec<String> = (vec![], parse_string_push, [UNTRACKED],
1065 "a single extra argument to prepend the linker invocation (can be used several times)"),
1066 pre_link_args: Option<Vec<String>> = (None, parse_opt_list, [UNTRACKED],
1067 "extra arguments to prepend to the linker invocation (space separated)"),
1068 profile: bool = (false, parse_bool, [TRACKED],
1069 "insert profiling code"),
1070 relro_level: Option<RelroLevel> = (None, parse_relro_level, [TRACKED],
1071 "choose which RELRO level to use"),
1072 nll: bool = (false, parse_bool, [UNTRACKED],
1073 "run the non-lexical lifetimes MIR pass"),
1074 trans_time_graph: bool = (false, parse_bool, [UNTRACKED],
1075 "generate a graphical HTML report of time spent in trans and LLVM"),
1078 pub fn default_lib_output() -> CrateType {
1082 pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
1083 let end = &sess.target.target.target_endian;
1084 let arch = &sess.target.target.arch;
1085 let wordsz = &sess.target.target.target_pointer_width;
1086 let os = &sess.target.target.target_os;
1087 let env = &sess.target.target.target_env;
1088 let vendor = &sess.target.target.target_vendor;
1089 let min_atomic_width = sess.target.target.min_atomic_width();
1090 let max_atomic_width = sess.target.target.max_atomic_width();
1092 let mut ret = HashSet::new();
1094 ret.insert((Symbol::intern("target_os"), Some(Symbol::intern(os))));
1095 if let Some(ref fam) = sess.target.target.options.target_family {
1096 ret.insert((Symbol::intern("target_family"), Some(Symbol::intern(fam))));
1097 if fam == "windows" || fam == "unix" {
1098 ret.insert((Symbol::intern(fam), None));
1101 ret.insert((Symbol::intern("target_arch"), Some(Symbol::intern(arch))));
1102 ret.insert((Symbol::intern("target_endian"), Some(Symbol::intern(end))));
1103 ret.insert((Symbol::intern("target_pointer_width"), Some(Symbol::intern(wordsz))));
1104 ret.insert((Symbol::intern("target_env"), Some(Symbol::intern(env))));
1105 ret.insert((Symbol::intern("target_vendor"), Some(Symbol::intern(vendor))));
1106 if sess.target.target.options.has_elf_tls {
1107 ret.insert((Symbol::intern("target_thread_local"), None));
1109 for &i in &[8, 16, 32, 64, 128] {
1110 if i >= min_atomic_width && i <= max_atomic_width {
1111 let s = i.to_string();
1112 ret.insert((Symbol::intern("target_has_atomic"), Some(Symbol::intern(&s))));
1114 ret.insert((Symbol::intern("target_has_atomic"), Some(Symbol::intern("ptr"))));
1118 if sess.opts.debug_assertions {
1119 ret.insert((Symbol::intern("debug_assertions"), None));
1121 if sess.opts.crate_types.contains(&CrateTypeProcMacro) {
1122 ret.insert((Symbol::intern("proc_macro"), None));
1127 pub fn build_configuration(sess: &Session,
1128 mut user_cfg: ast::CrateConfig)
1129 -> ast::CrateConfig {
1130 // Combine the configuration requested by the session (command line) with
1131 // some default and generated configuration items
1132 let default_cfg = default_configuration(sess);
1133 // If the user wants a test runner, then add the test cfg
1135 user_cfg.insert((Symbol::intern("test"), None));
1137 user_cfg.extend(default_cfg.iter().cloned());
1141 pub fn build_target_config(opts: &Options, sp: &Handler) -> Config {
1142 let target = match Target::search(&opts.target_triple) {
1145 sp.struct_fatal(&format!("Error loading target specification: {}", e))
1146 .help("Use `--print target-list` for a list of built-in targets")
1152 let (isize_ty, usize_ty) = match &target.target_pointer_width[..] {
1153 "16" => (ast::IntTy::I16, ast::UintTy::U16),
1154 "32" => (ast::IntTy::I32, ast::UintTy::U32),
1155 "64" => (ast::IntTy::I64, ast::UintTy::U64),
1156 w => panic!(sp.fatal(&format!("target specification was invalid: \
1157 unrecognized target-pointer-width {}", w))),
1167 #[derive(Copy, Clone, PartialEq, Eq, Debug)]
1168 pub enum OptionStability {
1174 pub struct RustcOptGroup {
1175 pub apply: Box<Fn(&mut getopts::Options) -> &mut getopts::Options>,
1176 pub name: &'static str,
1177 pub stability: OptionStability,
1180 impl RustcOptGroup {
1181 pub fn is_stable(&self) -> bool {
1182 self.stability == OptionStability::Stable
1185 pub fn stable<F>(name: &'static str, f: F) -> RustcOptGroup
1186 where F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static,
1191 stability: OptionStability::Stable,
1195 pub fn unstable<F>(name: &'static str, f: F) -> RustcOptGroup
1196 where F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static,
1201 stability: OptionStability::Unstable,
1206 // The `opt` local module holds wrappers around the `getopts` API that
1207 // adds extra rustc-specific metadata to each option; such metadata
1208 // is exposed by . The public
1209 // functions below ending with `_u` are the functions that return
1210 // *unstable* options, i.e. options that are only enabled when the
1211 // user also passes the `-Z unstable-options` debugging flag.
1213 // The `fn opt_u` etc below are written so that we can use them
1214 // in the future; do not warn about them not being used right now.
1215 #![allow(dead_code)]
1218 use super::RustcOptGroup;
1220 pub type R = RustcOptGroup;
1221 pub type S = &'static str;
1223 fn stable<F>(name: S, f: F) -> R
1224 where F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static
1226 RustcOptGroup::stable(name, f)
1229 fn unstable<F>(name: S, f: F) -> R
1230 where F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static
1232 RustcOptGroup::unstable(name, f)
1235 fn longer(a: S, b: S) -> S {
1236 if a.len() > b.len() {
1243 pub fn opt_s(a: S, b: S, c: S, d: S) -> R {
1244 stable(longer(a, b), move |opts| opts.optopt(a, b, c, d))
1246 pub fn multi_s(a: S, b: S, c: S, d: S) -> R {
1247 stable(longer(a, b), move |opts| opts.optmulti(a, b, c, d))
1249 pub fn flag_s(a: S, b: S, c: S) -> R {
1250 stable(longer(a, b), move |opts| opts.optflag(a, b, c))
1252 pub fn flagopt_s(a: S, b: S, c: S, d: S) -> R {
1253 stable(longer(a, b), move |opts| opts.optflagopt(a, b, c, d))
1255 pub fn flagmulti_s(a: S, b: S, c: S) -> R {
1256 stable(longer(a, b), move |opts| opts.optflagmulti(a, b, c))
1259 pub fn opt(a: S, b: S, c: S, d: S) -> R {
1260 unstable(longer(a, b), move |opts| opts.optopt(a, b, c, d))
1262 pub fn multi(a: S, b: S, c: S, d: S) -> R {
1263 unstable(longer(a, b), move |opts| opts.optmulti(a, b, c, d))
1265 pub fn flag(a: S, b: S, c: S) -> R {
1266 unstable(longer(a, b), move |opts| opts.optflag(a, b, c))
1268 pub fn flagopt(a: S, b: S, c: S, d: S) -> R {
1269 unstable(longer(a, b), move |opts| opts.optflagopt(a, b, c, d))
1271 pub fn flagmulti(a: S, b: S, c: S) -> R {
1272 unstable(longer(a, b), move |opts| opts.optflagmulti(a, b, c))
1276 /// Returns the "short" subset of the rustc command line options,
1277 /// including metadata for each option, such as whether the option is
1278 /// part of the stable long-term interface for rustc.
1279 pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
1281 opt::flag_s("h", "help", "Display this message"),
1282 opt::multi_s("", "cfg", "Configure the compilation environment", "SPEC"),
1283 opt::multi_s("L", "", "Add a directory to the library search path. The
1284 optional KIND can be one of dependency, crate, native,
1285 framework or all (the default).", "[KIND=]PATH"),
1286 opt::multi_s("l", "", "Link the generated crate(s) to the specified native
1287 library NAME. The optional KIND can be one of
1288 static, dylib, or framework. If omitted, dylib is
1289 assumed.", "[KIND=]NAME"),
1290 opt::multi_s("", "crate-type", "Comma separated list of types of crates
1291 for the compiler to emit",
1292 "[bin|lib|rlib|dylib|cdylib|staticlib|proc-macro]"),
1293 opt::opt_s("", "crate-name", "Specify the name of the crate being built",
1295 opt::multi_s("", "emit", "Comma separated list of types of output for \
1296 the compiler to emit",
1297 "[asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]"),
1298 opt::multi_s("", "print", "Comma separated list of compiler information to \
1300 "[crate-name|file-names|sysroot|cfg|target-list|\
1301 target-cpus|target-features|relocation-models|\
1302 code-models|target-spec-json|native-static-deps]"),
1303 opt::flagmulti_s("g", "", "Equivalent to -C debuginfo=2"),
1304 opt::flagmulti_s("O", "", "Equivalent to -C opt-level=2"),
1305 opt::opt_s("o", "", "Write output to <filename>", "FILENAME"),
1306 opt::opt_s("", "out-dir", "Write output to compiler-chosen filename \
1308 opt::opt_s("", "explain", "Provide a detailed explanation of an error \
1310 opt::flag_s("", "test", "Build a test harness"),
1311 opt::opt_s("", "target", "Target triple for which the code is compiled", "TARGET"),
1312 opt::multi_s("W", "warn", "Set lint warnings", "OPT"),
1313 opt::multi_s("A", "allow", "Set lint allowed", "OPT"),
1314 opt::multi_s("D", "deny", "Set lint denied", "OPT"),
1315 opt::multi_s("F", "forbid", "Set lint forbidden", "OPT"),
1316 opt::multi_s("", "cap-lints", "Set the most restrictive lint level. \
1317 More restrictive lints are capped at this \
1319 opt::multi_s("C", "codegen", "Set a codegen option", "OPT[=VALUE]"),
1320 opt::flag_s("V", "version", "Print version info and exit"),
1321 opt::flag_s("v", "verbose", "Use verbose output"),
1325 /// Returns all rustc command line options, including metadata for
1326 /// each option, such as whether the option is part of the stable
1327 /// long-term interface for rustc.
1328 pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
1329 let mut opts = rustc_short_optgroups();
1331 opt::multi_s("", "extern", "Specify where an external rust library is located",
1333 opt::opt_s("", "sysroot", "Override the system root", "PATH"),
1334 opt::multi("Z", "", "Set internal debugging options", "FLAG"),
1335 opt::opt_s("", "error-format",
1336 "How errors and other messages are produced",
1338 opt::opt_s("", "color", "Configure coloring of output:
1339 auto = colorize, if output goes to a tty (default);
1340 always = always colorize output;
1341 never = never colorize output", "auto|always|never"),
1343 opt::flagopt("", "pretty",
1344 "Pretty-print the input instead of compiling;
1345 valid types are: `normal` (un-annotated source),
1346 `expanded` (crates expanded), or
1347 `expanded,identified` (fully parenthesized, AST nodes with IDs).",
1349 opt::flagopt("", "unpretty",
1350 "Present the input source, unstable (and less-pretty) variants;
1351 valid types are any of the types for `--pretty`, as well as:
1352 `flowgraph=<nodeid>` (graphviz formatted flowgraph for node),
1353 `everybody_loops` (all function bodies replaced with `loop {}`),
1354 `hir` (the HIR), `hir,identified`, or
1355 `hir,typed` (HIR with types for each node).",
1361 // Convert strings provided as --cfg [cfgspec] into a crate_cfg
1362 pub fn parse_cfgspecs(cfgspecs: Vec<String> ) -> ast::CrateConfig {
1363 cfgspecs.into_iter().map(|s| {
1364 let sess = parse::ParseSess::new(FilePathMapping::empty());
1366 parse::new_parser_from_source_str(&sess, "cfgspec".to_string(), s.to_string());
1368 let meta_item = panictry!(parser.parse_meta_item());
1370 if parser.token != token::Eof {
1371 early_error(ErrorOutputType::default(), &format!("invalid --cfg argument: {}", s))
1372 } else if meta_item.is_meta_item_list() {
1374 format!("invalid predicate in --cfg command line argument: `{}`", meta_item.name());
1375 early_error(ErrorOutputType::default(), &msg)
1378 (meta_item.name(), meta_item.value_str())
1379 }).collect::<ast::CrateConfig>()
1382 pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
1383 -> (Options, ast::CrateConfig) {
1384 let color = match matches.opt_str("color").as_ref().map(|s| &s[..]) {
1385 Some("auto") => ColorConfig::Auto,
1386 Some("always") => ColorConfig::Always,
1387 Some("never") => ColorConfig::Never,
1389 None => ColorConfig::Auto,
1392 early_error(ErrorOutputType::default(), &format!("argument for --color must be auto, \
1393 always or never (instead was `{}`)",
1398 // We need the opts_present check because the driver will send us Matches
1399 // with only stable options if no unstable options are used. Since error-format
1400 // is unstable, it will not be present. We have to use opts_present not
1401 // opt_present because the latter will panic.
1402 let error_format = if matches.opts_present(&["error-format".to_owned()]) {
1403 match matches.opt_str("error-format").as_ref().map(|s| &s[..]) {
1404 Some("human") => ErrorOutputType::HumanReadable(color),
1405 Some("json") => ErrorOutputType::Json,
1407 None => ErrorOutputType::HumanReadable(color),
1410 early_error(ErrorOutputType::HumanReadable(color),
1411 &format!("argument for --error-format must be human or json (instead \
1417 ErrorOutputType::HumanReadable(color)
1420 let unparsed_crate_types = matches.opt_strs("crate-type");
1421 let crate_types = parse_crate_types_from_list(unparsed_crate_types)
1422 .unwrap_or_else(|e| early_error(error_format, &e[..]));
1424 let mut lint_opts = vec![];
1425 let mut describe_lints = false;
1427 for &level in &[lint::Allow, lint::Warn, lint::Deny, lint::Forbid] {
1428 for lint_name in matches.opt_strs(level.as_str()) {
1429 if lint_name == "help" {
1430 describe_lints = true;
1432 lint_opts.push((lint_name.replace("-", "_"), level));
1437 let lint_cap = matches.opt_str("cap-lints").map(|cap| {
1438 lint::Level::from_str(&cap).unwrap_or_else(|| {
1439 early_error(error_format, &format!("unknown lint level: `{}`", cap))
1443 let debugging_opts = build_debugging_options(matches, error_format);
1445 let mut output_types = BTreeMap::new();
1446 if !debugging_opts.parse_only {
1447 for list in matches.opt_strs("emit") {
1448 for output_type in list.split(',') {
1449 let mut parts = output_type.splitn(2, '=');
1450 let output_type = match parts.next().unwrap() {
1451 "asm" => OutputType::Assembly,
1452 "llvm-ir" => OutputType::LlvmAssembly,
1453 "mir" => OutputType::Mir,
1454 "llvm-bc" => OutputType::Bitcode,
1455 "obj" => OutputType::Object,
1456 "metadata" => OutputType::Metadata,
1457 "link" => OutputType::Exe,
1458 "dep-info" => OutputType::DepInfo,
1460 early_error(error_format, &format!("unknown emission type: `{}`",
1464 let path = parts.next().map(PathBuf::from);
1465 output_types.insert(output_type, path);
1469 if output_types.is_empty() {
1470 output_types.insert(OutputType::Exe, None);
1473 let remap_path_prefix_sources = debugging_opts.remap_path_prefix_from.len();
1474 let remap_path_prefix_targets = debugging_opts.remap_path_prefix_from.len();
1476 if remap_path_prefix_targets < remap_path_prefix_sources {
1477 for source in &debugging_opts.remap_path_prefix_from[remap_path_prefix_targets..] {
1478 early_error(error_format,
1479 &format!("option `-Zremap-path-prefix-from='{}'` does not have \
1480 a corresponding `-Zremap-path-prefix-to`", source))
1482 } else if remap_path_prefix_targets > remap_path_prefix_sources {
1483 for target in &debugging_opts.remap_path_prefix_to[remap_path_prefix_sources..] {
1484 early_error(error_format,
1485 &format!("option `-Zremap-path-prefix-to='{}'` does not have \
1486 a corresponding `-Zremap-path-prefix-from`", target))
1490 let mut cg = build_codegen_options(matches, error_format);
1492 // Issue #30063: if user requests llvm-related output to one
1493 // particular path, disable codegen-units.
1494 if matches.opt_present("o") && cg.codegen_units != 1 {
1495 let incompatible: Vec<_> = output_types.iter()
1496 .map(|ot_path| ot_path.0)
1498 !ot.is_compatible_with_codegen_units_and_single_output_file()
1500 if !incompatible.is_empty() {
1501 for ot in &incompatible {
1502 early_warn(error_format, &format!("--emit={} with -o incompatible with \
1503 -C codegen-units=N for N > 1",
1506 early_warn(error_format, "resetting to default -C codegen-units=1");
1507 cg.codegen_units = 1;
1511 if cg.codegen_units < 1 {
1512 early_error(error_format, "Value for codegen units must be a positive nonzero integer");
1515 // It's possible that we have `codegen_units > 1` but only one item in
1516 // `trans.modules`. We could theoretically proceed and do LTO in that
1517 // case, but it would be confusing to have the validity of
1518 // `-Z lto -C codegen-units=2` depend on details of the crate being
1519 // compiled, so we complain regardless.
1520 if cg.lto && cg.codegen_units > 1 {
1521 // This case is impossible to handle because LTO expects to be able
1522 // to combine the entire crate and all its dependencies into a
1523 // single compilation unit, but each codegen unit is in a separate
1524 // LLVM context, so they can't easily be combined.
1525 early_error(error_format, "can't perform LTO when using multiple codegen units");
1528 if cg.lto && debugging_opts.incremental.is_some() {
1529 early_error(error_format, "can't perform LTO when compiling incrementally");
1532 let mut prints = Vec::<PrintRequest>::new();
1533 if cg.target_cpu.as_ref().map_or(false, |s| s == "help") {
1534 prints.push(PrintRequest::TargetCPUs);
1535 cg.target_cpu = None;
1537 if cg.target_feature == "help" {
1538 prints.push(PrintRequest::TargetFeatures);
1539 cg.target_feature = "".to_string();
1541 if cg.relocation_model.as_ref().map_or(false, |s| s == "help") {
1542 prints.push(PrintRequest::RelocationModels);
1543 cg.relocation_model = None;
1545 if cg.code_model.as_ref().map_or(false, |s| s == "help") {
1546 prints.push(PrintRequest::CodeModels);
1547 cg.code_model = None;
1552 let sysroot_opt = matches.opt_str("sysroot").map(|m| PathBuf::from(&m));
1553 let target = matches.opt_str("target").unwrap_or(
1554 host_triple().to_string());
1556 if matches.opt_present("O") {
1557 if cg.opt_level.is_some() {
1558 early_error(error_format, "-O and -C opt-level both provided");
1562 match (cg.opt_level.as_ref().map(String::as_ref),
1563 nightly_options::is_nightly_build()) {
1564 (None, _) => OptLevel::No,
1565 (Some("0"), _) => OptLevel::No,
1566 (Some("1"), _) => OptLevel::Less,
1567 (Some("2"), _) => OptLevel::Default,
1568 (Some("3"), _) => OptLevel::Aggressive,
1569 (Some("s"), true) => OptLevel::Size,
1570 (Some("z"), true) => OptLevel::SizeMin,
1571 (Some("s"), false) | (Some("z"), false) => {
1572 early_error(error_format, &format!("the optimizations s or z are only \
1573 accepted on the nightly compiler"));
1576 early_error(error_format, &format!("optimization level needs to be \
1577 between 0-3 (instead was `{}`)",
1583 let debug_assertions = cg.debug_assertions.unwrap_or(opt_level == OptLevel::No);
1584 let debuginfo = if matches.opt_present("g") {
1585 if cg.debuginfo.is_some() {
1586 early_error(error_format, "-g and -C debuginfo both provided");
1590 match cg.debuginfo {
1591 None | Some(0) => NoDebugInfo,
1592 Some(1) => LimitedDebugInfo,
1593 Some(2) => FullDebugInfo,
1595 early_error(error_format, &format!("debug info level needs to be between \
1596 0-2 (instead was `{}`)",
1602 let mut search_paths = SearchPaths::new();
1603 for s in &matches.opt_strs("L") {
1604 search_paths.add_path(&s[..], error_format);
1607 let libs = matches.opt_strs("l").into_iter().map(|s| {
1608 // Parse string of the form "[KIND=]lib[:new_name]",
1609 // where KIND is one of "dylib", "framework", "static".
1610 let mut parts = s.splitn(2, '=');
1611 let kind = parts.next().unwrap();
1612 let (name, kind) = match (parts.next(), kind) {
1613 (None, name) => (name, None),
1614 (Some(name), "dylib") => (name, Some(cstore::NativeUnknown)),
1615 (Some(name), "framework") => (name, Some(cstore::NativeFramework)),
1616 (Some(name), "static") => (name, Some(cstore::NativeStatic)),
1617 (Some(name), "static-nobundle") => (name, Some(cstore::NativeStaticNobundle)),
1619 early_error(error_format, &format!("unknown library kind `{}`, expected \
1620 one of dylib, framework, or static",
1624 if kind == Some(cstore::NativeStaticNobundle) && !nightly_options::is_nightly_build() {
1625 early_error(error_format, &format!("the library kind 'static-nobundle' is only \
1626 accepted on the nightly compiler"));
1628 let mut name_parts = name.splitn(2, ':');
1629 let name = name_parts.next().unwrap();
1630 let new_name = name_parts.next();
1631 (name.to_string(), new_name.map(|n| n.to_string()), kind)
1634 let cfg = parse_cfgspecs(matches.opt_strs("cfg"));
1635 let test = matches.opt_present("test");
1637 prints.extend(matches.opt_strs("print").into_iter().map(|s| {
1639 "crate-name" => PrintRequest::CrateName,
1640 "file-names" => PrintRequest::FileNames,
1641 "sysroot" => PrintRequest::Sysroot,
1642 "cfg" => PrintRequest::Cfg,
1643 "target-list" => PrintRequest::TargetList,
1644 "target-cpus" => PrintRequest::TargetCPUs,
1645 "target-features" => PrintRequest::TargetFeatures,
1646 "relocation-models" => PrintRequest::RelocationModels,
1647 "code-models" => PrintRequest::CodeModels,
1648 "native-static-libs" => PrintRequest::NativeStaticLibs,
1649 "target-spec-json" => {
1650 if nightly_options::is_unstable_enabled(matches) {
1651 PrintRequest::TargetSpec
1653 early_error(error_format,
1654 &format!("the `-Z unstable-options` flag must also be passed to \
1655 enable the target-spec-json print option"));
1659 early_error(error_format, &format!("unknown print request `{}`", req))
1664 if !cg.remark.is_empty() && debuginfo == NoDebugInfo {
1665 early_warn(error_format, "-C remark will not show source locations without \
1669 let mut externs = BTreeMap::new();
1670 for arg in &matches.opt_strs("extern") {
1671 let mut parts = arg.splitn(2, '=');
1672 let name = match parts.next() {
1674 None => early_error(error_format, "--extern value must not be empty"),
1676 let location = match parts.next() {
1678 None => early_error(error_format, "--extern value must be of the format `foo=bar`"),
1681 externs.entry(name.to_string())
1682 .or_insert_with(BTreeSet::new)
1683 .insert(location.to_string());
1686 let crate_name = matches.opt_str("crate-name");
1688 let incremental = debugging_opts.incremental.as_ref().map(|m| PathBuf::from(m));
1692 optimize: opt_level,
1697 output_types: OutputTypes(output_types),
1699 maybe_sysroot: sysroot_opt,
1700 target_triple: target,
1707 externs: Externs(externs),
1711 unstable_features: UnstableFeatures::from_environment(),
1713 actually_rustdoc: false,
1718 pub fn parse_crate_types_from_list(list_list: Vec<String>)
1719 -> Result<Vec<CrateType>, String> {
1720 let mut crate_types: Vec<CrateType> = Vec::new();
1721 for unparsed_crate_type in &list_list {
1722 for part in unparsed_crate_type.split(',') {
1723 let new_part = match part {
1724 "lib" => default_lib_output(),
1725 "rlib" => CrateTypeRlib,
1726 "staticlib" => CrateTypeStaticlib,
1727 "dylib" => CrateTypeDylib,
1728 "cdylib" => CrateTypeCdylib,
1729 "bin" => CrateTypeExecutable,
1730 "proc-macro" => CrateTypeProcMacro,
1732 return Err(format!("unknown crate type: `{}`",
1736 if !crate_types.contains(&new_part) {
1737 crate_types.push(new_part)
1745 pub mod nightly_options {
1747 use syntax::feature_gate::UnstableFeatures;
1748 use super::{ErrorOutputType, OptionStability, RustcOptGroup};
1749 use session::early_error;
1751 pub fn is_unstable_enabled(matches: &getopts::Matches) -> bool {
1752 is_nightly_build() && matches.opt_strs("Z").iter().any(|x| *x == "unstable-options")
1755 pub fn is_nightly_build() -> bool {
1756 UnstableFeatures::from_environment().is_nightly_build()
1759 pub fn check_nightly_options(matches: &getopts::Matches, flags: &[RustcOptGroup]) {
1760 let has_z_unstable_option = matches.opt_strs("Z").iter().any(|x| *x == "unstable-options");
1761 let really_allows_unstable_options = UnstableFeatures::from_environment()
1762 .is_nightly_build();
1764 for opt in flags.iter() {
1765 if opt.stability == OptionStability::Stable {
1768 if !matches.opt_present(opt.name) {
1771 if opt.name != "Z" && !has_z_unstable_option {
1772 early_error(ErrorOutputType::default(),
1773 &format!("the `-Z unstable-options` flag must also be passed to enable \
1777 if really_allows_unstable_options {
1780 match opt.stability {
1781 OptionStability::Unstable => {
1782 let msg = format!("the option `{}` is only accepted on the \
1783 nightly compiler", opt.name);
1784 early_error(ErrorOutputType::default(), &msg);
1786 OptionStability::Stable => {}
1792 impl fmt::Display for CrateType {
1793 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1795 CrateTypeExecutable => "bin".fmt(f),
1796 CrateTypeDylib => "dylib".fmt(f),
1797 CrateTypeRlib => "rlib".fmt(f),
1798 CrateTypeStaticlib => "staticlib".fmt(f),
1799 CrateTypeCdylib => "cdylib".fmt(f),
1800 CrateTypeProcMacro => "proc-macro".fmt(f),
1805 /// Commandline arguments passed to the compiler have to be incorporated with
1806 /// the dependency tracking system for incremental compilation. This module
1807 /// provides some utilities to make this more convenient.
1809 /// The values of all commandline arguments that are relevant for dependency
1810 /// tracking are hashed into a single value that determines whether the
1811 /// incremental compilation cache can be re-used or not. This hashing is done
1812 /// via the DepTrackingHash trait defined below, since the standard Hash
1813 /// implementation might not be suitable (e.g. arguments are stored in a Vec,
1814 /// the hash of which is order dependent, but we might not want the order of
1815 /// arguments to make a difference for the hash).
1817 /// However, since the value provided by Hash::hash often *is* suitable,
1818 /// especially for primitive types, there is the
1819 /// impl_dep_tracking_hash_via_hash!() macro that allows to simply reuse the
1820 /// Hash implementation for DepTrackingHash. It's important though that
1821 /// we have an opt-in scheme here, so one is hopefully forced to think about
1822 /// how the hash should be calculated when adding a new commandline argument.
1826 use session::search_paths::{PathKind, SearchPaths};
1827 use std::collections::BTreeMap;
1828 use std::hash::Hash;
1829 use std::path::PathBuf;
1830 use std::collections::hash_map::DefaultHasher;
1831 use super::{Passes, CrateType, OptLevel, DebugInfoLevel,
1832 OutputTypes, Externs, ErrorOutputType, Sanitizer};
1833 use syntax::feature_gate::UnstableFeatures;
1834 use rustc_back::{PanicStrategy, RelroLevel};
1836 pub trait DepTrackingHash {
1837 fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType);
1840 macro_rules! impl_dep_tracking_hash_via_hash {
1842 impl DepTrackingHash for $t {
1843 fn hash(&self, hasher: &mut DefaultHasher, _: ErrorOutputType) {
1844 Hash::hash(self, hasher);
1850 macro_rules! impl_dep_tracking_hash_for_sortable_vec_of {
1852 impl DepTrackingHash for Vec<$t> {
1853 fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) {
1854 let mut elems: Vec<&$t> = self.iter().collect();
1856 Hash::hash(&elems.len(), hasher);
1857 for (index, elem) in elems.iter().enumerate() {
1858 Hash::hash(&index, hasher);
1859 DepTrackingHash::hash(*elem, hasher, error_format);
1866 impl_dep_tracking_hash_via_hash!(bool);
1867 impl_dep_tracking_hash_via_hash!(usize);
1868 impl_dep_tracking_hash_via_hash!(u64);
1869 impl_dep_tracking_hash_via_hash!(String);
1870 impl_dep_tracking_hash_via_hash!(lint::Level);
1871 impl_dep_tracking_hash_via_hash!(Option<bool>);
1872 impl_dep_tracking_hash_via_hash!(Option<usize>);
1873 impl_dep_tracking_hash_via_hash!(Option<String>);
1874 impl_dep_tracking_hash_via_hash!(Option<(String, u64)>);
1875 impl_dep_tracking_hash_via_hash!(Option<PanicStrategy>);
1876 impl_dep_tracking_hash_via_hash!(Option<RelroLevel>);
1877 impl_dep_tracking_hash_via_hash!(Option<lint::Level>);
1878 impl_dep_tracking_hash_via_hash!(Option<PathBuf>);
1879 impl_dep_tracking_hash_via_hash!(Option<cstore::NativeLibraryKind>);
1880 impl_dep_tracking_hash_via_hash!(CrateType);
1881 impl_dep_tracking_hash_via_hash!(PanicStrategy);
1882 impl_dep_tracking_hash_via_hash!(RelroLevel);
1883 impl_dep_tracking_hash_via_hash!(Passes);
1884 impl_dep_tracking_hash_via_hash!(OptLevel);
1885 impl_dep_tracking_hash_via_hash!(DebugInfoLevel);
1886 impl_dep_tracking_hash_via_hash!(UnstableFeatures);
1887 impl_dep_tracking_hash_via_hash!(Externs);
1888 impl_dep_tracking_hash_via_hash!(OutputTypes);
1889 impl_dep_tracking_hash_via_hash!(cstore::NativeLibraryKind);
1890 impl_dep_tracking_hash_via_hash!(Sanitizer);
1891 impl_dep_tracking_hash_via_hash!(Option<Sanitizer>);
1893 impl_dep_tracking_hash_for_sortable_vec_of!(String);
1894 impl_dep_tracking_hash_for_sortable_vec_of!(CrateType);
1895 impl_dep_tracking_hash_for_sortable_vec_of!((String, lint::Level));
1896 impl_dep_tracking_hash_for_sortable_vec_of!((String, Option<String>,
1897 Option<cstore::NativeLibraryKind>));
1898 impl_dep_tracking_hash_for_sortable_vec_of!((String, u64));
1899 impl DepTrackingHash for SearchPaths {
1900 fn hash(&self, hasher: &mut DefaultHasher, _: ErrorOutputType) {
1901 let mut elems: Vec<_> = self
1902 .iter(PathKind::All)
1905 Hash::hash(&elems, hasher);
1909 impl<T1, T2> DepTrackingHash for (T1, T2)
1910 where T1: DepTrackingHash,
1913 fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) {
1914 Hash::hash(&0, hasher);
1915 DepTrackingHash::hash(&self.0, hasher, error_format);
1916 Hash::hash(&1, hasher);
1917 DepTrackingHash::hash(&self.1, hasher, error_format);
1921 impl<T1, T2, T3> DepTrackingHash for (T1, T2, T3)
1922 where T1: DepTrackingHash,
1923 T2: DepTrackingHash,
1926 fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) {
1927 Hash::hash(&0, hasher);
1928 DepTrackingHash::hash(&self.0, hasher, error_format);
1929 Hash::hash(&1, hasher);
1930 DepTrackingHash::hash(&self.1, hasher, error_format);
1931 Hash::hash(&2, hasher);
1932 DepTrackingHash::hash(&self.2, hasher, error_format);
1936 // This is a stable hash because BTreeMap is a sorted container
1937 pub fn stable_hash(sub_hashes: BTreeMap<&'static str, &DepTrackingHash>,
1938 hasher: &mut DefaultHasher,
1939 error_format: ErrorOutputType) {
1940 for (key, sub_hash) in sub_hashes {
1941 // Using Hash::hash() instead of DepTrackingHash::hash() is fine for
1942 // the keys, as they are just plain strings
1943 Hash::hash(&key.len(), hasher);
1944 Hash::hash(key, hasher);
1945 sub_hash.hash(hasher, error_format);
1952 use dep_graph::DepGraph;
1957 use session::config::{build_configuration, build_session_options_and_crate_config};
1958 use session::build_session;
1959 use std::collections::{BTreeMap, BTreeSet};
1960 use std::iter::FromIterator;
1961 use std::path::PathBuf;
1962 use super::{OutputType, OutputTypes, Externs};
1963 use rustc_back::{PanicStrategy, RelroLevel};
1964 use syntax::symbol::Symbol;
1966 fn optgroups() -> getopts::Options {
1967 let mut opts = getopts::Options::new();
1968 for group in super::rustc_optgroups() {
1969 (group.apply)(&mut opts);
1974 fn mk_map<K: Ord, V>(entries: Vec<(K, V)>) -> BTreeMap<K, V> {
1975 BTreeMap::from_iter(entries.into_iter())
1978 fn mk_set<V: Ord>(entries: Vec<V>) -> BTreeSet<V> {
1979 BTreeSet::from_iter(entries.into_iter())
1982 // When the user supplies --test we should implicitly supply --cfg test
1984 fn test_switch_implies_cfg_test() {
1985 let dep_graph = DepGraph::new(false);
1987 &match optgroups().parse(&["--test".to_string()]) {
1989 Err(f) => panic!("test_switch_implies_cfg_test: {}", f)
1991 let registry = errors::registry::Registry::new(&[]);
1992 let (sessopts, cfg) = build_session_options_and_crate_config(matches);
1993 let sess = build_session(sessopts, &dep_graph, None, registry);
1994 let cfg = build_configuration(&sess, cfg);
1995 assert!(cfg.contains(&(Symbol::intern("test"), None)));
1998 // When the user supplies --test and --cfg test, don't implicitly add
1999 // another --cfg test
2001 fn test_switch_implies_cfg_test_unless_cfg_test() {
2002 let dep_graph = DepGraph::new(false);
2004 &match optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]) {
2007 panic!("test_switch_implies_cfg_test_unless_cfg_test: {}", f)
2010 let registry = errors::registry::Registry::new(&[]);
2011 let (sessopts, cfg) = build_session_options_and_crate_config(matches);
2012 let sess = build_session(sessopts, &dep_graph, None, registry);
2013 let cfg = build_configuration(&sess, cfg);
2014 let mut test_items = cfg.iter().filter(|&&(name, _)| name == "test");
2015 assert!(test_items.next().is_some());
2016 assert!(test_items.next().is_none());
2020 fn test_can_print_warnings() {
2021 let dep_graph = DepGraph::new(false);
2023 let matches = optgroups().parse(&[
2024 "-Awarnings".to_string()
2026 let registry = errors::registry::Registry::new(&[]);
2027 let (sessopts, _) = build_session_options_and_crate_config(&matches);
2028 let sess = build_session(sessopts, &dep_graph, None, registry);
2029 assert!(!sess.diagnostic().can_emit_warnings);
2033 let matches = optgroups().parse(&[
2034 "-Awarnings".to_string(),
2035 "-Dwarnings".to_string()
2037 let registry = errors::registry::Registry::new(&[]);
2038 let (sessopts, _) = build_session_options_and_crate_config(&matches);
2039 let sess = build_session(sessopts, &dep_graph, None, registry);
2040 assert!(sess.diagnostic().can_emit_warnings);
2044 let matches = optgroups().parse(&[
2045 "-Adead_code".to_string()
2047 let registry = errors::registry::Registry::new(&[]);
2048 let (sessopts, _) = build_session_options_and_crate_config(&matches);
2049 let sess = build_session(sessopts, &dep_graph, None, registry);
2050 assert!(sess.diagnostic().can_emit_warnings);
2055 fn test_output_types_tracking_hash_different_paths() {
2056 let mut v1 = super::basic_options();
2057 let mut v2 = super::basic_options();
2058 let mut v3 = super::basic_options();
2060 v1.output_types = OutputTypes::new(&[(OutputType::Exe,
2061 Some(PathBuf::from("./some/thing")))]);
2062 v2.output_types = OutputTypes::new(&[(OutputType::Exe,
2063 Some(PathBuf::from("/some/thing")))]);
2064 v3.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
2066 assert!(v1.dep_tracking_hash() != v2.dep_tracking_hash());
2067 assert!(v1.dep_tracking_hash() != v3.dep_tracking_hash());
2068 assert!(v2.dep_tracking_hash() != v3.dep_tracking_hash());
2071 assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
2072 assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
2073 assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash());
2077 fn test_output_types_tracking_hash_different_construction_order() {
2078 let mut v1 = super::basic_options();
2079 let mut v2 = super::basic_options();
2081 v1.output_types = OutputTypes::new(&[
2082 (OutputType::Exe, Some(PathBuf::from("./some/thing"))),
2083 (OutputType::Bitcode, Some(PathBuf::from("./some/thing.bc"))),
2086 v2.output_types = OutputTypes::new(&[
2087 (OutputType::Bitcode, Some(PathBuf::from("./some/thing.bc"))),
2088 (OutputType::Exe, Some(PathBuf::from("./some/thing"))),
2091 assert_eq!(v1.dep_tracking_hash(), v2.dep_tracking_hash());
2094 assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
2098 fn test_externs_tracking_hash_different_values() {
2099 let mut v1 = super::basic_options();
2100 let mut v2 = super::basic_options();
2101 let mut v3 = super::basic_options();
2103 v1.externs = Externs::new(mk_map(vec![
2104 (String::from("a"), mk_set(vec![String::from("b"),
2105 String::from("c")])),
2106 (String::from("d"), mk_set(vec![String::from("e"),
2107 String::from("f")])),
2110 v2.externs = Externs::new(mk_map(vec![
2111 (String::from("a"), mk_set(vec![String::from("b"),
2112 String::from("c")])),
2113 (String::from("X"), mk_set(vec![String::from("e"),
2114 String::from("f")])),
2117 v3.externs = Externs::new(mk_map(vec![
2118 (String::from("a"), mk_set(vec![String::from("b"),
2119 String::from("c")])),
2120 (String::from("d"), mk_set(vec![String::from("X"),
2121 String::from("f")])),
2124 assert!(v1.dep_tracking_hash() != v2.dep_tracking_hash());
2125 assert!(v1.dep_tracking_hash() != v3.dep_tracking_hash());
2126 assert!(v2.dep_tracking_hash() != v3.dep_tracking_hash());
2129 assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
2130 assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
2131 assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash());
2135 fn test_externs_tracking_hash_different_construction_order() {
2136 let mut v1 = super::basic_options();
2137 let mut v2 = super::basic_options();
2138 let mut v3 = super::basic_options();
2140 v1.externs = Externs::new(mk_map(vec![
2141 (String::from("a"), mk_set(vec![String::from("b"),
2142 String::from("c")])),
2143 (String::from("d"), mk_set(vec![String::from("e"),
2144 String::from("f")])),
2147 v2.externs = Externs::new(mk_map(vec![
2148 (String::from("d"), mk_set(vec![String::from("e"),
2149 String::from("f")])),
2150 (String::from("a"), mk_set(vec![String::from("b"),
2151 String::from("c")])),
2154 v3.externs = Externs::new(mk_map(vec![
2155 (String::from("a"), mk_set(vec![String::from("b"),
2156 String::from("c")])),
2157 (String::from("d"), mk_set(vec![String::from("f"),
2158 String::from("e")])),
2161 assert_eq!(v1.dep_tracking_hash(), v2.dep_tracking_hash());
2162 assert_eq!(v1.dep_tracking_hash(), v3.dep_tracking_hash());
2163 assert_eq!(v2.dep_tracking_hash(), v3.dep_tracking_hash());
2166 assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
2167 assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
2168 assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash());
2172 fn test_lints_tracking_hash_different_values() {
2173 let mut v1 = super::basic_options();
2174 let mut v2 = super::basic_options();
2175 let mut v3 = super::basic_options();
2177 v1.lint_opts = vec![(String::from("a"), lint::Allow),
2178 (String::from("b"), lint::Warn),
2179 (String::from("c"), lint::Deny),
2180 (String::from("d"), lint::Forbid)];
2182 v2.lint_opts = vec![(String::from("a"), lint::Allow),
2183 (String::from("b"), lint::Warn),
2184 (String::from("X"), lint::Deny),
2185 (String::from("d"), lint::Forbid)];
2187 v3.lint_opts = vec![(String::from("a"), lint::Allow),
2188 (String::from("b"), lint::Warn),
2189 (String::from("c"), lint::Forbid),
2190 (String::from("d"), lint::Deny)];
2192 assert!(v1.dep_tracking_hash() != v2.dep_tracking_hash());
2193 assert!(v1.dep_tracking_hash() != v3.dep_tracking_hash());
2194 assert!(v2.dep_tracking_hash() != v3.dep_tracking_hash());
2197 assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
2198 assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
2199 assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash());
2203 fn test_lints_tracking_hash_different_construction_order() {
2204 let mut v1 = super::basic_options();
2205 let mut v2 = super::basic_options();
2207 v1.lint_opts = vec![(String::from("a"), lint::Allow),
2208 (String::from("b"), lint::Warn),
2209 (String::from("c"), lint::Deny),
2210 (String::from("d"), lint::Forbid)];
2212 v2.lint_opts = vec![(String::from("a"), lint::Allow),
2213 (String::from("c"), lint::Deny),
2214 (String::from("b"), lint::Warn),
2215 (String::from("d"), lint::Forbid)];
2217 assert_eq!(v1.dep_tracking_hash(), v2.dep_tracking_hash());
2220 assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
2221 assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
2225 fn test_search_paths_tracking_hash_different_values() {
2226 let mut v1 = super::basic_options();
2227 let mut v2 = super::basic_options();
2228 let mut v3 = super::basic_options();
2229 let mut v4 = super::basic_options();
2230 let mut v5 = super::basic_options();
2233 v1.search_paths.add_path("native=abc", super::ErrorOutputType::Json);
2234 v1.search_paths.add_path("crate=def", super::ErrorOutputType::Json);
2235 v1.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json);
2236 v1.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json);
2237 v1.search_paths.add_path("all=mno", super::ErrorOutputType::Json);
2240 v2.search_paths.add_path("native=XXX", super::ErrorOutputType::Json);
2241 v2.search_paths.add_path("crate=def", super::ErrorOutputType::Json);
2242 v2.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json);
2243 v2.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json);
2244 v2.search_paths.add_path("all=mno", super::ErrorOutputType::Json);
2247 v2.search_paths.add_path("native=abc", super::ErrorOutputType::Json);
2248 v2.search_paths.add_path("crate=XXX", super::ErrorOutputType::Json);
2249 v2.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json);
2250 v2.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json);
2251 v2.search_paths.add_path("all=mno", super::ErrorOutputType::Json);
2253 // Dependency changed
2254 v3.search_paths.add_path("native=abc", super::ErrorOutputType::Json);
2255 v3.search_paths.add_path("crate=def", super::ErrorOutputType::Json);
2256 v3.search_paths.add_path("dependency=XXX", super::ErrorOutputType::Json);
2257 v3.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json);
2258 v3.search_paths.add_path("all=mno", super::ErrorOutputType::Json);
2260 // Framework changed
2261 v4.search_paths.add_path("native=abc", super::ErrorOutputType::Json);
2262 v4.search_paths.add_path("crate=def", super::ErrorOutputType::Json);
2263 v4.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json);
2264 v4.search_paths.add_path("framework=XXX", super::ErrorOutputType::Json);
2265 v4.search_paths.add_path("all=mno", super::ErrorOutputType::Json);
2268 v5.search_paths.add_path("native=abc", super::ErrorOutputType::Json);
2269 v5.search_paths.add_path("crate=def", super::ErrorOutputType::Json);
2270 v5.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json);
2271 v5.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json);
2272 v5.search_paths.add_path("all=XXX", super::ErrorOutputType::Json);
2274 assert!(v1.dep_tracking_hash() != v2.dep_tracking_hash());
2275 assert!(v1.dep_tracking_hash() != v3.dep_tracking_hash());
2276 assert!(v1.dep_tracking_hash() != v4.dep_tracking_hash());
2277 assert!(v1.dep_tracking_hash() != v5.dep_tracking_hash());
2280 assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
2281 assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
2282 assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash());
2283 assert_eq!(v4.dep_tracking_hash(), v4.clone().dep_tracking_hash());
2284 assert_eq!(v5.dep_tracking_hash(), v5.clone().dep_tracking_hash());
2288 fn test_search_paths_tracking_hash_different_order() {
2289 let mut v1 = super::basic_options();
2290 let mut v2 = super::basic_options();
2291 let mut v3 = super::basic_options();
2292 let mut v4 = super::basic_options();
2295 v1.search_paths.add_path("native=abc", super::ErrorOutputType::Json);
2296 v1.search_paths.add_path("crate=def", super::ErrorOutputType::Json);
2297 v1.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json);
2298 v1.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json);
2299 v1.search_paths.add_path("all=mno", super::ErrorOutputType::Json);
2301 v2.search_paths.add_path("native=abc", super::ErrorOutputType::Json);
2302 v2.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json);
2303 v2.search_paths.add_path("crate=def", super::ErrorOutputType::Json);
2304 v2.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json);
2305 v2.search_paths.add_path("all=mno", super::ErrorOutputType::Json);
2307 v3.search_paths.add_path("crate=def", super::ErrorOutputType::Json);
2308 v3.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json);
2309 v3.search_paths.add_path("native=abc", super::ErrorOutputType::Json);
2310 v3.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json);
2311 v3.search_paths.add_path("all=mno", super::ErrorOutputType::Json);
2313 v4.search_paths.add_path("all=mno", super::ErrorOutputType::Json);
2314 v4.search_paths.add_path("native=abc", super::ErrorOutputType::Json);
2315 v4.search_paths.add_path("crate=def", super::ErrorOutputType::Json);
2316 v4.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json);
2317 v4.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json);
2319 assert!(v1.dep_tracking_hash() == v2.dep_tracking_hash());
2320 assert!(v1.dep_tracking_hash() == v3.dep_tracking_hash());
2321 assert!(v1.dep_tracking_hash() == v4.dep_tracking_hash());
2324 assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
2325 assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
2326 assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash());
2327 assert_eq!(v4.dep_tracking_hash(), v4.clone().dep_tracking_hash());
2331 fn test_native_libs_tracking_hash_different_values() {
2332 let mut v1 = super::basic_options();
2333 let mut v2 = super::basic_options();
2334 let mut v3 = super::basic_options();
2335 let mut v4 = super::basic_options();
2338 v1.libs = vec![(String::from("a"), None, Some(cstore::NativeStatic)),
2339 (String::from("b"), None, Some(cstore::NativeFramework)),
2340 (String::from("c"), None, Some(cstore::NativeUnknown))];
2343 v2.libs = vec![(String::from("a"), None, Some(cstore::NativeStatic)),
2344 (String::from("X"), None, Some(cstore::NativeFramework)),
2345 (String::from("c"), None, Some(cstore::NativeUnknown))];
2348 v3.libs = vec![(String::from("a"), None, Some(cstore::NativeStatic)),
2349 (String::from("b"), None, Some(cstore::NativeStatic)),
2350 (String::from("c"), None, Some(cstore::NativeUnknown))];
2353 v4.libs = vec![(String::from("a"), None, Some(cstore::NativeStatic)),
2354 (String::from("b"), Some(String::from("X")), Some(cstore::NativeFramework)),
2355 (String::from("c"), None, Some(cstore::NativeUnknown))];
2357 assert!(v1.dep_tracking_hash() != v2.dep_tracking_hash());
2358 assert!(v1.dep_tracking_hash() != v3.dep_tracking_hash());
2359 assert!(v1.dep_tracking_hash() != v4.dep_tracking_hash());
2362 assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
2363 assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
2364 assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash());
2365 assert_eq!(v4.dep_tracking_hash(), v4.clone().dep_tracking_hash());
2369 fn test_native_libs_tracking_hash_different_order() {
2370 let mut v1 = super::basic_options();
2371 let mut v2 = super::basic_options();
2372 let mut v3 = super::basic_options();
2375 v1.libs = vec![(String::from("a"), None, Some(cstore::NativeStatic)),
2376 (String::from("b"), None, Some(cstore::NativeFramework)),
2377 (String::from("c"), None, Some(cstore::NativeUnknown))];
2379 v2.libs = vec![(String::from("b"), None, Some(cstore::NativeFramework)),
2380 (String::from("a"), None, Some(cstore::NativeStatic)),
2381 (String::from("c"), None, Some(cstore::NativeUnknown))];
2383 v3.libs = vec![(String::from("c"), None, Some(cstore::NativeUnknown)),
2384 (String::from("a"), None, Some(cstore::NativeStatic)),
2385 (String::from("b"), None, Some(cstore::NativeFramework))];
2387 assert!(v1.dep_tracking_hash() == v2.dep_tracking_hash());
2388 assert!(v1.dep_tracking_hash() == v3.dep_tracking_hash());
2389 assert!(v2.dep_tracking_hash() == v3.dep_tracking_hash());
2392 assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
2393 assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
2394 assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash());
2398 fn test_codegen_options_tracking_hash() {
2399 let reference = super::basic_options();
2400 let mut opts = super::basic_options();
2402 // Make sure the changing an [UNTRACKED] option leaves the hash unchanged
2403 opts.cg.ar = Some(String::from("abc"));
2404 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2406 opts.cg.linker = Some(String::from("linker"));
2407 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2409 opts.cg.link_args = Some(vec![String::from("abc"), String::from("def")]);
2410 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2412 opts.cg.link_dead_code = true;
2413 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2415 opts.cg.rpath = true;
2416 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2418 opts.cg.extra_filename = String::from("extra-filename");
2419 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2421 opts.cg.codegen_units = 42;
2422 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2424 opts.cg.remark = super::SomePasses(vec![String::from("pass1"),
2425 String::from("pass2")]);
2426 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2428 opts.cg.save_temps = true;
2429 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2432 // Make sure changing a [TRACKED] option changes the hash
2433 opts = reference.clone();
2435 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2437 opts = reference.clone();
2438 opts.cg.target_cpu = Some(String::from("abc"));
2439 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2441 opts = reference.clone();
2442 opts.cg.target_feature = String::from("all the features, all of them");
2443 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2445 opts = reference.clone();
2446 opts.cg.passes = vec![String::from("1"), String::from("2")];
2447 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2449 opts = reference.clone();
2450 opts.cg.llvm_args = vec![String::from("1"), String::from("2")];
2451 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2453 opts = reference.clone();
2454 opts.cg.overflow_checks = Some(true);
2455 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2457 opts = reference.clone();
2458 opts.cg.no_prepopulate_passes = true;
2459 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2461 opts = reference.clone();
2462 opts.cg.no_vectorize_loops = true;
2463 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2465 opts = reference.clone();
2466 opts.cg.no_vectorize_slp = true;
2467 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2469 opts = reference.clone();
2470 opts.cg.soft_float = true;
2471 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2473 opts = reference.clone();
2474 opts.cg.prefer_dynamic = true;
2475 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2477 opts = reference.clone();
2478 opts.cg.no_integrated_as = true;
2479 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2481 opts = reference.clone();
2482 opts.cg.no_redzone = Some(true);
2483 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2485 opts = reference.clone();
2486 opts.cg.relocation_model = Some(String::from("relocation model"));
2487 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2489 opts = reference.clone();
2490 opts.cg.code_model = Some(String::from("code model"));
2491 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2493 opts = reference.clone();
2494 opts.cg.metadata = vec![String::from("A"), String::from("B")];
2495 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2497 opts = reference.clone();
2498 opts.cg.debuginfo = Some(0xdeadbeef);
2499 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2501 opts = reference.clone();
2502 opts.cg.debuginfo = Some(0xba5eba11);
2503 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2505 opts = reference.clone();
2506 opts.cg.debug_assertions = Some(true);
2507 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2509 opts = reference.clone();
2510 opts.cg.inline_threshold = Some(0xf007ba11);
2511 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2513 opts = reference.clone();
2514 opts.cg.panic = Some(PanicStrategy::Abort);
2515 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2519 fn test_debugging_options_tracking_hash() {
2520 let reference = super::basic_options();
2521 let mut opts = super::basic_options();
2523 // Make sure the changing an [UNTRACKED] option leaves the hash unchanged
2524 opts.debugging_opts.verbose = true;
2525 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2526 opts.debugging_opts.time_passes = true;
2527 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2528 opts.debugging_opts.count_llvm_insns = true;
2529 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2530 opts.debugging_opts.time_llvm_passes = true;
2531 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2532 opts.debugging_opts.input_stats = true;
2533 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2534 opts.debugging_opts.trans_stats = true;
2535 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2536 opts.debugging_opts.borrowck_stats = true;
2537 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2538 opts.debugging_opts.debug_llvm = true;
2539 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2540 opts.debugging_opts.meta_stats = true;
2541 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2542 opts.debugging_opts.print_link_args = true;
2543 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2544 opts.debugging_opts.print_llvm_passes = true;
2545 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2546 opts.debugging_opts.ast_json = true;
2547 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2548 opts.debugging_opts.ast_json_noexpand = true;
2549 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2550 opts.debugging_opts.ls = true;
2551 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2552 opts.debugging_opts.save_analysis = true;
2553 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2554 opts.debugging_opts.print_move_fragments = true;
2555 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2556 opts.debugging_opts.flowgraph_print_loans = true;
2557 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2558 opts.debugging_opts.flowgraph_print_moves = true;
2559 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2560 opts.debugging_opts.flowgraph_print_assigns = true;
2561 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2562 opts.debugging_opts.flowgraph_print_all = true;
2563 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2564 opts.debugging_opts.print_region_graph = true;
2565 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2566 opts.debugging_opts.parse_only = true;
2567 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2568 opts.debugging_opts.incremental = Some(String::from("abc"));
2569 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2570 opts.debugging_opts.dump_dep_graph = true;
2571 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2572 opts.debugging_opts.query_dep_graph = true;
2573 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2574 opts.debugging_opts.no_analysis = true;
2575 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2576 opts.debugging_opts.unstable_options = true;
2577 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2578 opts.debugging_opts.trace_macros = true;
2579 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2580 opts.debugging_opts.keep_hygiene_data = true;
2581 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2582 opts.debugging_opts.keep_ast = true;
2583 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2584 opts.debugging_opts.print_trans_items = Some(String::from("abc"));
2585 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2586 opts.debugging_opts.dump_mir = Some(String::from("abc"));
2587 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2588 opts.debugging_opts.dump_mir_dir = Some(String::from("abc"));
2589 assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2591 // Make sure changing a [TRACKED] option changes the hash
2592 opts = reference.clone();
2593 opts.debugging_opts.asm_comments = true;
2594 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2596 opts = reference.clone();
2597 opts.debugging_opts.no_verify = true;
2598 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2600 opts = reference.clone();
2601 opts.debugging_opts.no_landing_pads = true;
2602 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2604 opts = reference.clone();
2605 opts.debugging_opts.no_trans = true;
2606 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2608 opts = reference.clone();
2609 opts.debugging_opts.treat_err_as_bug = true;
2610 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2612 opts = reference.clone();
2613 opts.debugging_opts.continue_parse_after_error = true;
2614 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2616 opts = reference.clone();
2617 opts.debugging_opts.extra_plugins = vec![String::from("plugin1"), String::from("plugin2")];
2618 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2620 opts = reference.clone();
2621 opts.debugging_opts.force_overflow_checks = Some(true);
2622 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2624 opts = reference.clone();
2625 opts.debugging_opts.enable_nonzeroing_move_hints = true;
2626 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2628 opts = reference.clone();
2629 opts.debugging_opts.show_span = Some(String::from("abc"));
2630 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2632 opts = reference.clone();
2633 opts.debugging_opts.mir_opt_level = 3;
2634 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2636 opts = reference.clone();
2637 opts.debugging_opts.relro_level = Some(RelroLevel::Full);
2638 assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());