Skip to content

Commit fef71af

Browse files
Eliminate hir::MacroDef
1 parent 43802ec commit fef71af

File tree

11 files changed

+17
-84
lines changed

11 files changed

+17
-84
lines changed

compiler/rustc_ast_lowering/src/item.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
445445
ItemKind::MacroDef(MacroDef { ref body, macro_rules }) => {
446446
let body = P(self.lower_mac_args(body));
447447

448-
hir::ItemKind::Macro(hir::MacroDef {
449-
ident: *ident,
450-
vis: *vis,
451-
def_id: hir_id.expect_owner(),
452-
span,
453-
ast: MacroDef { body, macro_rules },
454-
})
448+
hir::ItemKind::Macro(ast::MacroDef { body, macro_rules })
455449
}
456450
ItemKind::MacCall(..) => {
457451
panic!("`TyMac` should have been expanded by now")

compiler/rustc_hir/src/arena.rs

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ macro_rules! arena_types {
3535
[few] inline_asm: rustc_hir::InlineAsm<$tcx>,
3636
[few] llvm_inline_asm: rustc_hir::LlvmInlineAsm<$tcx>,
3737
[] local: rustc_hir::Local<$tcx>,
38-
[few] macro_def: rustc_hir::MacroDef<$tcx>,
3938
[few] mod_: rustc_hir::Mod<$tcx>,
4039
[] param: rustc_hir::Param<$tcx>,
4140
[] pat: rustc_hir::Pat<$tcx>,

compiler/rustc_hir/src/hir.rs

+1-20
Original file line numberDiff line numberDiff line change
@@ -767,25 +767,6 @@ impl Crate<'_> {
767767
}
768768
}
769769

770-
/// A macro definition, in this crate or imported from another.
771-
///
772-
/// Not parsed directly, but created on macro import or `macro_rules!` expansion.
773-
#[derive(Debug)]
774-
pub struct MacroDef<'hir> {
775-
pub ident: Ident,
776-
pub vis: Visibility<'hir>,
777-
pub def_id: LocalDefId,
778-
pub span: Span,
779-
pub ast: ast::MacroDef,
780-
}
781-
782-
impl MacroDef<'_> {
783-
#[inline]
784-
pub fn hir_id(&self) -> HirId {
785-
HirId::make_owner(self.def_id)
786-
}
787-
}
788-
789770
/// A block of statements `{ .. }`, which may have a label (in this case the
790771
/// `targeted_by_break` field will be `true`) and may be `unsafe` by means of
791772
/// the `rules` being anything but `DefaultBlock`.
@@ -2780,7 +2761,7 @@ pub enum ItemKind<'hir> {
27802761
/// An external module, e.g. `extern { .. }`.
27812762
ForeignMod { abi: Abi, items: &'hir [ForeignItemRef<'hir>] },
27822763
/// A MBE macro (`macro_rules!` or `macro`).
2783-
Macro(MacroDef<'hir>),
2764+
Macro(ast::MacroDef),
27842765
/// Module-level inline assembly (from `global_asm!`).
27852766
GlobalAsm(&'hir InlineAsm<'hir>),
27862767
/// A type alias, e.g., `type Foo = Bar<u8>`.

compiler/rustc_hir/src/intravisit.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,6 @@ pub trait Visitor<'v>: Sized {
466466
walk_assoc_type_binding(self, type_binding)
467467
}
468468
fn visit_attribute(&mut self, _id: HirId, _attr: &'v Attribute) {}
469-
fn visit_macro_def(&mut self, macro_def: &'v MacroDef<'v>) {
470-
walk_macro_def(self, macro_def)
471-
}
472469
fn visit_vis(&mut self, vis: &'v Visibility<'v>) {
473470
walk_vis(self, vis)
474471
}
@@ -491,11 +488,6 @@ pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate<'v>) {
491488
}
492489
}
493490

494-
pub fn walk_macro_def<'v, V: Visitor<'v>>(visitor: &mut V, macro_def: &'v MacroDef<'v>) {
495-
visitor.visit_id(macro_def.hir_id());
496-
visitor.visit_ident(macro_def.ident);
497-
}
498-
499491
pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod<'v>, mod_hir_id: HirId) {
500492
visitor.visit_id(mod_hir_id);
501493
for &item_id in module.item_ids {
@@ -593,9 +585,8 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
593585
visitor.visit_id(item.hir_id());
594586
walk_list!(visitor, visit_foreign_item_ref, items);
595587
}
596-
ItemKind::Macro(ref macro_def) => {
588+
ItemKind::Macro(_) => {
597589
visitor.visit_id(item.hir_id());
598-
visitor.visit_macro_def(macro_def)
599590
}
600591
ItemKind::GlobalAsm(asm) => {
601592
visitor.visit_id(item.hir_id());

compiler/rustc_hir/src/stable_hash_impls.rs

+2-15
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
22

33
use crate::hir::{
4-
BodyId, Expr, ForeignItem, ForeignItemId, ImplItem, ImplItemId, Item, ItemId, MacroDef, Mod,
5-
TraitItem, TraitItemId, Ty, VisibilityKind,
4+
BodyId, Expr, ForeignItem, ForeignItemId, ImplItem, ImplItemId, Item, ItemId, Mod, TraitItem,
5+
TraitItemId, Ty, VisibilityKind,
66
};
77
use crate::hir_id::{HirId, ItemLocalId};
88
use rustc_span::def_id::DefPathHash;
@@ -190,16 +190,3 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Item<'_> {
190190
});
191191
}
192192
}
193-
194-
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for MacroDef<'_> {
195-
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
196-
let MacroDef { ident, def_id: _, ref ast, ref vis, span } = *self;
197-
198-
hcx.hash_hir_item_like(|hcx| {
199-
ident.name.hash_stable(hcx, hasher);
200-
ast.hash_stable(hcx, hasher);
201-
vis.hash_stable(hcx, hasher);
202-
span.hash_stable(hcx, hasher);
203-
});
204-
}
205-
}

compiler/rustc_hir_pretty/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ impl<'a> State<'a> {
661661
self.bclose(item.span);
662662
}
663663
hir::ItemKind::Macro(ref macro_def) => {
664-
let (kw, has_bang) = if macro_def.ast.macro_rules {
664+
let (kw, has_bang) = if macro_def.macro_rules {
665665
("macro_rules", true)
666666
} else {
667667
self.print_visibility(&item.vis);
@@ -672,13 +672,13 @@ impl<'a> State<'a> {
672672
Some(MacHeader::Keyword(kw)),
673673
has_bang,
674674
Some(item.ident),
675-
macro_def.ast.body.delim(),
676-
&macro_def.ast.body.inner_tokens(),
675+
macro_def.body.delim(),
676+
&macro_def.body.inner_tokens(),
677677
true,
678678
item.span,
679679
);
680680

681-
if macro_def.ast.body.need_semicolon() {
681+
if macro_def.body.need_semicolon() {
682682
self.word(";");
683683
}
684684
}

compiler/rustc_metadata/src/rmeta/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ impl EncodeContext<'a, 'tcx> {
13751375
}
13761376
hir::ItemKind::ForeignMod { .. } => EntryKind::ForeignMod,
13771377
hir::ItemKind::Macro(ref macro_def) => {
1378-
EntryKind::MacroDef(self.lazy(macro_def.ast.clone()))
1378+
EntryKind::MacroDef(self.lazy(macro_def.clone()))
13791379
}
13801380
hir::ItemKind::GlobalAsm(..) => EntryKind::GlobalAsm,
13811381
hir::ItemKind::TyAlias(..) => EntryKind::Type,

compiler/rustc_passes/src/check_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1514,7 +1514,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
15141514
// In the long run, the checks should be harmonized.
15151515
if let ItemKind::Macro(ref macro_def) = item.kind {
15161516
let def_id = item.def_id.to_def_id();
1517-
if macro_def.ast.macro_rules && !self.tcx.has_attr(def_id, sym::macro_export) {
1517+
if macro_def.macro_rules && !self.tcx.has_attr(def_id, sym::macro_export) {
15181518
check_non_exported_macro_for_invalid_attrs(self.tcx, item);
15191519
}
15201520
}

compiler/rustc_passes/src/hir_stats.rs

-5
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,6 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
244244
fn visit_attribute(&mut self, _: hir::HirId, attr: &'v ast::Attribute) {
245245
self.record("Attribute", Id::Attr(attr.id), attr);
246246
}
247-
248-
fn visit_macro_def(&mut self, macro_def: &'v hir::MacroDef<'v>) {
249-
self.record("MacroDef", Id::Node(macro_def.hir_id()), macro_def);
250-
hir_visit::walk_macro_def(self, macro_def)
251-
}
252247
}
253248

254249
impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {

compiler/rustc_passes/src/stability.rs

-13
Original file line numberDiff line numberDiff line change
@@ -539,19 +539,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
539539
);
540540
}
541541

542-
fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) {
543-
self.annotate(
544-
md.def_id,
545-
md.span,
546-
None,
547-
AnnotationKind::Required,
548-
InheritDeprecation::Yes,
549-
InheritConstStability::No,
550-
InheritStability::No,
551-
|_| {},
552-
);
553-
}
554-
555542
fn visit_generic_param(&mut self, p: &'tcx hir::GenericParam<'tcx>) {
556543
let kind = match &p.kind {
557544
// Allow stability attributes on default generic arguments.

compiler/rustc_privacy/src/lib.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
642642
hir::ItemKind::Macro(ref macro_def) => {
643643
let def_id = item.def_id.to_def_id();
644644
let is_macro_export = self.tcx.has_attr(def_id, sym::macro_export);
645-
match (macro_def.ast.macro_rules, is_macro_export) {
645+
match (macro_def.macro_rules, is_macro_export) {
646646
(true, true) => Some(AccessLevel::Public),
647647
(true, false) => None,
648648
(false, _) => {
@@ -728,23 +728,22 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
728728
// are reachable, since they might be exported transitively.
729729

730730
// Non-opaque macros cannot make other items more accessible than they already are.
731-
let attrs = self.tcx.hir().attrs(md.hir_id());
732-
if attr::find_transparency(&self.tcx.sess, &attrs, md.ast.macro_rules).0
731+
let attrs = self.tcx.hir().attrs(item.hir_id());
732+
if attr::find_transparency(&self.tcx.sess, &attrs, md.macro_rules).0
733733
!= Transparency::Opaque
734734
{
735735
return;
736736
}
737737

738+
let item_def_id = item.def_id.to_def_id();
738739
let macro_module_def_id =
739-
ty::DefIdTree::parent(self.tcx, md.def_id.to_def_id()).unwrap().expect_local();
740+
ty::DefIdTree::parent(self.tcx, item_def_id).unwrap().expect_local();
740741
if self.tcx.hir().opt_def_kind(macro_module_def_id) != Some(DefKind::Mod) {
741742
// The macro's parent doesn't correspond to a `mod`, return early (#63164, #65252).
742743
return;
743744
}
744745

745-
let level = if md.vis.node.is_pub() { self.get(macro_module_def_id) } else { None };
746-
let new_level = self.update(md.def_id, level);
747-
if new_level.is_none() {
746+
if self.get(item.def_id).is_none() {
748747
return;
749748
}
750749

0 commit comments

Comments
 (0)