Skip to content

Commit d328f25

Browse files
committed
tidy up things
1 parent bc8c8a8 commit d328f25

File tree

20 files changed

+76
-132
lines changed

20 files changed

+76
-132
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3502,7 +3502,7 @@ pub struct Fn {
35023502
pub body: Option<P<Block>>,
35033503

35043504
/// This fn implements some EII, pointed to by the `path`
3505-
pub eii_impl: ThinVec<(NodeId, MetaItem)>,
3505+
pub eii_impl: ThinVec<(NodeId, Path)>,
35063506
}
35073507

35083508
#[derive(Clone, Encodable, Decodable, Debug)]

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,9 +981,9 @@ fn walk_fn<T: MutVisitor>(vis: &mut T, kind: FnKind<'_>) {
981981
// Identifier and visibility are visited as a part of the item.
982982
visit_defaultness(vis, defaultness);
983983

984-
for (node_id, mi) in eii_impl {
984+
for (node_id, path) in eii_impl {
985985
vis.visit_id(node_id);
986-
vis.visit_path(&mut mi.path);
986+
vis.visit_path(path);
987987
}
988988
vis.visit_fn_header(header);
989989
vis.visit_generics(generics);

compiler/rustc_ast/src/visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,8 +935,8 @@ pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Resu
935935
) => {
936936
// Identifier and visibility are visited as a part of the item.
937937

938-
for (node_id, mi) in eii_impl {
939-
try_visit!(visitor.visit_path(&mi.path, *node_id));
938+
for (node_id, path) in eii_impl {
939+
try_visit!(visitor.visit_path(path, *node_id));
940940
}
941941

942942
try_visit!(visitor.visit_fn_header(header));

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -149,21 +149,57 @@ impl<'hir> LoweringContext<'_, 'hir> {
149149
}
150150
}
151151

152+
fn generate_extra_attrs_for_item_kind(
153+
&mut self,
154+
id: NodeId,
155+
i: &ItemKind,
156+
) -> Vec<hir::Attribute> {
157+
match i {
158+
ItemKind::Fn(box Fn { eii_impl, .. }) => {
159+
let mut res = Vec::new();
160+
161+
for (id, path) in eii_impl {
162+
let did = self.lower_path_simple_eii(*id, path);
163+
res.push(hir::Attribute::Parsed(AttributeKind::EiiImpl { eii_macro: did }));
164+
}
165+
166+
res
167+
}
168+
ItemKind::MacroDef(MacroDef { eii_macro_for: Some(path), .. }) => {
169+
vec![hir::Attribute::Parsed(AttributeKind::EiiMacroFor {
170+
eii_extern_item: self.lower_path_simple_eii(id, path),
171+
})]
172+
}
173+
ItemKind::ExternCrate(..)
174+
| ItemKind::Use(..)
175+
| ItemKind::Static(..)
176+
| ItemKind::Const(..)
177+
| ItemKind::Mod(..)
178+
| ItemKind::ForeignMod(..)
179+
| ItemKind::GlobalAsm(..)
180+
| ItemKind::TyAlias(..)
181+
| ItemKind::Enum(..)
182+
| ItemKind::Struct(..)
183+
| ItemKind::Union(..)
184+
| ItemKind::Trait(..)
185+
| ItemKind::TraitAlias(..)
186+
| ItemKind::Impl(..)
187+
| ItemKind::MacCall(..)
188+
| ItemKind::MacroDef(..)
189+
| ItemKind::Delegation(..)
190+
| ItemKind::DelegationMac(..) => Vec::new(),
191+
}
192+
}
193+
152194
fn lower_item(&mut self, i: &Item) -> &'hir hir::Item<'hir> {
153195
let vis_span = self.lower_span(i.vis.span);
154196
let hir_id = hir::HirId::make_owner(self.current_hir_id_owner.def_id);
155197

156-
let mut extra_hir_attributes = Vec::new();
157-
if let ItemKind::Fn(f) = &i.kind {
158-
extra_hir_attributes.extend(f.eii_impl.iter().map(|(id, mi)| {
159-
let did = self.lower_path_simple_eii(*id, &mi.path);
160-
161-
hir::Attribute::Parsed(AttributeKind::EiiImpl { eii_macro: did })
162-
}));
163-
}
198+
let extra_hir_attributes = self.generate_extra_attrs_for_item_kind(i.id, &i.kind);
164199

165200
let attrs = self.lower_attrs(hir_id, &i.attrs, i.span, &extra_hir_attributes);
166201
let kind = self.lower_item_kind(i.span, i.id, hir_id, i.ident, attrs, vis_span, &i.kind);
202+
167203
let item = hir::Item {
168204
owner_id: hir_id.expect_owner(),
169205
kind,
@@ -230,7 +266,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
230266
body,
231267
contract,
232268
define_opaque,
233-
eii_impl,
234269
..
235270
}) => {
236271
debug_assert_ne!(ident.name, kw::Empty);
@@ -485,7 +520,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
485520
);
486521
hir::ItemKind::TraitAlias(ident, generics, bounds)
487522
}
488-
ItemKind::MacroDef(MacroDef { body, macro_rules, eii_macro_for }) => {
523+
ItemKind::MacroDef(MacroDef { body, macro_rules, eii_macro_for: _ }) => {
489524
debug_assert_ne!(ident.name, kw::Empty);
490525
let ident = self.lower_ident(ident);
491526
let body = P(self.lower_delim_args(body));
@@ -504,14 +539,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
504539
eii_macro_for: None,
505540
});
506541

507-
hir::ItemKind::Macro {
508-
name: ident,
509-
ast_macro_def,
510-
kind: macro_kind,
511-
eii_macro_for: eii_macro_for
512-
.as_ref()
513-
.map(|path| self.lower_path_simple_eii(id, path)),
514-
}
542+
hir::ItemKind::Macro(ident, ast_macro_def, macro_kind)
515543
}
516544
ItemKind::Delegation(box delegation) => {
517545
debug_assert_ne!(ident.name, kw::Empty);

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -930,8 +930,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
930930
) => {
931931
self.check_defaultness(item.span, *defaultness);
932932

933-
for (id, mi) in eii_impl {
934-
self.visit_path(&mi.path, *id);
933+
for (id, path) in eii_impl {
934+
self.visit_path(path, *id);
935935
}
936936

937937
let is_intrinsic =

compiler/rustc_ast_pretty/src/pprust/state/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,9 +682,9 @@ impl<'a> State<'a> {
682682

683683
self.print_define_opaques(define_opaque.as_deref());
684684

685-
for (_, mi) in eii_impl {
685+
for (_, path) in eii_impl {
686686
self.word("#[");
687-
self.print_meta_item(mi);
687+
self.print_path(path, false, 0);
688688
self.word("]");
689689
self.hardbreak();
690690
}

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ pub enum AttributeKind {
194194
EiiImpl {
195195
eii_macro: DefId,
196196
},
197+
EiiMacroFor {
198+
eii_extern_item: DefId,
199+
},
197200
MacroTransparency(Transparency),
198201
Repr(ThinVec<(ReprAttr, Span)>),
199202
RustcMacroEdition2021,

compiler/rustc_attr_parsing/src/attributes/eii.rs

Lines changed: 0 additions & 62 deletions
This file was deleted.

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pub(crate) mod allow_unstable;
2727
pub(crate) mod cfg;
2828
pub(crate) mod confusables;
2929
pub(crate) mod deprecation;
30-
pub(crate) mod eii;
3130
pub(crate) mod repr;
3231
pub(crate) mod rustc;
3332
pub(crate) mod stability;

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};
1414
use crate::attributes::allow_unstable::{AllowConstFnUnstableParser, AllowInternalUnstableParser};
1515
use crate::attributes::confusables::ConfusablesParser;
1616
use crate::attributes::deprecation::DeprecationParser;
17-
use crate::attributes::eii::EiiParser;
1817
use crate::attributes::repr::ReprParser;
1918
use crate::attributes::rustc::RustcMacroEdition2021Parser;
2019
use crate::attributes::stability::{
@@ -78,7 +77,6 @@ attribute_groups!(
7877
// tidy-alphabetical-start
7978
Single<ConstStabilityIndirectParser>,
8079
Single<DeprecationParser>,
81-
Single<EiiParser>,
8280
Single<RustcMacroEdition2021Parser>,
8381
Single<TransparencyParser>,
8482
// tidy-alphabetical-end

0 commit comments

Comments
 (0)