Move basic_options to impl of Default

This commit is contained in:
Mark Rousskov 2018-07-26 12:36:11 -06:00
parent 3cc4450a8a
commit 5fcef251d3
5 changed files with 70 additions and 68 deletions

View File

@ -596,37 +596,38 @@ pub fn host_triple() -> &'static str {
(option_env!("CFG_COMPILER_HOST_TRIPLE")).expect("CFG_COMPILER_HOST_TRIPLE")
}
/// Some reasonable defaults
pub fn basic_options() -> Options {
Options {
crate_types: Vec::new(),
optimize: OptLevel::No,
debuginfo: DebugInfo::None,
lint_opts: Vec::new(),
lint_cap: None,
describe_lints: false,
output_types: OutputTypes(BTreeMap::new()),
search_paths: SearchPaths::new(),
maybe_sysroot: None,
target_triple: TargetTriple::from_triple(host_triple()),
test: false,
incremental: None,
debugging_opts: basic_debugging_options(),
prints: Vec::new(),
borrowck_mode: BorrowckMode::Ast,
cg: basic_codegen_options(),
error_format: ErrorOutputType::default(),
externs: Externs(BTreeMap::new()),
crate_name: None,
alt_std_name: None,
libs: Vec::new(),
unstable_features: UnstableFeatures::Disallow,
debug_assertions: true,
actually_rustdoc: false,
cli_forced_codegen_units: None,
cli_forced_thinlto_off: false,
remap_path_prefix: Vec::new(),
edition: DEFAULT_EDITION,
impl Default for Options {
fn default() -> Options {
Options {
crate_types: Vec::new(),
optimize: OptLevel::No,
debuginfo: DebugInfo::None,
lint_opts: Vec::new(),
lint_cap: None,
describe_lints: false,
output_types: OutputTypes(BTreeMap::new()),
search_paths: SearchPaths::new(),
maybe_sysroot: None,
target_triple: TargetTriple::from_triple(host_triple()),
test: false,
incremental: None,
debugging_opts: basic_debugging_options(),
prints: Vec::new(),
borrowck_mode: BorrowckMode::Ast,
cg: basic_codegen_options(),
error_format: ErrorOutputType::default(),
externs: Externs(BTreeMap::new()),
crate_name: None,
alt_std_name: None,
libs: Vec::new(),
unstable_features: UnstableFeatures::Disallow,
debug_assertions: true,
actually_rustdoc: false,
cli_forced_codegen_units: None,
cli_forced_thinlto_off: false,
remap_path_prefix: Vec::new(),
edition: DEFAULT_EDITION,
}
}
}
@ -2529,6 +2530,7 @@ mod tests {
use syntax::symbol::Symbol;
use syntax::edition::{Edition, DEFAULT_EDITION};
use syntax;
use super::Options;
fn optgroups() -> getopts::Options {
let mut opts = getopts::Options::new();
@ -2613,9 +2615,9 @@ mod tests {
#[test]
fn test_output_types_tracking_hash_different_paths() {
let mut v1 = super::basic_options();
let mut v2 = super::basic_options();
let mut v3 = super::basic_options();
let mut v1 = Options::default();
let mut v2 = Options::default();
let mut v3 = Options::default();
v1.output_types =
OutputTypes::new(&[(OutputType::Exe, Some(PathBuf::from("./some/thing")))]);
@ -2635,8 +2637,8 @@ mod tests {
#[test]
fn test_output_types_tracking_hash_different_construction_order() {
let mut v1 = super::basic_options();
let mut v2 = super::basic_options();
let mut v1 = Options::default();
let mut v2 = Options::default();
v1.output_types = OutputTypes::new(&[
(OutputType::Exe, Some(PathBuf::from("./some/thing"))),
@ -2656,9 +2658,9 @@ mod tests {
#[test]
fn test_externs_tracking_hash_different_construction_order() {
let mut v1 = super::basic_options();
let mut v2 = super::basic_options();
let mut v3 = super::basic_options();
let mut v1 = Options::default();
let mut v2 = Options::default();
let mut v3 = Options::default();
v1.externs = Externs::new(mk_map(vec![
(
@ -2705,9 +2707,9 @@ mod tests {
#[test]
fn test_lints_tracking_hash_different_values() {
let mut v1 = super::basic_options();
let mut v2 = super::basic_options();
let mut v3 = super::basic_options();
let mut v1 = Options::default();
let mut v2 = Options::default();
let mut v3 = Options::default();
v1.lint_opts = vec![
(String::from("a"), lint::Allow),
@ -2742,8 +2744,8 @@ mod tests {
#[test]
fn test_lints_tracking_hash_different_construction_order() {
let mut v1 = super::basic_options();
let mut v2 = super::basic_options();
let mut v1 = Options::default();
let mut v2 = Options::default();
v1.lint_opts = vec![
(String::from("a"), lint::Allow),
@ -2768,10 +2770,10 @@ mod tests {
#[test]
fn test_search_paths_tracking_hash_different_order() {
let mut v1 = super::basic_options();
let mut v2 = super::basic_options();
let mut v3 = super::basic_options();
let mut v4 = super::basic_options();
let mut v1 = Options::default();
let mut v2 = Options::default();
let mut v3 = Options::default();
let mut v4 = Options::default();
// Reference
v1.search_paths
@ -2831,10 +2833,10 @@ mod tests {
#[test]
fn test_native_libs_tracking_hash_different_values() {
let mut v1 = super::basic_options();
let mut v2 = super::basic_options();
let mut v3 = super::basic_options();
let mut v4 = super::basic_options();
let mut v1 = Options::default();
let mut v2 = Options::default();
let mut v3 = Options::default();
let mut v4 = Options::default();
// Reference
v1.libs = vec![
@ -2881,9 +2883,9 @@ mod tests {
#[test]
fn test_native_libs_tracking_hash_different_order() {
let mut v1 = super::basic_options();
let mut v2 = super::basic_options();
let mut v3 = super::basic_options();
let mut v1 = Options::default();
let mut v2 = Options::default();
let mut v3 = Options::default();
// Reference
v1.libs = vec![
@ -2916,8 +2918,8 @@ mod tests {
#[test]
fn test_codegen_options_tracking_hash() {
let reference = super::basic_options();
let mut opts = super::basic_options();
let reference = Options::default();
let mut opts = Options::default();
// Make sure the changing an [UNTRACKED] option leaves the hash unchanged
opts.cg.ar = Some(String::from("abc"));
@ -3054,8 +3056,8 @@ mod tests {
#[test]
fn test_debugging_options_tracking_hash() {
let reference = super::basic_options();
let mut opts = super::basic_options();
let reference = Options::default();
let mut opts = Options::default();
// Make sure the changing an [UNTRACKED] option leaves the hash unchanged
opts.debugging_opts.verbose = true;
@ -3184,7 +3186,7 @@ mod tests {
#[test]
fn test_edition_parsing() {
// test default edition
let options = super::basic_options();
let options = Options::default();
assert!(options.edition == DEFAULT_EDITION);
let matches = optgroups()

View File

@ -99,7 +99,7 @@ fn test_env<F>(source_string: &str,
where F: FnOnce(Env)
{
syntax::with_globals(|| {
let mut options = config::basic_options();
let mut options = config::Options::default();
options.debugging_opts.verbose = true;
options.unstable_features = UnstableFeatures::Allow;

View File

@ -43,7 +43,7 @@ use clean;
use clean::Clean;
use html::render::RenderInfo;
pub use rustc::session::config::{Input, CodegenOptions};
pub use rustc::session::config::{Input, Options, CodegenOptions};
pub use rustc::session::search_paths::SearchPaths;
pub type ExternalPaths = FxHashMap<DefId, (Vec<String>, clean::TypeKind)>;
@ -127,7 +127,7 @@ pub fn new_handler(error_format: ErrorOutputType, codemap: Option<Lrc<codemap::C
{
// rustdoc doesn't override (or allow to override) anything from this that is relevant here, so
// stick to the defaults
let sessopts = config::basic_options();
let sessopts = Options::default();
let emitter: Box<dyn Emitter + sync::Send> = match error_format {
ErrorOutputType::HumanReadable(color_config) => Box::new(
EmitterWriter::stderr(
@ -243,7 +243,7 @@ pub fn run_core(search_paths: SearchPaths,
error_format,
edition,
describe_lints,
..config::basic_options()
..Options::default()
};
driver::spawn_thread_pool(sessopts, move |sessopts| {
let codemap = Lrc::new(codemap::CodeMap::new(sessopts.file_path_mapping()));

View File

@ -83,7 +83,7 @@ pub fn run(input_path: &Path,
..config::basic_debugging_options()
},
edition,
..config::basic_options().clone()
..config::Options::default()
};
driver::spawn_thread_pool(sessopts, |sessopts| {
let codemap = Lrc::new(CodeMap::new(sessopts.file_path_mapping()));
@ -230,7 +230,7 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize,
..config::basic_debugging_options()
},
edition,
..config::basic_options().clone()
..config::Options::default()
};
// Shuffle around a few input and output handles here. We're going to pass

View File

@ -19,7 +19,7 @@ extern crate rustc_codegen_utils;
extern crate syntax;
use rustc::session::{build_session, Session};
use rustc::session::config::{basic_options, Input, Options,
use rustc::session::config::{Input, Options,
OutputType, OutputTypes};
use rustc_driver::driver::{self, compile_input, CompileController};
use rustc_metadata::cstore::CStore;
@ -63,7 +63,7 @@ fn basic_sess(opts: Options) -> (Session, Rc<CStore>, Box<CodegenBackend>) {
fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
syntax::with_globals(|| {
let mut opts = basic_options();
let mut opts = Options::default();
opts.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
opts.maybe_sysroot = Some(sysroot);
if let Ok(linker) = std::env::var("RUSTC_LINKER") {