diff options
Diffstat (limited to 'src/librustc_session/config.rs')
| -rw-r--r-- | src/librustc_session/config.rs | 163 |
1 files changed, 80 insertions, 83 deletions
diff --git a/src/librustc_session/config.rs b/src/librustc_session/config.rs index a6f9a5fe3e0..8a690621a6e 100644 --- a/src/librustc_session/config.rs +++ b/src/librustc_session/config.rs @@ -18,9 +18,10 @@ use rustc_feature::UnstableFeatures; use rustc_span::edition::{Edition, DEFAULT_EDITION, EDITION_NAME_LIST}; use rustc_span::source_map::{FileName, FilePathMapping}; use rustc_span::symbol::{sym, Symbol}; +use rustc_span::SourceFileHashAlgorithm; use rustc_errors::emitter::HumanReadableErrorType; -use rustc_errors::{ColorConfig, FatalError, Handler, HandlerFlags}; +use rustc_errors::{ColorConfig, HandlerFlags}; use std::collections::btree_map::{ Iter as BTreeMapIter, Keys as BTreeMapKeysIter, Values as BTreeMapValuesIter, @@ -391,6 +392,7 @@ impl ExternEntry { pub enum PrintRequest { FileNames, Sysroot, + TargetLibdir, CrateName, Cfg, TargetList, @@ -615,10 +617,6 @@ impl Options { } impl DebuggingOptions { - pub fn ui_testing(&self) -> bool { - self.ui_testing.unwrap_or(false) - } - pub fn diagnostic_handler_flags(&self, can_emit_warnings: bool) -> HandlerFlags { HandlerFlags { can_emit_warnings, @@ -626,7 +624,7 @@ impl DebuggingOptions { dont_buffer_diagnostics: self.dont_buffer_diagnostics, report_delayed_bugs: self.report_delayed_bugs, macro_backtrace: self.macro_backtrace, - deduplicate_diagnostics: self.deduplicate_diagnostics.unwrap_or(true), + deduplicate_diagnostics: self.deduplicate_diagnostics, } } } @@ -747,25 +745,30 @@ pub fn build_configuration(sess: &Session, mut user_cfg: CrateConfig) -> CrateCo user_cfg } -pub fn build_target_config(opts: &Options, sp: &Handler) -> Config { +pub fn build_target_config(opts: &Options, error_format: ErrorOutputType) -> Config { let target = Target::search(&opts.target_triple).unwrap_or_else(|e| { - sp.struct_fatal(&format!("Error loading target specification: {}", e)) - .help("Use `--print target-list` for a list of built-in targets") - .emit(); - FatalError.raise(); + early_error( + error_format, + &format!( + "Error loading target specification: {}. \ + Use `--print target-list` for a list of built-in targets", + e + ), + ) }); let ptr_width = match &target.target_pointer_width[..] { "16" => 16, "32" => 32, "64" => 64, - w => sp - .fatal(&format!( + w => early_error( + error_format, + &format!( "target specification was invalid: \ unrecognized target-pointer-width {}", w - )) - .raise(), + ), + ), }; Config { target, ptr_width } @@ -912,7 +915,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> { "", "print", "Compiler information to print on stdout", - "[crate-name|file-names|sysroot|cfg|target-list|\ + "[crate-name|file-names|sysroot|target-libdir|cfg|target-list|\ target-cpus|target-features|relocation-models|\ code-models|tls-models|target-spec-json|native-static-libs]", ), @@ -1010,7 +1013,15 @@ pub fn get_cmd_lint_options( let mut describe_lints = false; for &level in &[lint::Allow, lint::Warn, lint::Deny, lint::Forbid] { - for (arg_pos, lint_name) in matches.opt_strs_pos(level.as_str()) { + for (passed_arg_pos, lint_name) in matches.opt_strs_pos(level.as_str()) { + let arg_pos = if let lint::Forbid = level { + // HACK: forbid is always specified last, so it can't be overridden. + // FIXME: remove this once <https://github.com/rust-lang/rust/issues/70819> is + // fixed and `forbid` works as expected. + usize::max_value() + } else { + passed_arg_pos + }; if lint_name == "help" { describe_lints = true; } else { @@ -1129,7 +1140,7 @@ pub fn parse_error_format( // Conservatively require that the `--json` argument is coupled with // `--error-format=json`. This means that `--json` is specified we // should actually be emitting JSON blobs. - _ if matches.opt_strs("json").len() > 0 => { + _ if !matches.opt_strs("json").is_empty() => { early_error( ErrorOutputType::default(), "using `--json` requires also using `--error-format=json`", @@ -1139,7 +1150,7 @@ pub fn parse_error_format( _ => {} } - return error_format; + error_format } fn parse_crate_edition(matches: &getopts::Matches) -> Edition { @@ -1285,33 +1296,6 @@ fn check_thread_count(debugging_opts: &DebuggingOptions, error_format: ErrorOutp } } -fn select_incremental_path( - debugging_opts: &DebuggingOptions, - cg: &CodegenOptions, - error_format: ErrorOutputType, -) -> Option<PathBuf> { - match (&debugging_opts.incremental, &cg.incremental) { - (Some(path1), Some(path2)) => { - if path1 != path2 { - early_error( - error_format, - &format!( - "conflicting paths for `-Z incremental` and \ - `-C incremental` specified: {} versus {}", - path1, path2 - ), - ); - } else { - Some(path1) - } - } - (Some(path), None) => Some(path), - (None, Some(path)) => Some(path), - (None, None) => None, - } - .map(|m| PathBuf::from(m)) -} - fn collect_print_requests( cg: &mut CodegenOptions, dopts: &mut DebuggingOptions, @@ -1327,23 +1311,16 @@ fn collect_print_requests( prints.push(PrintRequest::TargetFeatures); cg.target_feature = String::new(); } - if cg.relocation_model.as_ref().map_or(false, |s| s == "help") { - prints.push(PrintRequest::RelocationModels); - cg.relocation_model = None; - } if cg.code_model.as_ref().map_or(false, |s| s == "help") { prints.push(PrintRequest::CodeModels); cg.code_model = None; } - if dopts.tls_model.as_ref().map_or(false, |s| s == "help") { - prints.push(PrintRequest::TlsModels); - dopts.tls_model = None; - } prints.extend(matches.opt_strs("print").into_iter().map(|s| match &*s { "crate-name" => PrintRequest::CrateName, "file-names" => PrintRequest::FileNames, "sysroot" => PrintRequest::Sysroot, + "target-libdir" => PrintRequest::TargetLibdir, "cfg" => PrintRequest::Cfg, "target-list" => PrintRequest::TargetList, "target-cpus" => PrintRequest::TargetCPUs, @@ -1406,15 +1383,14 @@ fn parse_opt_level( if max_o > max_c { OptLevel::Default } else { - match cg.opt_level.as_ref().map(String::as_ref) { - None => OptLevel::No, - Some("0") => OptLevel::No, - Some("1") => OptLevel::Less, - Some("2") => OptLevel::Default, - Some("3") => OptLevel::Aggressive, - Some("s") => OptLevel::Size, - Some("z") => OptLevel::SizeMin, - Some(arg) => { + match cg.opt_level.as_ref() { + "0" => OptLevel::No, + "1" => OptLevel::Less, + "2" => OptLevel::Default, + "3" => OptLevel::Aggressive, + "s" => OptLevel::Size, + "z" => OptLevel::SizeMin, + arg => { early_error( error_format, &format!( @@ -1447,10 +1423,10 @@ fn select_debuginfo( DebugInfo::Full } else { match cg.debuginfo { - None | Some(0) => DebugInfo::None, - Some(1) => DebugInfo::Limited, - Some(2) => DebugInfo::Full, - Some(arg) => { + 0 => DebugInfo::None, + 1 => DebugInfo::Limited, + 2 => DebugInfo::Full, + arg => { early_error( error_format, &format!( @@ -1500,10 +1476,8 @@ fn parse_libs( { early_error( error_format, - &format!( - "the library kind 'static-nobundle' is only \ - accepted on the nightly compiler" - ), + "the library kind 'static-nobundle' is only \ + accepted on the nightly compiler", ); } let mut name_parts = name.splitn(2, ':'); @@ -1515,10 +1489,10 @@ fn parse_libs( } fn parse_borrowck_mode(dopts: &DebuggingOptions, error_format: ErrorOutputType) -> BorrowckMode { - match dopts.borrowck.as_ref().map(|s| &s[..]) { - None | Some("migrate") => BorrowckMode::Migrate, - Some("mir") => BorrowckMode::Mir, - Some(m) => early_error(error_format, &format!("unknown borrowck mode `{}`", m)), + match dopts.borrowck.as_ref() { + "migrate" => BorrowckMode::Migrate, + "mir" => BorrowckMode::Mir, + m => early_error(error_format, &format!("unknown borrowck mode `{}`", m)), } } @@ -1668,7 +1642,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { let output_types = parse_output_types(&debugging_opts, matches, error_format); let mut cg = build_codegen_options(matches, error_format); - let (disable_thinlto, codegen_units) = should_override_cgus_and_disable_thinlto( + let (disable_thinlto, mut codegen_units) = should_override_cgus_and_disable_thinlto( &output_types, matches, error_format, @@ -1677,7 +1651,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { check_thread_count(&debugging_opts, error_format); - let incremental = select_incremental_path(&debugging_opts, &cg, error_format); + let incremental = cg.incremental.as_ref().map(PathBuf::from); if debugging_opts.profile && incremental.is_some() { early_error( @@ -1685,6 +1659,16 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { "can't instrument with gcov profiling when compiling incrementally", ); } + if debugging_opts.profile { + match codegen_units { + Some(1) => {} + None => codegen_units = Some(1), + Some(_) => early_error( + error_format, + "can't instrument with gcov profiling with multiple codegen units", + ), + } + } if cg.profile_generate.enabled() && cg.profile_use.is_some() { early_error( @@ -1693,6 +1677,16 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { ); } + if !cg.embed_bitcode { + match cg.lto { + LtoCli::No | LtoCli::Unspecified => {} + LtoCli::Yes | LtoCli::NoParam | LtoCli::Thin | LtoCli::Fat => early_error( + error_format, + "options `-C embed-bitcode=no` and `-C lto` are incompatible", + ), + } + } + let prints = collect_print_requests(&mut cg, &mut debugging_opts, matches, error_format); let cg = cg; @@ -1955,11 +1949,9 @@ impl PpMode { use PpMode::*; use PpSourceMode::*; match *self { - PpmSource(PpmNormal) | PpmSource(PpmEveryBodyLoops) | PpmSource(PpmIdentified) => false, + PpmSource(PpmNormal | PpmEveryBodyLoops | PpmIdentified) => false, - PpmSource(PpmExpanded) - | PpmSource(PpmExpandedIdentified) - | PpmSource(PpmExpandedHygiene) + PpmSource(PpmExpanded | PpmExpandedIdentified | PpmExpandedHygiene) | PpmHir(_) | PpmHirTree(_) | PpmMir @@ -1998,13 +1990,15 @@ impl PpMode { crate mod dep_tracking { use super::{ CFGuard, CrateType, DebugInfo, ErrorOutputType, LinkerPluginLto, LtoCli, OptLevel, - OutputTypes, Passes, Sanitizer, SwitchWithOptPath, SymbolManglingVersion, + OutputTypes, Passes, Sanitizer, SourceFileHashAlgorithm, SwitchWithOptPath, + SymbolManglingVersion, }; use crate::lint; use crate::utils::NativeLibraryKind; use rustc_feature::UnstableFeatures; use rustc_span::edition::Edition; - use rustc_target::spec::{MergeFunctions, PanicStrategy, RelroLevel, TargetTriple}; + use rustc_target::spec::{MergeFunctions, PanicStrategy, RelocModel}; + use rustc_target::spec::{RelroLevel, TargetTriple, TlsModel}; use std::collections::hash_map::DefaultHasher; use std::collections::BTreeMap; use std::hash::Hash; @@ -2052,6 +2046,8 @@ crate mod dep_tracking { impl_dep_tracking_hash_via_hash!(Option<(String, u64)>); impl_dep_tracking_hash_via_hash!(Option<Vec<String>>); impl_dep_tracking_hash_via_hash!(Option<MergeFunctions>); + impl_dep_tracking_hash_via_hash!(Option<RelocModel>); + impl_dep_tracking_hash_via_hash!(Option<TlsModel>); impl_dep_tracking_hash_via_hash!(Option<PanicStrategy>); impl_dep_tracking_hash_via_hash!(Option<RelroLevel>); impl_dep_tracking_hash_via_hash!(Option<lint::Level>); @@ -2076,6 +2072,7 @@ crate mod dep_tracking { impl_dep_tracking_hash_via_hash!(LinkerPluginLto); impl_dep_tracking_hash_via_hash!(SwitchWithOptPath); impl_dep_tracking_hash_via_hash!(SymbolManglingVersion); + impl_dep_tracking_hash_via_hash!(Option<SourceFileHashAlgorithm>); impl_dep_tracking_hash_for_sortable_vec_of!(String); impl_dep_tracking_hash_for_sortable_vec_of!(PathBuf); |
