Skip to content

Commit 95bfa31

Browse files
committed
tidy up things
1 parent 75286cb commit 95bfa31

File tree

19 files changed

+78
-113
lines changed

19 files changed

+78
-113
lines changed

compiler/rustc_ast/src/ast.rs

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

34743474
/// This fn implements some EII, pointed to by the `path`
3475-
pub eii_impl: ThinVec<(NodeId, MetaItem)>,
3475+
pub eii_impl: ThinVec<(NodeId, Path)>,
34763476
}
34773477

34783478
#[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
@@ -977,9 +977,9 @@ fn walk_fn<T: MutVisitor>(vis: &mut T, kind: FnKind<'_>) {
977977
// Identifier and visibility are visited as a part of the item.
978978
visit_defaultness(vis, defaultness);
979979

980-
for (node_id, mi) in eii_impl {
980+
for (node_id, path) in eii_impl {
981981
vis.visit_id(node_id);
982-
vis.visit_path(&mut mi.path);
982+
vis.visit_path(path);
983983
}
984984
vis.visit_fn_header(header);
985985
vis.visit_generics(generics);

compiler/rustc_ast/src/visit.rs

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

911-
for (node_id, mi) in eii_impl {
912-
try_visit!(visitor.visit_path(&mi.path, *node_id));
911+
for (node_id, path) in eii_impl {
912+
try_visit!(visitor.visit_path(path, *node_id));
913913
}
914914

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

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,55 @@ impl<'hir> LoweringContext<'_, 'hir> {
155155
}
156156
}
157157

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

163-
let mut extra_hir_attributes = Vec::new();
164-
if let ItemKind::Fn(f) = &i.kind {
165-
extra_hir_attributes.extend(f.eii_impl.iter().map(|(id, mi)| {
166-
let did = self.lower_path_simple_eii(*id, &mi.path);
167-
168-
hir::Attribute::Parsed(AttributeKind::EiiImpl { eii_macro: did })
169-
}));
170-
}
171-
172-
let attrs = self.lower_attrs(hir_id, &i.attrs, i.span, &extra_hir_attributes);
205+
let extra_attributes = self.generate_extra_attrs_for_item_kind(i.id, &i.kind);
206+
let attrs = self.lower_attrs(hir_id, &i.attrs, i.span, &extra_attributes);
173207
let kind = self.lower_item_kind(i.span, i.id, hir_id, &mut ident, attrs, vis_span, &i.kind);
174208
let item = hir::Item {
175209
owner_id: hir_id.expect_owner(),
@@ -221,7 +255,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
221255
body,
222256
contract,
223257
define_opaque,
224-
eii_impl,
225258
..
226259
}) => {
227260
self.with_new_scopes(*fn_sig_span, |this| {
@@ -446,7 +479,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
446479
);
447480
hir::ItemKind::TraitAlias(generics, bounds)
448481
}
449-
ItemKind::MacroDef(MacroDef { body, macro_rules, eii_macro_for }) => {
482+
ItemKind::MacroDef(MacroDef { body, macro_rules, eii_macro_for: _ }) => {
450483
let body = P(self.lower_delim_args(body));
451484
let def_id = self.local_def_id(id);
452485
let def_kind = self.tcx.def_kind(def_id);
@@ -456,19 +489,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
456489
def_kind.descr(def_id.to_def_id())
457490
);
458491
};
459-
let ast_macro_def = self.arena.alloc(ast::MacroDef {
492+
493+
let macro_def = self.arena.alloc(ast::MacroDef {
460494
body,
461495
macro_rules: *macro_rules,
462496
eii_macro_for: None,
463497
});
464-
465-
hir::ItemKind::Macro {
466-
ast_macro_def,
467-
kind: macro_kind,
468-
eii_macro_for: eii_macro_for
469-
.as_ref()
470-
.map(|path| self.lower_path_simple_eii(id, path)),
471-
}
498+
hir::ItemKind::Macro(macro_def, macro_kind)
472499
}
473500
ItemKind::Delegation(box delegation) => {
474501
let delegation_results = self.lower_delegation(delegation, id);

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
@@ -660,9 +660,9 @@ impl<'a> State<'a> {
660660
}
661661
}
662662

663-
for (_, mi) in eii_impl {
663+
for (_, path) in eii_impl {
664664
self.word("#[");
665-
self.print_meta_item(mi);
665+
self.print_path(path, false, 0);
666666
self.word("]");
667667
self.hardbreak();
668668
}

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 {
Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
use rustc_ast::LitKind;
21
use rustc_attr_data_structures::AttributeKind;
32
use rustc_feature::{AttributeTemplate, template};
4-
use rustc_middle::bug;
53
use rustc_span::sym;
64

75
use super::{AcceptContext, AttributeOrder, OnDuplicate};
@@ -21,42 +19,3 @@ impl<S: Stage> SingleAttributeParser<S> for EiiParser {
2119
Some(AttributeKind::Eii(cx.attr_span))
2220
}
2321
}
24-
25-
// pub(crate) struct EiiImplParser;
26-
//
27-
// impl<S: Stage> SingleAttributeParser<S> for EiiImplParser {
28-
// const PATH: &'static [rustc_span::Symbol] = &[sym::eii_impl];
29-
// const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepLast;
30-
// const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
31-
// const TEMPLATE: AttributeTemplate = template!(List: "<eii_id>, /*opt*/ default");
32-
//
33-
// fn convert(cx: &AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
34-
// let Some(l) = args.list() else {
35-
// cx.expected_list(cx.attr_span);
36-
// return None;
37-
// };
38-
//
39-
// let mut args = l.mixed();
40-
//
41-
// let id = args.next().unwrap();
42-
// let is_default = args.next();
43-
// assert!(args.next().is_none());
44-
//
45-
// let Some(id) = id.lit().and_then(|i| if let LitKind::Int(i, _) = i.kind {
46-
// Some(i)
47-
// } else {
48-
// None
49-
// }) else {
50-
// bug!("expected integer");
51-
// };
52-
//
53-
// let Ok(id) = u32::try_from(id.get()) else {
54-
// bug!("too large");
55-
// };
56-
// let id = EiiId::from(id);
57-
//
58-
// // AttributeKind::EiiImpl { eii: (), is_default: () }
59-
// todo!()
60-
// }
61-
// }
62-
//

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::stability::{
2019
BodyStabilityParser, ConstStabilityIndirectParser, ConstStabilityParser, StabilityParser,
@@ -77,7 +76,6 @@ attribute_groups!(
7776
// tidy-alphabetical-start
7877
Single<ConstStabilityIndirectParser>,
7978
Single<DeprecationParser>,
80-
Single<EiiParser>,
8179
Single<TransparencyParser>,
8280
// tidy-alphabetical-end
8381
];

compiler/rustc_builtin_macros/src/eii.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub(crate) fn eii_macro(
3131

3232
assert!(meta_item.is_word());
3333

34-
f.eii_impl.push((DUMMY_NODE_ID, meta_item.clone()));
34+
f.eii_impl.push((DUMMY_NODE_ID, meta_item.path.clone()));
3535

3636
vec![item]
3737
}

0 commit comments

Comments
 (0)