Skip to content

Commit 40bd698

Browse files
committed
use self instead of super
1 parent d993bd1 commit 40bd698

1 file changed

Lines changed: 9 additions & 45 deletions

File tree

  • compiler/rustc_builtin_macros/src

compiler/rustc_builtin_macros/src/eii.rs

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ fn eii_(
105105
let item_span = func.sig.span;
106106
let foreign_item_name = func.ident;
107107

108-
let mut return_items = Vec::new();
108+
let mut module_items = Vec::new();
109109

110110
if func.body.is_some() {
111-
return_items.push(generate_default_impl(
111+
module_items.push(generate_default_impl(
112112
ecx,
113113
&func,
114114
impl_unsafe,
@@ -119,15 +119,15 @@ fn eii_(
119119
))
120120
}
121121

122-
return_items.push(generate_foreign_item(
122+
module_items.push(generate_foreign_item(
123123
ecx,
124124
eii_attr_span,
125125
item_span,
126126
func,
127127
vis,
128128
&attrs_from_decl,
129129
));
130-
return_items.push(generate_attribute_macro_to_implement(
130+
module_items.push(generate_attribute_macro_to_implement(
131131
ecx,
132132
eii_attr_span,
133133
macro_name,
@@ -136,7 +136,7 @@ fn eii_(
136136
&attrs_from_decl,
137137
));
138138

139-
return_items.into_iter().map(wrap_item).collect()
139+
module_items.into_iter().map(wrap_item).collect()
140140
}
141141

142142
/// Decide on the name of the macro that can be used to implement the EII.
@@ -213,29 +213,13 @@ fn generate_default_impl(
213213
known_eii_macro_resolution: Some(ast::EiiExternTarget {
214214
extern_item_path: ecx.path(
215215
foreign_item_name.span,
216-
// prefix super to escape the `dflt` module generated below
217-
vec![Ident::from_str_and_span("super", foreign_item_name.span), foreign_item_name],
216+
// prefix super to explicitly escape the const block generated below
217+
vec![Ident::from_str_and_span("self", foreign_item_name.span), foreign_item_name],
218218
),
219219
impl_unsafe,
220220
}),
221221
});
222222

223-
let item_mod = |span: Span, name: Ident, items: ThinVec<Box<ast::Item>>| {
224-
ecx.item(
225-
item_span,
226-
ThinVec::new(),
227-
ItemKind::Mod(
228-
ast::Safety::Default,
229-
name,
230-
ast::ModKind::Loaded(
231-
items,
232-
ast::Inline::Yes,
233-
ast::ModSpans { inner_span: span, inject_use_span: span },
234-
),
235-
),
236-
)
237-
};
238-
239223
let anon_mod = |span: Span, stmts: ThinVec<ast::Stmt>| {
240224
let unit = ecx.ty(item_span, ast::TyKind::Tup(ThinVec::new()));
241225
let underscore = Ident::new(kw::Underscore, item_span);
@@ -248,33 +232,13 @@ fn generate_default_impl(
248232
};
249233

250234
// const _: () = {
251-
// mod dflt {
252-
// use super::*;
253-
// <orig fn>
254-
// }
235+
// <orig fn>
255236
// }
256237
anon_mod(
257238
item_span,
258239
thin_vec![ecx.stmt_item(
259240
item_span,
260-
item_mod(
261-
item_span,
262-
Ident::from_str_and_span("dflt", item_span),
263-
thin_vec![
264-
ecx.item(
265-
item_span,
266-
thin_vec![ecx.attr_nested_word(sym::allow, sym::unused_imports, item_span)],
267-
ItemKind::Use(ast::UseTree {
268-
prefix: ast::Path::from_ident(Ident::from_str_and_span(
269-
"super", item_span,
270-
)),
271-
kind: ast::UseTreeKind::Glob,
272-
span: item_span,
273-
})
274-
),
275-
ecx.item(item_span, attrs, ItemKind::Fn(Box::new(default_func)))
276-
]
277-
)
241+
ecx.item(item_span, attrs, ItemKind::Fn(Box::new(default_func)))
278242
),],
279243
)
280244
}

0 commit comments

Comments
 (0)