diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 3b442697b5f..cf887bc665b 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -24,6 +24,7 @@ use rustc_session::{lint, EarlyErrorHandler}; use rustc_span::source_map::{FileLoader, FileName}; use rustc_span::symbol::sym; +use rustc_span::Symbol; use std::path::PathBuf; use std::result; use std::sync::Arc; @@ -64,7 +65,7 @@ pub fn build_output_filenames( } /// Converts strings provided as `--cfg [cfgspec]` into a `Cfg`. -pub(crate) fn parse_cfg(handler: &EarlyErrorHandler, cfgs: Vec) -> Cfg { +pub(crate) fn parse_cfg(handler: &EarlyErrorHandler, cfgs: Vec) -> Cfg { cfgs.into_iter() .map(|s| { let sess = ParseSess::with_silent_emitter(Some(format!( @@ -94,10 +95,7 @@ macro_rules! error { } MetaItemKind::NameValue(..) | MetaItemKind::Word => { let ident = meta_item.ident().expect("multi-segment cfg key"); - return ( - ident.name.to_string(), - meta_item.value_str().map(|sym| sym.to_string()), - ); + return (ident.name, meta_item.value_str()); } } } @@ -118,11 +116,11 @@ macro_rules! error { error!(r#"expected `key` or `key="value"`"#); } }) - .collect::>() + .collect::>() } /// Converts strings provided as `--check-cfg [specs]` into a `CheckCfg`. -pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec) -> CheckCfg { +pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec) -> CheckCfg { // If any --check-cfg is passed then exhaustive_values and exhaustive_names // are enabled by default. let exhaustive_names = !specs.is_empty(); @@ -179,10 +177,7 @@ macro_rules! error { for arg in args { if arg.is_word() && arg.ident().is_some() { let ident = arg.ident().expect("multi-segment cfg key"); - check_cfg - .expecteds - .entry(ident.name.to_string()) - .or_insert(ExpectedValues::Any); + check_cfg.expecteds.entry(ident.name).or_insert(ExpectedValues::Any); } else { error!("`names()` arguments must be simple identifiers"); } @@ -200,7 +195,7 @@ macro_rules! error { let ident = name.ident().expect("multi-segment cfg key"); let expected_values = check_cfg .expecteds - .entry(ident.name.to_string()) + .entry(ident.name) .and_modify(|expected_values| match expected_values { ExpectedValues::Some(_) => {} ExpectedValues::Any => { @@ -217,7 +212,7 @@ macro_rules! error { for val in values { if let Some(LitKind::Str(s, _)) = val.lit().map(|lit| &lit.kind) { - expected_values.insert(Some(s.to_string())); + expected_values.insert(Some(*s)); } else { error!("`values()` arguments must be string literals"); } @@ -271,10 +266,8 @@ macro_rules! error { values_specified = true; for arg in args { - if let Some(LitKind::Str(s, _)) = - arg.lit().map(|lit| &lit.kind) - { - values.insert(Some(s.to_string())); + if let Some(LitKind::Str(s, _)) = arg.lit().map(|lit| &lit.kind) { + values.insert(Some(*s)); } else if arg.has_name(sym::any) && let Some(args) = arg.meta_item_list() { @@ -322,7 +315,7 @@ macro_rules! error { for name in names { check_cfg .expecteds - .entry(name.to_string()) + .entry(name.name) .and_modify(|v| match v { ExpectedValues::Some(v) if !values_any_specified => { v.extend(values.clone()) diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 57ca709267a..466aa21ad8e 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -26,8 +26,8 @@ use rustc_session::{CompilerIO, EarlyErrorHandler}; use rustc_span::edition::{Edition, DEFAULT_EDITION}; use rustc_span::symbol::sym; -use rustc_span::FileName; use rustc_span::SourceFileHashAlgorithm; +use rustc_span::{FileName, Symbol}; use rustc_target::spec::{CodeModel, LinkerFlavorCli, MergeFunctions, PanicStrategy, RelocModel}; use rustc_target::spec::{RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel}; use std::collections::{BTreeMap, BTreeSet}; @@ -38,7 +38,7 @@ fn mk_session( handler: &mut EarlyErrorHandler, matches: getopts::Matches, -) -> (Session, Cfg) { +) -> (Session, Cfg) { let registry = registry::Registry::new(&[]); let sessopts = build_session_options(handler, &matches); let cfg = parse_cfg(handler, matches.opt_strs("cfg")); diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index 4d0be65697a..a974bdd3c0e 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -59,8 +59,8 @@ pub fn add_configuration( pub fn create_session( handler: &EarlyErrorHandler, sopts: config::Options, - cfg: Cfg, - check_cfg: CheckCfg, + cfg: Cfg, + mut check_cfg: CheckCfg, locale_resources: &'static [&'static str], file_loader: Option>, io: CompilerIO, @@ -123,7 +123,6 @@ pub fn create_session( let mut cfg = config::build_configuration(&sess, cfg); add_configuration(&mut cfg, &mut sess, &*codegen_backend); - let mut check_cfg = check_cfg.intern(); check_cfg.fill_well_known(&sess.target); // These configs use symbols, rather than strings. diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 854e2b77993..4a0bdd511a3 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1386,30 +1386,6 @@ fn default() -> Self { } } -impl CheckCfg { - pub fn intern(self) -> CheckCfg { - CheckCfg { - exhaustive_names: self.exhaustive_names, - exhaustive_values: self.exhaustive_values, - expecteds: self - .expecteds - .into_iter() - .map(|(name, values)| { - ( - Symbol::intern(&name), - match values { - ExpectedValues::Some(values) => ExpectedValues::Some( - values.into_iter().map(|b| b.map(|b| Symbol::intern(&b))).collect(), - ), - ExpectedValues::Any => ExpectedValues::Any, - }, - ) - }) - .collect(), - } - } -} - pub enum ExpectedValues { Some(FxHashSet>), Any, @@ -1582,13 +1558,7 @@ pub fn fill_well_known(&mut self, current_target: &Target) { } } -pub fn build_configuration(sess: &Session, user_cfg: Cfg) -> Cfg { - // We can now intern these strings. - let mut user_cfg: Cfg = user_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: Cfg) -> Cfg { // Combine the configuration requested by the session (command line) with // some default and generated configuration items. let default_cfg = default_configuration(sess);