Skip to content

Commit da12aaa

Browse files
committed
tidy up things
1 parent 514826b commit da12aaa

File tree

20 files changed

+79
-134
lines changed

20 files changed

+79
-134
lines changed

compiler/rustc_ast/src/ast.rs

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

35913591
/// This fn implements some EII, pointed to by the `path`
3592-
pub eii_impl: ThinVec<(NodeId, MetaItem)>,
3592+
pub eii_impl: ThinVec<(NodeId, Path)>,
35933593
}
35943594

35953595
#[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
@@ -946,9 +946,9 @@ fn walk_fn<T: MutVisitor>(vis: &mut T, kind: FnKind<'_>) {
946946
visit_defaultness(vis, defaultness);
947947
vis.visit_ident(ident);
948948

949-
for (node_id, mi) in eii_impl {
949+
for (node_id, path) in eii_impl {
950950
vis.visit_id(node_id);
951-
vis.visit_path(&mut mi.path);
951+
vis.visit_path(path);
952952
}
953953
vis.visit_fn_header(header);
954954
vis.visit_generics(generics);

compiler/rustc_ast/src/visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -961,8 +961,8 @@ pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Resu
961961
try_visit!(visitor.visit_ident(ident));
962962

963963
// Identifier and visibility are visited as a part of the item.
964-
for (node_id, mi) in eii_impl {
965-
try_visit!(visitor.visit_path(&mi.path, *node_id));
964+
for (node_id, path) in eii_impl {
965+
try_visit!(visitor.visit_path(path, *node_id));
966966
}
967967

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

compiler/rustc_ast_lowering/src/item.rs

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

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

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

164199
let attrs = self.lower_attrs(hir_id, &i.attrs, i.span, &extra_hir_attributes);
165200
let kind = self.lower_item_kind(i.span, i.id, hir_id, attrs, vis_span, &i.kind);
201+
166202
let item = hir::Item {
167203
owner_id: hir_id.expect_owner(),
168204
kind,
@@ -233,7 +269,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
233269
body,
234270
contract,
235271
define_opaque,
236-
eii_impl,
237272
..
238273
}) => {
239274
self.with_new_scopes(*fn_sig_span, |this| {
@@ -475,7 +510,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
475510
);
476511
hir::ItemKind::TraitAlias(ident, generics, bounds)
477512
}
478-
ItemKind::MacroDef(ident, MacroDef { body, macro_rules, eii_macro_for }) => {
513+
ItemKind::MacroDef(ident, MacroDef { body, macro_rules, eii_macro_for: _ }) => {
479514
let ident = self.lower_ident(*ident);
480515
let body = P(self.lower_delim_args(body));
481516
let def_id = self.local_def_id(id);
@@ -493,14 +528,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
493528
eii_macro_for: None,
494529
});
495530

496-
hir::ItemKind::Macro {
497-
name: ident,
498-
ast_macro_def,
499-
kind: macro_kind,
500-
eii_macro_for: eii_macro_for
501-
.as_ref()
502-
.map(|path| self.lower_path_simple_eii(id, path)),
503-
}
531+
hir::ItemKind::Macro(ident, ast_macro_def, macro_kind)
504532
}
505533
ItemKind::Delegation(box delegation) => {
506534
let delegation_results = self.lower_delegation(delegation, id, false);
@@ -680,6 +708,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
680708
self.lower_generics(generics, i.id, itctx, |this| {
681709
(
682710
// Disallow `impl Trait` in foreign items.
711+
this.lower_fn_decl(fdec, i.id, sig.span, FnDeclKind::ExternFn, None),
683712
this.lower_fn_params_to_idents(fdec),
684713
)
685714
});

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,8 +948,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
948948
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
949949
self.check_defaultness(item.span, *defaultness);
950950

951-
for (id, mi) in eii_impl {
952-
self.visit_path(&mi.path, *id);
951+
for (id, path) in eii_impl {
952+
self.visit_path(path, *id);
953953
}
954954

955955
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
let ast::Fn { defaultness, ident, generics, sig, contract, body, define_opaque, eii_impl } = func;
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)