Skip to content

Commit de897f5

Browse files
committed
rustc_expand: Remove redundant field from proc macro expander structures
This information is already available from `ExpnData`
1 parent 28f4dba commit de897f5

File tree

5 files changed

+18
-33
lines changed

5 files changed

+18
-33
lines changed

compiler/rustc_builtin_macros/src/lib.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use crate::deriving::*;
1919

2020
use rustc_expand::base::{MacroExpanderFn, ResolverExpand, SyntaxExtensionKind};
2121
use rustc_expand::proc_macro::BangProcMacro;
22-
use rustc_span::def_id::LOCAL_CRATE;
2322
use rustc_span::symbol::sym;
2423

2524
mod asm;
@@ -113,8 +112,5 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
113112
}
114113

115114
let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);
116-
register(
117-
sym::quote,
118-
SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client, krate: LOCAL_CRATE })),
119-
);
115+
register(sym::quote, SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client })));
120116
}

compiler/rustc_expand/src/proc_macro.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ use rustc_data_structures::sync::Lrc;
99
use rustc_errors::ErrorReported;
1010
use rustc_parse::nt_to_tokenstream;
1111
use rustc_parse::parser::ForceCollect;
12-
use rustc_span::def_id::CrateNum;
1312
use rustc_span::{Span, DUMMY_SP};
1413

1514
const EXEC_STRATEGY: pm::bridge::server::SameThread = pm::bridge::server::SameThread;
1615

1716
pub struct BangProcMacro {
1817
pub client: pm::bridge::client::Client<fn(pm::TokenStream) -> pm::TokenStream>,
19-
pub krate: CrateNum,
2018
}
2119

2220
impl base::ProcMacro for BangProcMacro {
@@ -26,7 +24,7 @@ impl base::ProcMacro for BangProcMacro {
2624
span: Span,
2725
input: TokenStream,
2826
) -> Result<TokenStream, ErrorReported> {
29-
let server = proc_macro_server::Rustc::new(ecx, self.krate);
27+
let server = proc_macro_server::Rustc::new(ecx);
3028
self.client.run(&EXEC_STRATEGY, server, input, ecx.ecfg.proc_macro_backtrace).map_err(|e| {
3129
let mut err = ecx.struct_span_err(span, "proc macro panicked");
3230
if let Some(s) = e.as_str() {
@@ -40,7 +38,6 @@ impl base::ProcMacro for BangProcMacro {
4038

4139
pub struct AttrProcMacro {
4240
pub client: pm::bridge::client::Client<fn(pm::TokenStream, pm::TokenStream) -> pm::TokenStream>,
43-
pub krate: CrateNum,
4441
}
4542

4643
impl base::AttrProcMacro for AttrProcMacro {
@@ -51,7 +48,7 @@ impl base::AttrProcMacro for AttrProcMacro {
5148
annotation: TokenStream,
5249
annotated: TokenStream,
5350
) -> Result<TokenStream, ErrorReported> {
54-
let server = proc_macro_server::Rustc::new(ecx, self.krate);
51+
let server = proc_macro_server::Rustc::new(ecx);
5552
self.client
5653
.run(&EXEC_STRATEGY, server, annotation, annotated, ecx.ecfg.proc_macro_backtrace)
5754
.map_err(|e| {
@@ -67,7 +64,6 @@ impl base::AttrProcMacro for AttrProcMacro {
6764

6865
pub struct ProcMacroDerive {
6966
pub client: pm::bridge::client::Client<fn(pm::TokenStream) -> pm::TokenStream>,
70-
pub krate: CrateNum,
7167
}
7268

7369
impl MultiItemModifier for ProcMacroDerive {
@@ -101,7 +97,7 @@ impl MultiItemModifier for ProcMacroDerive {
10197
nt_to_tokenstream(&item, &ecx.sess.parse_sess, CanSynthesizeMissingTokens::No)
10298
};
10399

104-
let server = proc_macro_server::Rustc::new(ecx, self.krate);
100+
let server = proc_macro_server::Rustc::new(ecx);
105101
let stream =
106102
match self.client.run(&EXEC_STRATEGY, server, input, ecx.ecfg.proc_macro_backtrace) {
107103
Ok(stream) => stream,

compiler/rustc_expand/src/proc_macro_server.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ pub(crate) struct Rustc<'a> {
368368
}
369369

370370
impl<'a> Rustc<'a> {
371-
pub fn new(cx: &'a ExtCtxt<'_>, krate: CrateNum) -> Self {
371+
pub fn new(cx: &'a ExtCtxt<'_>) -> Self {
372372
let expn_data = cx.current_expansion.id.expn_data();
373373
let def_site = cx.with_def_site_ctxt(expn_data.def_site);
374374
let call_site = cx.with_call_site_ctxt(expn_data.call_site);
@@ -381,7 +381,7 @@ impl<'a> Rustc<'a> {
381381
call_site,
382382
mixed_site,
383383
span_debug: cx.ecfg.span_debug,
384-
krate,
384+
krate: expn_data.macro_def_id.unwrap().krate,
385385
expn_id: cx.current_expansion.id,
386386
rebased_spans: FxHashMap::default(),
387387
}

compiler/rustc_metadata/src/rmeta/decoder.rs

+11-18
Original file line numberDiff line numberDiff line change
@@ -725,37 +725,30 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
725725
.decode((self, sess))
726726
}
727727

728-
fn load_proc_macro(&self, def_id: DefId, sess: &Session) -> SyntaxExtension {
729-
let (name, kind, helper_attrs) = match *self.raw_proc_macro(def_id.index) {
728+
fn load_proc_macro(&self, id: DefIndex, sess: &Session) -> SyntaxExtension {
729+
let (name, kind, helper_attrs) = match *self.raw_proc_macro(id) {
730730
ProcMacro::CustomDerive { trait_name, attributes, client } => {
731731
let helper_attrs =
732732
attributes.iter().cloned().map(Symbol::intern).collect::<Vec<_>>();
733733
(
734734
trait_name,
735-
SyntaxExtensionKind::Derive(Box::new(ProcMacroDerive {
736-
client,
737-
krate: def_id.krate,
738-
})),
735+
SyntaxExtensionKind::Derive(Box::new(ProcMacroDerive { client })),
739736
helper_attrs,
740737
)
741738
}
742-
ProcMacro::Attr { name, client } => (
743-
name,
744-
SyntaxExtensionKind::Attr(Box::new(AttrProcMacro { client, krate: def_id.krate })),
745-
Vec::new(),
746-
),
747-
ProcMacro::Bang { name, client } => (
748-
name,
749-
SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client, krate: def_id.krate })),
750-
Vec::new(),
751-
),
739+
ProcMacro::Attr { name, client } => {
740+
(name, SyntaxExtensionKind::Attr(Box::new(AttrProcMacro { client })), Vec::new())
741+
}
742+
ProcMacro::Bang { name, client } => {
743+
(name, SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client })), Vec::new())
744+
}
752745
};
753746

754-
let attrs: Vec<_> = self.get_item_attrs(def_id.index, sess).collect();
747+
let attrs: Vec<_> = self.get_item_attrs(id, sess).collect();
755748
SyntaxExtension::new(
756749
sess,
757750
kind,
758-
self.get_span(def_id.index, sess),
751+
self.get_span(id, sess),
759752
helper_attrs,
760753
self.root.edition,
761754
Symbol::intern(name),

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ impl CStore {
411411

412412
let data = self.get_crate_data(id.krate);
413413
if data.root.is_proc_macro_crate() {
414-
return LoadedMacro::ProcMacro(data.load_proc_macro(id, sess));
414+
return LoadedMacro::ProcMacro(data.load_proc_macro(id.index, sess));
415415
}
416416

417417
let span = data.get_span(id.index, sess);

0 commit comments

Comments
 (0)