Skip to content

Commit 2193301

Browse files
committed
tidy up things
1 parent 3d61264 commit 2193301

File tree

20 files changed

+79
-133
lines changed

20 files changed

+79
-133
lines changed

compiler/rustc_ast/src/ast.rs

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

35843584
/// This fn implements some EII, pointed to by the `path`
3585-
pub eii_impl: ThinVec<(NodeId, MetaItem)>,
3585+
pub eii_impl: ThinVec<(NodeId, Path)>,
35863586
}
35873587

35883588
#[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
@@ -846,9 +846,9 @@ fn walk_fn<T: MutVisitor>(vis: &mut T, kind: FnKind<'_>) {
846846
visit_defaultness(vis, defaultness);
847847
vis.visit_ident(ident);
848848

849-
for (node_id, mi) in eii_impl {
849+
for (node_id, path) in eii_impl {
850850
vis.visit_id(node_id);
851-
vis.visit_path(&mut mi.path);
851+
vis.visit_path(path);
852852
}
853853
vis.visit_fn_header(header);
854854
vis.visit_generics(generics);

compiler/rustc_ast/src/visit.rs

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

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

969969
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
@@ -954,8 +954,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
954954
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
955955
self.check_defaultness(item.span, *defaultness);
956956

957-
for (id, mi) in eii_impl {
958-
self.visit_path(&mi.path, *id);
957+
for (id, path) in eii_impl {
958+
self.visit_path(path, *id);
959959
}
960960

961961
let is_intrinsic = item.attrs.iter().any(|a| a.has_name(sym::rustc_intrinsic));

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

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

678678
let body_cb_ib = body.as_ref().map(|body| (body, self.head("")));
679679

680-
for (_, mi) in eii_impl {
680+
for (_, path) in eii_impl {
681681
self.word("#[");
682-
self.print_meta_item(mi);
682+
self.print_path(path, false, 0);
683683
self.word("]");
684684
self.hardbreak();
685685
}

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
Stability {

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 stability;
3332
pub(crate) mod transparency;

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 0 additions & 1 deletion
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::stability::{
2019
BodyStabilityParser, ConstStabilityIndirectParser, ConstStabilityParser, StabilityParser,

0 commit comments

Comments
 (0)