Use a symbol for ExpansionConfig::crate_name.

This avoids some symbol interning and `to_string` conversions.
This commit is contained in:
Nicholas Nethercote 2025-05-30 00:37:27 +10:00
parent 42b02019dc
commit 4a1f445142
7 changed files with 12 additions and 11 deletions

View file

@ -56,7 +56,7 @@ pub fn inject(
is_test_crate: bool,
dcx: DiagCtxtHandle<'_>,
) {
let ecfg = ExpansionConfig::default("proc_macro".to_string(), features);
let ecfg = ExpansionConfig::default(sym::proc_macro, features);
let mut cx = ExtCtxt::new(sess, ecfg, resolver, None);
let mut collect = CollectProcMacros {

View file

@ -36,7 +36,7 @@ pub fn inject(
let span = DUMMY_SP.with_def_site_ctxt(expn_id.to_expn_id());
let call_site = DUMMY_SP.with_call_site_ctxt(expn_id.to_expn_id());
let ecfg = ExpansionConfig::default("std_lib_injection".to_string(), features);
let ecfg = ExpansionConfig::default(sym::std_lib_injection, features);
let cx = ExtCtxt::new(sess, ecfg, resolver, None);
let ident_span = if edition >= Edition2018 { span } else { call_site };

View file

@ -227,7 +227,7 @@ fn generate_test_harness(
panic_strategy: PanicStrategy,
test_runner: Option<ast::Path>,
) {
let econfig = ExpansionConfig::default("test".to_string(), features);
let econfig = ExpansionConfig::default(sym::test, features);
let ext_cx = ExtCtxt::new(sess, econfig, resolver, None);
let expn_id = ext_cx.resolver.expansion_for_ast_pass(

View file

@ -183,12 +183,12 @@ pub(crate) struct FeatureNotAllowed {
#[derive(Diagnostic)]
#[diag(expand_recursion_limit_reached)]
#[help]
pub(crate) struct RecursionLimitReached<'a> {
pub(crate) struct RecursionLimitReached {
#[primary_span]
pub span: Span,
pub descr: String,
pub suggested_limit: Limit,
pub crate_name: &'a str,
pub crate_name: Symbol,
}
#[derive(Diagnostic)]

View file

@ -26,7 +26,7 @@ use rustc_session::lint::builtin::{UNUSED_ATTRIBUTES, UNUSED_DOC_COMMENTS};
use rustc_session::parse::feature_err;
use rustc_session::{Limit, Session};
use rustc_span::hygiene::SyntaxContext;
use rustc_span::{ErrorGuaranteed, FileName, Ident, LocalExpnId, Span, sym};
use rustc_span::{ErrorGuaranteed, FileName, Ident, LocalExpnId, Span, Symbol, sym};
use smallvec::SmallVec;
use crate::base::*;
@ -473,7 +473,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
let dir_path = file_path.parent().unwrap_or(&file_path).to_owned();
self.cx.root_path = dir_path.clone();
self.cx.current_expansion.module = Rc::new(ModuleData {
mod_path: vec![Ident::from_str(&self.cx.ecfg.crate_name)],
mod_path: vec![Ident::with_dummy_span(self.cx.ecfg.crate_name)],
file_path_stack: vec![file_path],
dir_path,
});
@ -689,7 +689,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
span: expn_data.call_site,
descr: expn_data.kind.descr(),
suggested_limit,
crate_name: &self.cx.ecfg.crate_name,
crate_name: self.cx.ecfg.crate_name,
});
self.cx.trace_macros_diag();
@ -2458,7 +2458,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
}
pub struct ExpansionConfig<'feat> {
pub crate_name: String,
pub crate_name: Symbol,
pub features: &'feat Features,
pub recursion_limit: Limit,
pub trace_mac: bool,
@ -2471,7 +2471,7 @@ pub struct ExpansionConfig<'feat> {
}
impl ExpansionConfig<'_> {
pub fn default(crate_name: String, features: &Features) -> ExpansionConfig<'_> {
pub fn default(crate_name: Symbol, features: &Features) -> ExpansionConfig<'_> {
ExpansionConfig {
crate_name,
features,

View file

@ -192,7 +192,7 @@ fn configure_and_expand(
// Create the config for macro expansion
let recursion_limit = get_recursion_limit(pre_configured_attrs, sess);
let cfg = rustc_expand::expand::ExpansionConfig {
crate_name: crate_name.to_string(),
crate_name,
features,
recursion_limit,
trace_mac: sess.opts.unstable_opts.trace_macros,

View file

@ -2052,6 +2052,7 @@ symbols! {
static_recursion,
staticlib,
std,
std_lib_injection,
std_panic,
std_panic_2015_macro,
std_panic_macro,