pub use crate::options::*;
use crate::lint;
+use crate::search_paths::SearchPath;
use crate::utils::NativeLibraryKind;
use crate::{early_error, early_warn, Session};
-use crate::search_paths::SearchPath;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::impl_stable_hash_via_hash;
use rustc_target::spec::{Target, TargetTriple};
-use syntax_pos::source_map::{FileName, FilePathMapping};
-use syntax_pos::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION};
-use syntax_pos::symbol::{sym, Symbol};
-use rustc_feature::UnstableFeatures;
use crate::parse::CrateConfig;
+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_errors::emitter::HumanReadableErrorType;
-use rustc_errors::{ColorConfig, FatalError, Handler};
+use rustc_errors::{ColorConfig, FatalError, Handler, HandlerFlags};
use getopts;
-use std::collections::{BTreeMap, BTreeSet};
use std::collections::btree_map::{
Iter as BTreeMapIter, Keys as BTreeMapKeysIter, Values as BTreeMapValuesIter,
};
+use std::collections::{BTreeMap, BTreeSet};
use std::fmt;
-use std::str::{self, FromStr};
use std::iter::{self, FromIterator};
use std::path::{Path, PathBuf};
+use std::str::{self, FromStr};
pub struct Config {
pub target: Target,
pub enum LinkerPluginLto {
LinkerPlugin(PathBuf),
LinkerPluginAuto,
- Disabled
+ Disabled,
}
impl LinkerPluginLto {
pub fn enabled(&self) -> bool {
match *self {
- LinkerPluginLto::LinkerPlugin(_) |
- LinkerPluginLto::LinkerPluginAuto => true,
+ LinkerPluginLto::LinkerPlugin(_) | LinkerPluginLto::LinkerPluginAuto => true,
LinkerPluginLto::Disabled => false,
}
}
impl OutputTypes {
pub fn new(entries: &[(OutputType, Option<PathBuf>)]) -> OutputTypes {
- OutputTypes(BTreeMap::from_iter(
- entries.iter().map(|&(k, ref v)| (k, v.clone())),
- ))
+ OutputTypes(BTreeMap::from_iter(entries.iter().map(|&(k, ref v)| (k, v.clone()))))
}
pub fn get(&self, key: &OutputType) -> Option<&Option<PathBuf>> {
}
pub fn with_extension(&self, extension: &str) -> PathBuf {
- self.out_directory
- .join(&self.filestem())
- .with_extension(extension)
+ self.out_directory.join(&self.filestem()).with_extension(extension)
}
pub fn filestem(&self) -> String {
impl Options {
/// Returns `true` if there is a reason to build the dep graph.
pub fn build_dep_graph(&self) -> bool {
- self.incremental.is_some() || self.debugging_opts.dump_dep_graph
+ self.incremental.is_some()
+ || self.debugging_opts.dump_dep_graph
|| self.debugging_opts.query_dep_graph
}
pub fn share_generics(&self) -> bool {
match self.debugging_opts.share_generics {
Some(setting) => setting,
- None => {
- match self.optimize {
- OptLevel::No |
- OptLevel::Less |
- OptLevel::Size |
- OptLevel::SizeMin => true,
- OptLevel::Default |
- OptLevel::Aggressive => false,
- }
- }
+ None => match self.optimize {
+ OptLevel::No | OptLevel::Less | OptLevel::Size | OptLevel::SizeMin => true,
+ OptLevel::Default | OptLevel::Aggressive => false,
+ },
+ }
+ }
+}
+
+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,
+ treat_err_as_bug: self.treat_err_as_bug,
+ dont_buffer_diagnostics: self.dont_buffer_diagnostics,
+ report_delayed_bugs: self.report_delayed_bugs,
+ external_macro_backtrace: self.external_macro_backtrace,
+ deduplicate_diagnostics: self.deduplicate_diagnostics.unwrap_or(true),
}
}
}
}
ret.insert((Symbol::intern("target_arch"), Some(Symbol::intern(arch))));
ret.insert((Symbol::intern("target_endian"), Some(Symbol::intern(end))));
- ret.insert((
- Symbol::intern("target_pointer_width"),
- Some(Symbol::intern(wordsz)),
- ));
+ ret.insert((Symbol::intern("target_pointer_width"), Some(Symbol::intern(wordsz))));
ret.insert((Symbol::intern("target_env"), Some(Symbol::intern(env))));
- ret.insert((
- Symbol::intern("target_vendor"),
- Some(Symbol::intern(vendor)),
- ));
+ ret.insert((Symbol::intern("target_vendor"), Some(Symbol::intern(vendor))));
if sess.target.target.options.has_elf_tls {
ret.insert((sym::target_thread_local, None));
}
for &i in &[8, 16, 32, 64, 128] {
if i >= min_atomic_width && i <= max_atomic_width {
let mut insert_atomic = |s| {
- ret.insert((
- sym::target_has_atomic_load_store,
- Some(Symbol::intern(s)),
- ));
+ ret.insert((sym::target_has_atomic_load_store, Some(Symbol::intern(s))));
if atomic_cas {
- ret.insert((
- sym::target_has_atomic,
- Some(Symbol::intern(s))
- ));
+ ret.insert((sym::target_has_atomic, Some(Symbol::intern(s))));
}
};
let s = i.to_string();
insert_atomic(&s);
if &s == wordsz {
- insert_atomic("ptr");
+ insert_atomic("ptr");
}
}
}
/// `rustc_interface::interface::Config` accepts this in the compiler configuration,
/// but the symbol interner is not yet set up then, so we must convert it later.
pub fn to_crate_config(cfg: FxHashSet<(String, Option<String>)>) -> CrateConfig {
- cfg.into_iter()
- .map(|(a, b)| (Symbol::intern(&a), b.map(|b| Symbol::intern(&b))))
- .collect()
+ cfg.into_iter().map(|(a, b)| (Symbol::intern(&a), b.map(|b| Symbol::intern(&b)))).collect()
}
pub fn build_configuration(sess: &Session, mut user_cfg: CrateConfig) -> CrateConfig {
pub fn build_target_config(opts: &Options, sp: &Handler) -> 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();
+ .help("Use `--print target-list` for a list of built-in targets")
+ .emit();
FatalError.raise();
});
"16" => 16,
"32" => 32,
"64" => 64,
- w => sp.fatal(&format!(
- "target specification was invalid: \
+ w => sp
+ .fatal(&format!(
+ "target specification was invalid: \
unrecognized target-pointer-width {}",
- w
- )).raise(),
+ w
+ ))
+ .raise(),
};
- Config {
- target,
- ptr_width,
- }
+ Config { target, ptr_width }
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
where
F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static,
{
- RustcOptGroup {
- name,
- apply: Box::new(f),
- stability: OptionStability::Stable,
- }
+ RustcOptGroup { name, apply: Box::new(f), stability: OptionStability::Stable }
}
pub fn unstable<F>(name: &'static str, f: F) -> RustcOptGroup
where
F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static,
{
- RustcOptGroup {
- name,
- apply: Box::new(f),
- stability: OptionStability::Unstable,
- }
+ RustcOptGroup { name, apply: Box::new(f), stability: OptionStability::Unstable }
}
}
// in the future; do not warn about them not being used right now.
#![allow(dead_code)]
- use getopts;
use super::RustcOptGroup;
+ use getopts;
pub type R = RustcOptGroup;
pub type S = &'static str;
}
fn longer(a: S, b: S) -> S {
- if a.len() > b.len() {
- a
- } else {
- b
- }
+ if a.len() > b.len() { a } else { b }
}
pub fn opt_s(a: S, b: S, c: S, d: S) -> R {
"[KIND=]NAME",
),
make_crate_type_option(),
- opt::opt_s(
- "",
- "crate-name",
- "Specify the name of the crate being built",
- "NAME",
- ),
+ opt::opt_s("", "crate-name", "Specify the name of the crate being built", "NAME"),
opt::opt_s(
"",
"edition",
"OPT",
),
opt::flag_s("", "test", "Build a test harness"),
- opt::opt_s(
- "",
- "target",
- "Target triple for which the code is compiled",
- "TARGET",
- ),
+ opt::opt_s("", "target", "Target triple for which the code is compiled", "TARGET"),
opt::multi_s("W", "warn", "Set lint warnings", "OPT"),
opt::multi_s("A", "allow", "Set lint allowed", "OPT"),
opt::multi_s("D", "deny", "Set lint denied", "OPT"),
"How errors and other messages are produced",
"human|json|short",
),
- opt::multi_s(
- "",
- "json",
- "Configure the JSON output of the compiler",
- "CONFIG",
- ),
+ opt::multi_s("", "json", "Configure the JSON output of the compiler", "CONFIG"),
opt::opt_s(
"",
"color",
opts
}
-pub fn get_cmd_lint_options(matches: &getopts::Matches,
- error_format: ErrorOutputType)
- -> (Vec<(String, lint::Level)>, bool, Option<lint::Level>) {
+pub fn get_cmd_lint_options(
+ matches: &getopts::Matches,
+ error_format: ErrorOutputType,
+) -> (Vec<(String, lint::Level)>, bool, Option<lint::Level>) {
let mut lint_opts = vec![];
let mut describe_lints = false;
"diagnostic-short" => json_rendered = HumanReadableErrorType::Short,
"diagnostic-rendered-ansi" => json_color = ColorConfig::Always,
"artifacts" => json_artifact_notifications = true,
- s => {
- early_error(
- ErrorOutputType::default(),
- &format!("unknown `--json` option `{}`", s),
- )
- }
+ s => early_error(
+ ErrorOutputType::default(),
+ &format!("unknown `--json` option `{}`", s),
+ ),
}
}
}
// `opt_present` because the latter will panic.
let error_format = if matches.opts_present(&["error-format".to_owned()]) {
match matches.opt_str("error-format").as_ref().map(|s| &s[..]) {
- None |
- Some("human") => ErrorOutputType::HumanReadable(HumanReadableErrorType::Default(color)),
+ None | Some("human") => {
+ ErrorOutputType::HumanReadable(HumanReadableErrorType::Default(color))
+ }
Some("human-annotate-rs") => {
ErrorOutputType::HumanReadable(HumanReadableErrorType::AnnotateSnippet(color))
- },
+ }
Some("json") => ErrorOutputType::Json { pretty: false, json_rendered },
Some("pretty-json") => ErrorOutputType::Json { pretty: true, json_rendered },
Some("short") => ErrorOutputType::HumanReadable(HumanReadableErrorType::Short(color)),
fn parse_crate_edition(matches: &getopts::Matches) -> Edition {
let edition = match matches.opt_str("edition") {
- Some(arg) => Edition::from_str(&arg).unwrap_or_else(|_|
+ Some(arg) => Edition::from_str(&arg).unwrap_or_else(|_| {
early_error(
ErrorOutputType::default(),
&format!(
"argument for `--edition` must be one of: \
{}. (instead was `{}`)",
- EDITION_NAME_LIST,
- arg
+ EDITION_NAME_LIST, arg
),
- ),
- ),
+ )
+ }),
None => DEFAULT_EDITION,
};
if !edition.is_stable() && !nightly_options::is_nightly_build() {
early_error(
- ErrorOutputType::default(),
- &format!(
- "edition {} is unstable and only \
+ ErrorOutputType::default(),
+ &format!(
+ "edition {} is unstable and only \
available for nightly builds of rustc.",
- edition,
- )
+ edition,
+ ),
)
}
);
}
if let ErrorOutputType::HumanReadable(HumanReadableErrorType::AnnotateSnippet(_)) =
- error_format {
+ error_format
+ {
early_error(
ErrorOutputType::Json { pretty: false, json_rendered },
"`--error-format=human-annotate-rs` is unstable",
for output_type in list.split(',') {
let mut parts = output_type.splitn(2, '=');
let shorthand = parts.next().unwrap();
- let output_type = OutputType::from_shorthand(shorthand).unwrap_or_else(||
+ let output_type = OutputType::from_shorthand(shorthand).unwrap_or_else(|| {
early_error(
error_format,
&format!(
shorthand,
OutputType::shorthands_display(),
),
- ),
- );
+ )
+ });
let path = parts.next().map(PathBuf::from);
output_types.insert(output_type, path);
}
let mut disable_thinlto = false;
// Issue #30063: if user requests LLVM-related output to one
// particular path, disable codegen-units.
- let incompatible: Vec<_> = output_types.0
+ let incompatible: Vec<_> = output_types
+ .0
.iter()
.map(|ot_path| ot_path.0)
.filter(|ot| !ot.is_compatible_with_codegen_units_and_single_output_file())
}
if codegen_units == Some(0) {
- early_error(
- error_format,
- "value for codegen units must be a positive non-zero integer",
- );
+ early_error(error_format, "value for codegen units must be a positive non-zero integer");
}
(disable_thinlto, codegen_units)
fn check_thread_count(debugging_opts: &DebuggingOptions, error_format: ErrorOutputType) {
if debugging_opts.threads == 0 {
- early_error(
- error_format,
- "value for threads must be a positive non-zero integer",
- );
+ early_error(error_format, "value for threads must be a positive non-zero integer");
}
if debugging_opts.threads > 1 && debugging_opts.fuel.is_some() {
- early_error(
- error_format,
- "optimization fuel is incompatible with multiple threads",
- );
+ early_error(error_format, "optimization fuel is incompatible with multiple threads");
}
}
(Some(path), None) => Some(path),
(None, Some(path)) => Some(path),
(None, None) => None,
- }.map(|m| PathBuf::from(m))
+ }
+ .map(|m| PathBuf::from(m))
}
fn collect_print_requests(
prints.push(PrintRequest::CodeModels);
cg.code_model = None;
}
- if dopts
- .tls_model
- .as_ref()
- .map_or(false, |s| s == "help")
- {
+ if dopts.tls_model.as_ref().map_or(false, |s| s == "help") {
prints.push(PrintRequest::TlsModels);
dopts.tls_model = None;
}
match matches.opt_str("target") {
Some(target) if target.ends_with(".json") => {
let path = Path::new(&target);
- TargetTriple::from_path(&path).unwrap_or_else(|_|
- early_error(error_format, &format!("target file {:?} does not exist", path)))
+ TargetTriple::from_path(&path).unwrap_or_else(|_| {
+ early_error(error_format, &format!("target file {:?} does not exist", path))
+ })
}
Some(target) => TargetTriple::TargetTriple(target),
_ => TargetTriple::from_triple(host_triple()),
// comparing them. Note that if a flag is not found, its position will be `None`, which
// always compared less than `Some(_)`.
let max_o = matches.opt_positions("O").into_iter().max();
- let max_c = matches.opt_strs_pos("C").into_iter().flat_map(|(i, s)| {
- if let Some("opt-level") = s.splitn(2, '=').next() {
- Some(i)
- } else {
- None
- }
- }).max();
+ let max_c = matches
+ .opt_strs_pos("C")
+ .into_iter()
+ .flat_map(
+ |(i, s)| {
+ if let Some("opt-level") = s.splitn(2, '=').next() { Some(i) } else { None }
+ },
+ )
+ .max();
if max_o > max_c {
OptLevel::Default
} else {
error_format: ErrorOutputType,
) -> DebugInfo {
let max_g = matches.opt_positions("g").into_iter().max();
- let max_c = matches.opt_strs_pos("C").into_iter().flat_map(|(i, s)| {
- if let Some("debuginfo") = s.splitn(2, '=').next() {
- Some(i)
- } else {
- None
- }
- }).max();
+ let max_c = matches
+ .opt_strs_pos("C")
+ .into_iter()
+ .flat_map(
+ |(i, s)| {
+ if let Some("debuginfo") = s.splitn(2, '=').next() { Some(i) } else { None }
+ },
+ )
+ .max();
if max_g > max_c {
DebugInfo::Full
} else {
);
}
};
- if kind == Some(NativeLibraryKind::NativeStaticNobundle) &&
- !nightly_options::is_nightly_build() {
+ if kind == Some(NativeLibraryKind::NativeStaticNobundle)
+ && !nightly_options::is_nightly_build()
+ {
early_error(
error_format,
&format!(
fn parse_remap_path_prefix(
matches: &getopts::Matches,
- error_format: ErrorOutputType
+ error_format: ErrorOutputType,
) -> Vec<(PathBuf, PathBuf)> {
matches
.opt_strs("remap-path-prefix")
);
}
- let prints = collect_print_requests(
- &mut cg,
- &mut debugging_opts,
- matches,
- error_format,
- );
+ let prints = collect_print_requests(&mut cg, &mut debugging_opts, matches, error_format);
let cg = cg;
let borrowck_mode = parse_borrowck_mode(&debugging_opts, error_format);
if !cg.remark.is_empty() && debuginfo == DebugInfo::None {
- early_warn(
- error_format,
- "-C remark requires \"-C debuginfo=n\" to show source locations",
- );
+ early_warn(error_format, "-C remark requires \"-C debuginfo=n\" to show source locations");
}
let externs = parse_externs(matches, &debugging_opts, error_format);
pretty
};
- fn parse_pretty_inner(
- efmt: ErrorOutputType,
- name: &str,
- extended: bool,
- ) -> PpMode {
+ fn parse_pretty_inner(efmt: ErrorOutputType, name: &str, extended: bool) -> PpMode {
use PpMode::*;
use PpSourceMode::*;
let first = match (name, extended) {
("mir-cfg", true) => PpmMirCFG,
_ => {
if extended {
- early_error(efmt, &format!("argument to `unpretty` must be one of `normal`, \
+ early_error(
+ efmt,
+ &format!(
+ "argument to `unpretty` must be one of `normal`, \
`expanded`, `identified`, `expanded,identified`, \
`expanded,hygiene`, `everybody_loops`, \
`hir`, `hir,identified`, `hir,typed`, `hir-tree`, \
`mir` or `mir-cfg`; got {}",
- name));
+ name
+ ),
+ );
} else {
- early_error(efmt, &format!("argument to `pretty` must be one of `normal`, \
+ early_error(
+ efmt,
+ &format!(
+ "argument to `pretty` must be one of `normal`, \
`expanded`, `identified`, or `expanded,identified`; got {}",
- name));
+ name
+ ),
+ );
}
}
};
"cdylib" => CrateType::Cdylib,
"bin" => CrateType::Executable,
"proc-macro" => CrateType::ProcMacro,
- _ => return Err(format!("unknown crate type: `{}`", part))
+ _ => return Err(format!("unknown crate type: `{}`", part)),
};
if !crate_types.contains(&new_part) {
crate_types.push(new_part)
}
pub mod nightly_options {
- use getopts;
- use rustc_feature::UnstableFeatures;
use super::{ErrorOutputType, OptionStability, RustcOptGroup};
use crate::early_error;
+ use getopts;
+ use rustc_feature::UnstableFeatures;
pub fn is_unstable_enabled(matches: &getopts::Matches) -> bool {
- is_nightly_build()
- && matches
- .opt_strs("Z")
- .iter()
- .any(|x| *x == "unstable-options")
+ is_nightly_build() && matches.opt_strs("Z").iter().any(|x| *x == "unstable-options")
}
pub fn is_nightly_build() -> bool {
}
pub fn check_nightly_options(matches: &getopts::Matches, flags: &[RustcOptGroup]) {
- let has_z_unstable_option = matches
- .opt_strs("Z")
- .iter()
- .any(|x| *x == "unstable-options");
+ let has_z_unstable_option = matches.opt_strs("Z").iter().any(|x| *x == "unstable-options");
let really_allows_unstable_options =
UnstableFeatures::from_environment().is_nightly_build();
use PpMode::*;
use PpSourceMode::*;
match *self {
- PpmSource(PpmNormal) |
- PpmSource(PpmEveryBodyLoops) |
- PpmSource(PpmIdentified) => false,
-
- PpmSource(PpmExpanded) |
- PpmSource(PpmExpandedIdentified) |
- PpmSource(PpmExpandedHygiene) |
- PpmHir(_) |
- PpmHirTree(_) |
- PpmMir |
- PpmMirCFG => true,
+ PpmSource(PpmNormal) | PpmSource(PpmEveryBodyLoops) | PpmSource(PpmIdentified) => false,
+
+ PpmSource(PpmExpanded)
+ | PpmSource(PpmExpandedIdentified)
+ | PpmSource(PpmExpandedHygiene)
+ | PpmHir(_)
+ | PpmHirTree(_)
+ | PpmMir
+ | PpmMirCFG => true,
PpmSource(PpmTyped) => panic!("invalid state"),
}
}
/// we have an opt-in scheme here, so one is hopefully forced to think about
/// how the hash should be calculated when adding a new command-line argument.
crate mod dep_tracking {
+ use super::{
+ CrateType, DebugInfo, ErrorOutputType, LinkerPluginLto, LtoCli, OptLevel, OutputTypes,
+ Passes, Sanitizer, 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 std::collections::hash_map::DefaultHasher;
use std::collections::BTreeMap;
use std::hash::Hash;
use std::path::PathBuf;
- use std::collections::hash_map::DefaultHasher;
- use super::{CrateType, DebugInfo, ErrorOutputType, OptLevel, OutputTypes,
- Passes, Sanitizer, LtoCli, LinkerPluginLto, SwitchWithOptPath,
- SymbolManglingVersion};
- use rustc_target::spec::{MergeFunctions, PanicStrategy, RelroLevel, TargetTriple};
- use syntax_pos::edition::Edition;
- use rustc_feature::UnstableFeatures;
pub trait DepTrackingHash {
fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType);
}
macro_rules! impl_dep_tracking_hash_via_hash {
- ($t:ty) => (
+ ($t:ty) => {
impl DepTrackingHash for $t {
fn hash(&self, hasher: &mut DefaultHasher, _: ErrorOutputType) {
Hash::hash(self, hasher);
}
}
- )
+ };
}
macro_rules! impl_dep_tracking_hash_for_sortable_vec_of {
- ($t:ty) => (
+ ($t:ty) => {
impl DepTrackingHash for Vec<$t> {
fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) {
let mut elems: Vec<&$t> = self.iter().collect();
}
}
}
- );
+ };
}
impl_dep_tracking_hash_via_hash!(bool);