mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 19:58:32 +00:00
Move basic_options to impl of Default
This commit is contained in:
parent
3cc4450a8a
commit
5fcef251d3
@ -596,37 +596,38 @@ pub fn host_triple() -> &'static str {
|
|||||||
(option_env!("CFG_COMPILER_HOST_TRIPLE")).expect("CFG_COMPILER_HOST_TRIPLE")
|
(option_env!("CFG_COMPILER_HOST_TRIPLE")).expect("CFG_COMPILER_HOST_TRIPLE")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Some reasonable defaults
|
impl Default for Options {
|
||||||
pub fn basic_options() -> Options {
|
fn default() -> Options {
|
||||||
Options {
|
Options {
|
||||||
crate_types: Vec::new(),
|
crate_types: Vec::new(),
|
||||||
optimize: OptLevel::No,
|
optimize: OptLevel::No,
|
||||||
debuginfo: DebugInfo::None,
|
debuginfo: DebugInfo::None,
|
||||||
lint_opts: Vec::new(),
|
lint_opts: Vec::new(),
|
||||||
lint_cap: None,
|
lint_cap: None,
|
||||||
describe_lints: false,
|
describe_lints: false,
|
||||||
output_types: OutputTypes(BTreeMap::new()),
|
output_types: OutputTypes(BTreeMap::new()),
|
||||||
search_paths: SearchPaths::new(),
|
search_paths: SearchPaths::new(),
|
||||||
maybe_sysroot: None,
|
maybe_sysroot: None,
|
||||||
target_triple: TargetTriple::from_triple(host_triple()),
|
target_triple: TargetTriple::from_triple(host_triple()),
|
||||||
test: false,
|
test: false,
|
||||||
incremental: None,
|
incremental: None,
|
||||||
debugging_opts: basic_debugging_options(),
|
debugging_opts: basic_debugging_options(),
|
||||||
prints: Vec::new(),
|
prints: Vec::new(),
|
||||||
borrowck_mode: BorrowckMode::Ast,
|
borrowck_mode: BorrowckMode::Ast,
|
||||||
cg: basic_codegen_options(),
|
cg: basic_codegen_options(),
|
||||||
error_format: ErrorOutputType::default(),
|
error_format: ErrorOutputType::default(),
|
||||||
externs: Externs(BTreeMap::new()),
|
externs: Externs(BTreeMap::new()),
|
||||||
crate_name: None,
|
crate_name: None,
|
||||||
alt_std_name: None,
|
alt_std_name: None,
|
||||||
libs: Vec::new(),
|
libs: Vec::new(),
|
||||||
unstable_features: UnstableFeatures::Disallow,
|
unstable_features: UnstableFeatures::Disallow,
|
||||||
debug_assertions: true,
|
debug_assertions: true,
|
||||||
actually_rustdoc: false,
|
actually_rustdoc: false,
|
||||||
cli_forced_codegen_units: None,
|
cli_forced_codegen_units: None,
|
||||||
cli_forced_thinlto_off: false,
|
cli_forced_thinlto_off: false,
|
||||||
remap_path_prefix: Vec::new(),
|
remap_path_prefix: Vec::new(),
|
||||||
edition: DEFAULT_EDITION,
|
edition: DEFAULT_EDITION,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2529,6 +2530,7 @@ mod tests {
|
|||||||
use syntax::symbol::Symbol;
|
use syntax::symbol::Symbol;
|
||||||
use syntax::edition::{Edition, DEFAULT_EDITION};
|
use syntax::edition::{Edition, DEFAULT_EDITION};
|
||||||
use syntax;
|
use syntax;
|
||||||
|
use super::Options;
|
||||||
|
|
||||||
fn optgroups() -> getopts::Options {
|
fn optgroups() -> getopts::Options {
|
||||||
let mut opts = getopts::Options::new();
|
let mut opts = getopts::Options::new();
|
||||||
@ -2613,9 +2615,9 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_output_types_tracking_hash_different_paths() {
|
fn test_output_types_tracking_hash_different_paths() {
|
||||||
let mut v1 = super::basic_options();
|
let mut v1 = Options::default();
|
||||||
let mut v2 = super::basic_options();
|
let mut v2 = Options::default();
|
||||||
let mut v3 = super::basic_options();
|
let mut v3 = Options::default();
|
||||||
|
|
||||||
v1.output_types =
|
v1.output_types =
|
||||||
OutputTypes::new(&[(OutputType::Exe, Some(PathBuf::from("./some/thing")))]);
|
OutputTypes::new(&[(OutputType::Exe, Some(PathBuf::from("./some/thing")))]);
|
||||||
@ -2635,8 +2637,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_output_types_tracking_hash_different_construction_order() {
|
fn test_output_types_tracking_hash_different_construction_order() {
|
||||||
let mut v1 = super::basic_options();
|
let mut v1 = Options::default();
|
||||||
let mut v2 = super::basic_options();
|
let mut v2 = Options::default();
|
||||||
|
|
||||||
v1.output_types = OutputTypes::new(&[
|
v1.output_types = OutputTypes::new(&[
|
||||||
(OutputType::Exe, Some(PathBuf::from("./some/thing"))),
|
(OutputType::Exe, Some(PathBuf::from("./some/thing"))),
|
||||||
@ -2656,9 +2658,9 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_externs_tracking_hash_different_construction_order() {
|
fn test_externs_tracking_hash_different_construction_order() {
|
||||||
let mut v1 = super::basic_options();
|
let mut v1 = Options::default();
|
||||||
let mut v2 = super::basic_options();
|
let mut v2 = Options::default();
|
||||||
let mut v3 = super::basic_options();
|
let mut v3 = Options::default();
|
||||||
|
|
||||||
v1.externs = Externs::new(mk_map(vec![
|
v1.externs = Externs::new(mk_map(vec![
|
||||||
(
|
(
|
||||||
@ -2705,9 +2707,9 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_lints_tracking_hash_different_values() {
|
fn test_lints_tracking_hash_different_values() {
|
||||||
let mut v1 = super::basic_options();
|
let mut v1 = Options::default();
|
||||||
let mut v2 = super::basic_options();
|
let mut v2 = Options::default();
|
||||||
let mut v3 = super::basic_options();
|
let mut v3 = Options::default();
|
||||||
|
|
||||||
v1.lint_opts = vec![
|
v1.lint_opts = vec![
|
||||||
(String::from("a"), lint::Allow),
|
(String::from("a"), lint::Allow),
|
||||||
@ -2742,8 +2744,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_lints_tracking_hash_different_construction_order() {
|
fn test_lints_tracking_hash_different_construction_order() {
|
||||||
let mut v1 = super::basic_options();
|
let mut v1 = Options::default();
|
||||||
let mut v2 = super::basic_options();
|
let mut v2 = Options::default();
|
||||||
|
|
||||||
v1.lint_opts = vec![
|
v1.lint_opts = vec![
|
||||||
(String::from("a"), lint::Allow),
|
(String::from("a"), lint::Allow),
|
||||||
@ -2768,10 +2770,10 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_search_paths_tracking_hash_different_order() {
|
fn test_search_paths_tracking_hash_different_order() {
|
||||||
let mut v1 = super::basic_options();
|
let mut v1 = Options::default();
|
||||||
let mut v2 = super::basic_options();
|
let mut v2 = Options::default();
|
||||||
let mut v3 = super::basic_options();
|
let mut v3 = Options::default();
|
||||||
let mut v4 = super::basic_options();
|
let mut v4 = Options::default();
|
||||||
|
|
||||||
// Reference
|
// Reference
|
||||||
v1.search_paths
|
v1.search_paths
|
||||||
@ -2831,10 +2833,10 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_native_libs_tracking_hash_different_values() {
|
fn test_native_libs_tracking_hash_different_values() {
|
||||||
let mut v1 = super::basic_options();
|
let mut v1 = Options::default();
|
||||||
let mut v2 = super::basic_options();
|
let mut v2 = Options::default();
|
||||||
let mut v3 = super::basic_options();
|
let mut v3 = Options::default();
|
||||||
let mut v4 = super::basic_options();
|
let mut v4 = Options::default();
|
||||||
|
|
||||||
// Reference
|
// Reference
|
||||||
v1.libs = vec![
|
v1.libs = vec![
|
||||||
@ -2881,9 +2883,9 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_native_libs_tracking_hash_different_order() {
|
fn test_native_libs_tracking_hash_different_order() {
|
||||||
let mut v1 = super::basic_options();
|
let mut v1 = Options::default();
|
||||||
let mut v2 = super::basic_options();
|
let mut v2 = Options::default();
|
||||||
let mut v3 = super::basic_options();
|
let mut v3 = Options::default();
|
||||||
|
|
||||||
// Reference
|
// Reference
|
||||||
v1.libs = vec![
|
v1.libs = vec![
|
||||||
@ -2916,8 +2918,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_codegen_options_tracking_hash() {
|
fn test_codegen_options_tracking_hash() {
|
||||||
let reference = super::basic_options();
|
let reference = Options::default();
|
||||||
let mut opts = super::basic_options();
|
let mut opts = Options::default();
|
||||||
|
|
||||||
// Make sure the changing an [UNTRACKED] option leaves the hash unchanged
|
// Make sure the changing an [UNTRACKED] option leaves the hash unchanged
|
||||||
opts.cg.ar = Some(String::from("abc"));
|
opts.cg.ar = Some(String::from("abc"));
|
||||||
@ -3054,8 +3056,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_debugging_options_tracking_hash() {
|
fn test_debugging_options_tracking_hash() {
|
||||||
let reference = super::basic_options();
|
let reference = Options::default();
|
||||||
let mut opts = super::basic_options();
|
let mut opts = Options::default();
|
||||||
|
|
||||||
// Make sure the changing an [UNTRACKED] option leaves the hash unchanged
|
// Make sure the changing an [UNTRACKED] option leaves the hash unchanged
|
||||||
opts.debugging_opts.verbose = true;
|
opts.debugging_opts.verbose = true;
|
||||||
@ -3184,7 +3186,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_edition_parsing() {
|
fn test_edition_parsing() {
|
||||||
// test default edition
|
// test default edition
|
||||||
let options = super::basic_options();
|
let options = Options::default();
|
||||||
assert!(options.edition == DEFAULT_EDITION);
|
assert!(options.edition == DEFAULT_EDITION);
|
||||||
|
|
||||||
let matches = optgroups()
|
let matches = optgroups()
|
||||||
|
@ -99,7 +99,7 @@ fn test_env<F>(source_string: &str,
|
|||||||
where F: FnOnce(Env)
|
where F: FnOnce(Env)
|
||||||
{
|
{
|
||||||
syntax::with_globals(|| {
|
syntax::with_globals(|| {
|
||||||
let mut options = config::basic_options();
|
let mut options = config::Options::default();
|
||||||
options.debugging_opts.verbose = true;
|
options.debugging_opts.verbose = true;
|
||||||
options.unstable_features = UnstableFeatures::Allow;
|
options.unstable_features = UnstableFeatures::Allow;
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ use clean;
|
|||||||
use clean::Clean;
|
use clean::Clean;
|
||||||
use html::render::RenderInfo;
|
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 use rustc::session::search_paths::SearchPaths;
|
||||||
|
|
||||||
pub type ExternalPaths = FxHashMap<DefId, (Vec<String>, clean::TypeKind)>;
|
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
|
// rustdoc doesn't override (or allow to override) anything from this that is relevant here, so
|
||||||
// stick to the defaults
|
// stick to the defaults
|
||||||
let sessopts = config::basic_options();
|
let sessopts = Options::default();
|
||||||
let emitter: Box<dyn Emitter + sync::Send> = match error_format {
|
let emitter: Box<dyn Emitter + sync::Send> = match error_format {
|
||||||
ErrorOutputType::HumanReadable(color_config) => Box::new(
|
ErrorOutputType::HumanReadable(color_config) => Box::new(
|
||||||
EmitterWriter::stderr(
|
EmitterWriter::stderr(
|
||||||
@ -243,7 +243,7 @@ pub fn run_core(search_paths: SearchPaths,
|
|||||||
error_format,
|
error_format,
|
||||||
edition,
|
edition,
|
||||||
describe_lints,
|
describe_lints,
|
||||||
..config::basic_options()
|
..Options::default()
|
||||||
};
|
};
|
||||||
driver::spawn_thread_pool(sessopts, move |sessopts| {
|
driver::spawn_thread_pool(sessopts, move |sessopts| {
|
||||||
let codemap = Lrc::new(codemap::CodeMap::new(sessopts.file_path_mapping()));
|
let codemap = Lrc::new(codemap::CodeMap::new(sessopts.file_path_mapping()));
|
||||||
|
@ -83,7 +83,7 @@ pub fn run(input_path: &Path,
|
|||||||
..config::basic_debugging_options()
|
..config::basic_debugging_options()
|
||||||
},
|
},
|
||||||
edition,
|
edition,
|
||||||
..config::basic_options().clone()
|
..config::Options::default()
|
||||||
};
|
};
|
||||||
driver::spawn_thread_pool(sessopts, |sessopts| {
|
driver::spawn_thread_pool(sessopts, |sessopts| {
|
||||||
let codemap = Lrc::new(CodeMap::new(sessopts.file_path_mapping()));
|
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()
|
..config::basic_debugging_options()
|
||||||
},
|
},
|
||||||
edition,
|
edition,
|
||||||
..config::basic_options().clone()
|
..config::Options::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Shuffle around a few input and output handles here. We're going to pass
|
// Shuffle around a few input and output handles here. We're going to pass
|
||||||
|
@ -19,7 +19,7 @@ extern crate rustc_codegen_utils;
|
|||||||
extern crate syntax;
|
extern crate syntax;
|
||||||
|
|
||||||
use rustc::session::{build_session, Session};
|
use rustc::session::{build_session, Session};
|
||||||
use rustc::session::config::{basic_options, Input, Options,
|
use rustc::session::config::{Input, Options,
|
||||||
OutputType, OutputTypes};
|
OutputType, OutputTypes};
|
||||||
use rustc_driver::driver::{self, compile_input, CompileController};
|
use rustc_driver::driver::{self, compile_input, CompileController};
|
||||||
use rustc_metadata::cstore::CStore;
|
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) {
|
fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
|
||||||
syntax::with_globals(|| {
|
syntax::with_globals(|| {
|
||||||
let mut opts = basic_options();
|
let mut opts = Options::default();
|
||||||
opts.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
|
opts.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
|
||||||
opts.maybe_sysroot = Some(sysroot);
|
opts.maybe_sysroot = Some(sysroot);
|
||||||
if let Ok(linker) = std::env::var("RUSTC_LINKER") {
|
if let Ok(linker) = std::env::var("RUSTC_LINKER") {
|
||||||
|
Loading…
Reference in New Issue
Block a user