Remove ast::{Impl,Trait}{Item,ItemKind}
.
This commit is contained in:
parent
35e9e097e7
commit
abf2e7aa95
@ -477,11 +477,11 @@ fn visit_item(&mut self, item: &'tcx Item) {
|
||||
});
|
||||
}
|
||||
|
||||
fn visit_trait_item(&mut self, item: &'tcx TraitItem) {
|
||||
fn visit_trait_item(&mut self, item: &'tcx AssocItem) {
|
||||
self.lctx.allocate_hir_id_counter(item.id);
|
||||
|
||||
match item.kind {
|
||||
TraitItemKind::Method(_, None) => {
|
||||
AssocItemKind::Method(_, None) => {
|
||||
// Ignore patterns in trait methods without bodies
|
||||
self.with_hir_id_owner(None, |this| {
|
||||
visit::walk_trait_item(this, item)
|
||||
@ -493,7 +493,7 @@ fn visit_trait_item(&mut self, item: &'tcx TraitItem) {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_impl_item(&mut self, item: &'tcx ImplItem) {
|
||||
fn visit_impl_item(&mut self, item: &'tcx AssocItem) {
|
||||
self.lctx.allocate_hir_id_counter(item.id);
|
||||
self.with_hir_id_owner(Some(item.id), |this| {
|
||||
visit::walk_impl_item(this, item);
|
||||
|
@ -86,7 +86,7 @@ fn visit_item(&mut self, item: &'tcx Item) {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_trait_item(&mut self, item: &'tcx TraitItem) {
|
||||
fn visit_trait_item(&mut self, item: &'tcx AssocItem) {
|
||||
self.lctx.with_hir_id_owner(item.id, |lctx| {
|
||||
let hir_item = lctx.lower_trait_item(item);
|
||||
let id = hir::TraitItemId { hir_id: hir_item.hir_id };
|
||||
@ -97,7 +97,7 @@ fn visit_trait_item(&mut self, item: &'tcx TraitItem) {
|
||||
visit::walk_assoc_item(self, item);
|
||||
}
|
||||
|
||||
fn visit_impl_item(&mut self, item: &'tcx ImplItem) {
|
||||
fn visit_impl_item(&mut self, item: &'tcx AssocItem) {
|
||||
self.lctx.with_hir_id_owner(item.id, |lctx| {
|
||||
let hir_item = lctx.lower_impl_item(item);
|
||||
let id = hir::ImplItemId { hir_id: hir_item.hir_id };
|
||||
@ -813,11 +813,11 @@ fn lower_struct_field(&mut self, (index, f): (usize, &StructField)) -> hir::Stru
|
||||
}
|
||||
}
|
||||
|
||||
fn lower_trait_item(&mut self, i: &TraitItem) -> hir::TraitItem {
|
||||
fn lower_trait_item(&mut self, i: &AssocItem) -> hir::TraitItem {
|
||||
let trait_item_def_id = self.resolver.definitions().local_def_id(i.id);
|
||||
|
||||
let (generics, kind) = match i.kind {
|
||||
TraitItemKind::Const(ref ty, ref default) => (
|
||||
AssocItemKind::Const(ref ty, ref default) => (
|
||||
self.lower_generics(&i.generics, ImplTraitContext::disallowed()),
|
||||
hir::TraitItemKind::Const(
|
||||
self.lower_ty(ty, ImplTraitContext::disallowed()),
|
||||
@ -826,7 +826,7 @@ fn lower_trait_item(&mut self, i: &TraitItem) -> hir::TraitItem {
|
||||
.map(|x| self.lower_const_body(i.span, Some(x))),
|
||||
),
|
||||
),
|
||||
TraitItemKind::Method(ref sig, None) => {
|
||||
AssocItemKind::Method(ref sig, None) => {
|
||||
let names = self.lower_fn_params_to_names(&sig.decl);
|
||||
let (generics, sig) = self.lower_method_sig(
|
||||
&i.generics,
|
||||
@ -837,7 +837,7 @@ fn lower_trait_item(&mut self, i: &TraitItem) -> hir::TraitItem {
|
||||
);
|
||||
(generics, hir::TraitItemKind::Method(sig, hir::TraitMethod::Required(names)))
|
||||
}
|
||||
TraitItemKind::Method(ref sig, Some(ref body)) => {
|
||||
AssocItemKind::Method(ref sig, Some(ref body)) => {
|
||||
let body_id = self.lower_fn_body_block(i.span, &sig.decl, Some(body));
|
||||
let (generics, sig) = self.lower_method_sig(
|
||||
&i.generics,
|
||||
@ -848,7 +848,7 @@ fn lower_trait_item(&mut self, i: &TraitItem) -> hir::TraitItem {
|
||||
);
|
||||
(generics, hir::TraitItemKind::Method(sig, hir::TraitMethod::Provided(body_id)))
|
||||
}
|
||||
TraitItemKind::TyAlias(ref bounds, ref default) => {
|
||||
AssocItemKind::TyAlias(ref bounds, ref default) => {
|
||||
let generics = self.lower_generics(&i.generics, ImplTraitContext::disallowed());
|
||||
let kind = hir::TraitItemKind::Type(
|
||||
self.lower_param_bounds(bounds, ImplTraitContext::disallowed()),
|
||||
@ -859,7 +859,7 @@ fn lower_trait_item(&mut self, i: &TraitItem) -> hir::TraitItem {
|
||||
|
||||
(generics, kind)
|
||||
},
|
||||
TraitItemKind::Macro(..) => bug!("macro item shouldn't exist at this point"),
|
||||
AssocItemKind::Macro(..) => bug!("macro item shouldn't exist at this point"),
|
||||
};
|
||||
|
||||
hir::TraitItem {
|
||||
@ -872,21 +872,21 @@ fn lower_trait_item(&mut self, i: &TraitItem) -> hir::TraitItem {
|
||||
}
|
||||
}
|
||||
|
||||
fn lower_trait_item_ref(&mut self, i: &TraitItem) -> hir::TraitItemRef {
|
||||
fn lower_trait_item_ref(&mut self, i: &AssocItem) -> hir::TraitItemRef {
|
||||
let (kind, has_default) = match i.kind {
|
||||
TraitItemKind::Const(_, ref default) => {
|
||||
AssocItemKind::Const(_, ref default) => {
|
||||
(hir::AssocItemKind::Const, default.is_some())
|
||||
}
|
||||
TraitItemKind::TyAlias(_, ref default) => {
|
||||
AssocItemKind::TyAlias(_, ref default) => {
|
||||
(hir::AssocItemKind::Type, default.is_some())
|
||||
}
|
||||
TraitItemKind::Method(ref sig, ref default) => (
|
||||
AssocItemKind::Method(ref sig, ref default) => (
|
||||
hir::AssocItemKind::Method {
|
||||
has_self: sig.decl.has_self(),
|
||||
},
|
||||
default.is_some(),
|
||||
),
|
||||
TraitItemKind::Macro(..) => unimplemented!(),
|
||||
AssocItemKind::Macro(..) => unimplemented!(),
|
||||
};
|
||||
hir::TraitItemRef {
|
||||
id: hir::TraitItemId { hir_id: self.lower_node_id(i.id) },
|
||||
@ -902,18 +902,18 @@ fn expr_err(&mut self, span: Span) -> hir::Expr {
|
||||
self.expr(span, hir::ExprKind::Err, ThinVec::new())
|
||||
}
|
||||
|
||||
fn lower_impl_item(&mut self, i: &ImplItem) -> hir::ImplItem {
|
||||
fn lower_impl_item(&mut self, i: &AssocItem) -> hir::ImplItem {
|
||||
let impl_item_def_id = self.resolver.definitions().local_def_id(i.id);
|
||||
|
||||
let (generics, kind) = match i.kind {
|
||||
ImplItemKind::Const(ref ty, ref expr) => (
|
||||
AssocItemKind::Const(ref ty, ref expr) => (
|
||||
self.lower_generics(&i.generics, ImplTraitContext::disallowed()),
|
||||
hir::ImplItemKind::Const(
|
||||
self.lower_ty(ty, ImplTraitContext::disallowed()),
|
||||
self.lower_const_body(i.span, expr.as_deref()),
|
||||
),
|
||||
),
|
||||
ImplItemKind::Method(ref sig, ref body) => {
|
||||
AssocItemKind::Method(ref sig, ref body) => {
|
||||
self.current_item = Some(i.span);
|
||||
let body_id = self.lower_maybe_async_body(
|
||||
i.span,
|
||||
@ -932,7 +932,7 @@ fn lower_impl_item(&mut self, i: &ImplItem) -> hir::ImplItem {
|
||||
|
||||
(generics, hir::ImplItemKind::Method(sig, body_id))
|
||||
}
|
||||
ImplItemKind::TyAlias(_, ref ty) => {
|
||||
AssocItemKind::TyAlias(_, ref ty) => {
|
||||
let generics = self.lower_generics(&i.generics, ImplTraitContext::disallowed());
|
||||
let kind = match ty {
|
||||
None => {
|
||||
@ -951,7 +951,7 @@ fn lower_impl_item(&mut self, i: &ImplItem) -> hir::ImplItem {
|
||||
};
|
||||
(generics, kind)
|
||||
},
|
||||
ImplItemKind::Macro(..) => bug!("`TyMac` should have been expanded by now"),
|
||||
AssocItemKind::Macro(..) => bug!("`TyMac` should have been expanded by now"),
|
||||
};
|
||||
|
||||
hir::ImplItem {
|
||||
@ -968,7 +968,7 @@ fn lower_impl_item(&mut self, i: &ImplItem) -> hir::ImplItem {
|
||||
// [1] since `default impl` is not yet implemented, this is always true in impls
|
||||
}
|
||||
|
||||
fn lower_impl_item_ref(&mut self, i: &ImplItem) -> hir::ImplItemRef {
|
||||
fn lower_impl_item_ref(&mut self, i: &AssocItem) -> hir::ImplItemRef {
|
||||
hir::ImplItemRef {
|
||||
id: hir::ImplItemId { hir_id: self.lower_node_id(i.id) },
|
||||
ident: i.ident,
|
||||
@ -976,18 +976,18 @@ fn lower_impl_item_ref(&mut self, i: &ImplItem) -> hir::ImplItemRef {
|
||||
vis: self.lower_visibility(&i.vis, Some(i.id)),
|
||||
defaultness: self.lower_defaultness(i.defaultness, true /* [1] */),
|
||||
kind: match &i.kind {
|
||||
ImplItemKind::Const(..) => hir::AssocItemKind::Const,
|
||||
ImplItemKind::TyAlias(_, ty) => match ty
|
||||
AssocItemKind::Const(..) => hir::AssocItemKind::Const,
|
||||
AssocItemKind::TyAlias(_, ty) => match ty
|
||||
.as_deref()
|
||||
.and_then(|ty| ty.kind.opaque_top_hack())
|
||||
{
|
||||
None => hir::AssocItemKind::Type,
|
||||
Some(_) => hir::AssocItemKind::OpaqueTy,
|
||||
},
|
||||
ImplItemKind::Method(sig, _) => hir::AssocItemKind::Method {
|
||||
AssocItemKind::Method(sig, _) => hir::AssocItemKind::Method {
|
||||
has_self: sig.decl.has_self(),
|
||||
},
|
||||
ImplItemKind::Macro(..) => unimplemented!(),
|
||||
AssocItemKind::Macro(..) => unimplemented!(),
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -1249,7 +1249,7 @@ fn visit_poly_trait_ref(&mut self, t: &'a ast::PolyTraitRef, m: &'a ast::TraitBo
|
||||
ast_visit::walk_poly_trait_ref(self, t, m);
|
||||
}
|
||||
|
||||
fn visit_trait_item(&mut self, trait_item: &'a ast::TraitItem) {
|
||||
fn visit_trait_item(&mut self, trait_item: &'a ast::AssocItem) {
|
||||
self.with_lint_attrs(trait_item.id, &trait_item.attrs, |cx| {
|
||||
run_early_pass!(cx, check_trait_item, trait_item);
|
||||
ast_visit::walk_trait_item(cx, trait_item);
|
||||
@ -1257,7 +1257,7 @@ fn visit_trait_item(&mut self, trait_item: &'a ast::TraitItem) {
|
||||
});
|
||||
}
|
||||
|
||||
fn visit_impl_item(&mut self, impl_item: &'a ast::ImplItem) {
|
||||
fn visit_impl_item(&mut self, impl_item: &'a ast::AssocItem) {
|
||||
self.with_lint_attrs(impl_item.id, &impl_item.attrs, |cx| {
|
||||
run_early_pass!(cx, check_impl_item, impl_item);
|
||||
ast_visit::walk_impl_item(cx, impl_item);
|
||||
|
@ -258,10 +258,10 @@ fn check_fn_post(
|
||||
c: Span,
|
||||
d: ast::NodeId
|
||||
);
|
||||
fn check_trait_item(a: &ast::TraitItem);
|
||||
fn check_trait_item_post(a: &ast::TraitItem);
|
||||
fn check_impl_item(a: &ast::ImplItem);
|
||||
fn check_impl_item_post(a: &ast::ImplItem);
|
||||
fn check_trait_item(a: &ast::AssocItem);
|
||||
fn check_trait_item_post(a: &ast::AssocItem);
|
||||
fn check_impl_item(a: &ast::AssocItem);
|
||||
fn check_impl_item_post(a: &ast::AssocItem);
|
||||
fn check_struct_def(a: &ast::VariantData);
|
||||
fn check_struct_def_post(a: &ast::VariantData);
|
||||
fn check_struct_field(a: &ast::StructField);
|
||||
|
@ -776,22 +776,17 @@ fn visit_item_kind(&mut self, i: &mut ast::ItemKind) {
|
||||
self.run(is_const, |s| noop_visit_item_kind(i, s))
|
||||
}
|
||||
|
||||
fn flat_map_trait_item(&mut self, i: ast::TraitItem) -> SmallVec<[ast::TraitItem; 1]> {
|
||||
fn flat_map_trait_item(&mut self, i: ast::AssocItem) -> SmallVec<[ast::AssocItem; 1]> {
|
||||
let is_const = match i.kind {
|
||||
ast::TraitItemKind::Const(..) => true,
|
||||
ast::TraitItemKind::Method(ref sig, _) => Self::is_sig_const(sig),
|
||||
ast::AssocItemKind::Const(..) => true,
|
||||
ast::AssocItemKind::Method(ref sig, _) => Self::is_sig_const(sig),
|
||||
_ => false,
|
||||
};
|
||||
self.run(is_const, |s| noop_flat_map_assoc_item(i, s))
|
||||
}
|
||||
|
||||
fn flat_map_impl_item(&mut self, i: ast::ImplItem) -> SmallVec<[ast::ImplItem; 1]> {
|
||||
let is_const = match i.kind {
|
||||
ast::ImplItemKind::Const(..) => true,
|
||||
ast::ImplItemKind::Method(ref sig, _) => Self::is_sig_const(sig),
|
||||
_ => false,
|
||||
};
|
||||
self.run(is_const, |s| noop_flat_map_assoc_item(i, s))
|
||||
fn flat_map_impl_item(&mut self, i: ast::AssocItem) -> SmallVec<[ast::AssocItem; 1]> {
|
||||
self.flat_map_trait_item(i)
|
||||
}
|
||||
|
||||
fn visit_anon_const(&mut self, c: &mut ast::AnonConst) {
|
||||
|
@ -268,8 +268,8 @@ fn check_fn(&mut self,
|
||||
}
|
||||
}
|
||||
|
||||
fn check_trait_item(&mut self, cx: &EarlyContext<'_>, item: &ast::TraitItem) {
|
||||
if let ast::TraitItemKind::Method(ref sig, None) = item.kind {
|
||||
fn check_trait_item(&mut self, cx: &EarlyContext<'_>, item: &ast::AssocItem) {
|
||||
if let ast::AssocItemKind::Method(ref sig, None) = item.kind {
|
||||
if sig.header.unsafety == ast::Unsafety::Unsafe {
|
||||
self.report_unsafe(cx, item.span, "declaration of an `unsafe` method")
|
||||
}
|
||||
@ -615,9 +615,9 @@ fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item) {
|
||||
);
|
||||
|
||||
impl EarlyLintPass for AnonymousParameters {
|
||||
fn check_trait_item(&mut self, cx: &EarlyContext<'_>, it: &ast::TraitItem) {
|
||||
fn check_trait_item(&mut self, cx: &EarlyContext<'_>, it: &ast::AssocItem) {
|
||||
match it.kind {
|
||||
ast::TraitItemKind::Method(ref sig, _) => {
|
||||
ast::AssocItemKind::Method(ref sig, _) => {
|
||||
for arg in sig.decl.inputs.iter() {
|
||||
match arg.pat.kind {
|
||||
ast::PatKind::Ident(_, ident, None) => {
|
||||
|
@ -544,7 +544,7 @@ fn visit_item(&mut self, item: &'a Item) {
|
||||
}
|
||||
for impl_item in impl_items {
|
||||
self.invalid_visibility(&impl_item.vis, None);
|
||||
if let ImplItemKind::Method(ref sig, _) = impl_item.kind {
|
||||
if let AssocItemKind::Method(ref sig, _) = impl_item.kind {
|
||||
self.check_trait_fn_not_const(sig.header.constness);
|
||||
self.check_trait_fn_not_async(impl_item.span, sig.header.asyncness.node);
|
||||
}
|
||||
|
@ -314,12 +314,12 @@ fn visit_fn(&mut self,
|
||||
ast_visit::walk_fn(self, fk, fd, s)
|
||||
}
|
||||
|
||||
fn visit_trait_item(&mut self, ti: &'v ast::TraitItem) {
|
||||
fn visit_trait_item(&mut self, ti: &'v ast::AssocItem) {
|
||||
self.record("TraitItem", Id::None, ti);
|
||||
ast_visit::walk_trait_item(self, ti)
|
||||
}
|
||||
|
||||
fn visit_impl_item(&mut self, ii: &'v ast::ImplItem) {
|
||||
fn visit_impl_item(&mut self, ii: &'v ast::AssocItem) {
|
||||
self.record("ImplItem", Id::None, ii);
|
||||
ast_visit::walk_impl_item(self, ii)
|
||||
}
|
||||
|
@ -30,7 +30,7 @@
|
||||
use syntax::ast::{Name, Ident};
|
||||
use syntax::attr;
|
||||
use syntax::ast::{self, Block, ForeignItem, ForeignItemKind, Item, ItemKind, NodeId};
|
||||
use syntax::ast::{MetaItemKind, StmtKind, TraitItem, TraitItemKind};
|
||||
use syntax::ast::{MetaItemKind, StmtKind, AssocItem, AssocItemKind};
|
||||
use syntax::token::{self, Token};
|
||||
use syntax::span_err;
|
||||
use syntax::source_map::{respan, Spanned};
|
||||
@ -1164,10 +1164,10 @@ fn visit_block(&mut self, block: &'b Block) {
|
||||
self.parent_scope.legacy = orig_current_legacy_scope;
|
||||
}
|
||||
|
||||
fn visit_trait_item(&mut self, item: &'b TraitItem) {
|
||||
fn visit_trait_item(&mut self, item: &'b AssocItem) {
|
||||
let parent = self.parent_scope.module;
|
||||
|
||||
if let TraitItemKind::Macro(_) = item.kind {
|
||||
if let AssocItemKind::Macro(_) = item.kind {
|
||||
self.visit_invoc(item.id);
|
||||
return
|
||||
}
|
||||
@ -1175,15 +1175,15 @@ fn visit_trait_item(&mut self, item: &'b TraitItem) {
|
||||
// Add the item to the trait info.
|
||||
let item_def_id = self.r.definitions.local_def_id(item.id);
|
||||
let (res, ns) = match item.kind {
|
||||
TraitItemKind::Const(..) => (Res::Def(DefKind::AssocConst, item_def_id), ValueNS),
|
||||
TraitItemKind::Method(ref sig, _) => {
|
||||
AssocItemKind::Const(..) => (Res::Def(DefKind::AssocConst, item_def_id), ValueNS),
|
||||
AssocItemKind::Method(ref sig, _) => {
|
||||
if sig.decl.has_self() {
|
||||
self.r.has_self.insert(item_def_id);
|
||||
}
|
||||
(Res::Def(DefKind::Method, item_def_id), ValueNS)
|
||||
}
|
||||
TraitItemKind::TyAlias(..) => (Res::Def(DefKind::AssocTy, item_def_id), TypeNS),
|
||||
TraitItemKind::Macro(_) => bug!(), // handled above
|
||||
AssocItemKind::TyAlias(..) => (Res::Def(DefKind::AssocTy, item_def_id), TypeNS),
|
||||
AssocItemKind::Macro(_) => bug!(), // handled above
|
||||
};
|
||||
|
||||
let vis = ty::Visibility::Public;
|
||||
@ -1193,8 +1193,8 @@ fn visit_trait_item(&mut self, item: &'b TraitItem) {
|
||||
visit::walk_trait_item(self, item);
|
||||
}
|
||||
|
||||
fn visit_impl_item(&mut self, item: &'b ast::ImplItem) {
|
||||
if let ast::ImplItemKind::Macro(..) = item.kind {
|
||||
fn visit_impl_item(&mut self, item: &'b ast::AssocItem) {
|
||||
if let ast::AssocItemKind::Macro(..) = item.kind {
|
||||
self.visit_invoc(item.id);
|
||||
} else {
|
||||
self.resolve_visibility(&item.vis);
|
||||
|
@ -212,23 +212,23 @@ fn visit_generic_param(&mut self, param: &'a GenericParam) {
|
||||
visit::walk_generic_param(self, param);
|
||||
}
|
||||
|
||||
fn visit_trait_item(&mut self, ti: &'a TraitItem) {
|
||||
fn visit_trait_item(&mut self, ti: &'a AssocItem) {
|
||||
let def_data = match ti.kind {
|
||||
TraitItemKind::Method(..) | TraitItemKind::Const(..) =>
|
||||
AssocItemKind::Method(..) | AssocItemKind::Const(..) =>
|
||||
DefPathData::ValueNs(ti.ident.name),
|
||||
TraitItemKind::TyAlias(..) => {
|
||||
AssocItemKind::TyAlias(..) => {
|
||||
DefPathData::TypeNs(ti.ident.name)
|
||||
},
|
||||
TraitItemKind::Macro(..) => return self.visit_macro_invoc(ti.id),
|
||||
AssocItemKind::Macro(..) => return self.visit_macro_invoc(ti.id),
|
||||
};
|
||||
|
||||
let def = self.create_def(ti.id, def_data, ti.span);
|
||||
self.with_parent(def, |this| visit::walk_trait_item(this, ti));
|
||||
}
|
||||
|
||||
fn visit_impl_item(&mut self, ii: &'a ImplItem) {
|
||||
fn visit_impl_item(&mut self, ii: &'a AssocItem) {
|
||||
let def_data = match ii.kind {
|
||||
ImplItemKind::Method(FnSig {
|
||||
AssocItemKind::Method(FnSig {
|
||||
ref header,
|
||||
ref decl,
|
||||
}, ref body) if header.asyncness.node.is_async() => {
|
||||
@ -242,10 +242,10 @@ fn visit_impl_item(&mut self, ii: &'a ImplItem) {
|
||||
body.as_deref(),
|
||||
)
|
||||
}
|
||||
ImplItemKind::Method(..) |
|
||||
ImplItemKind::Const(..) => DefPathData::ValueNs(ii.ident.name),
|
||||
ImplItemKind::TyAlias(..) => DefPathData::TypeNs(ii.ident.name),
|
||||
ImplItemKind::Macro(..) => return self.visit_macro_invoc(ii.id),
|
||||
AssocItemKind::Method(..) |
|
||||
AssocItemKind::Const(..) => DefPathData::ValueNs(ii.ident.name),
|
||||
AssocItemKind::TyAlias(..) => DefPathData::TypeNs(ii.ident.name),
|
||||
AssocItemKind::Macro(..) => return self.visit_macro_invoc(ii.id),
|
||||
};
|
||||
|
||||
let def = self.create_def(ii.id, def_data, ii.span);
|
||||
|
@ -806,7 +806,7 @@ fn resolve_item(&mut self, item: &Item) {
|
||||
this.with_generic_param_rib(&trait_item.generics, AssocItemRibKind,
|
||||
|this| {
|
||||
match trait_item.kind {
|
||||
TraitItemKind::Const(ref ty, ref default) => {
|
||||
AssocItemKind::Const(ref ty, ref default) => {
|
||||
this.visit_ty(ty);
|
||||
|
||||
// Only impose the restrictions of
|
||||
@ -818,13 +818,13 @@ fn resolve_item(&mut self, item: &Item) {
|
||||
});
|
||||
}
|
||||
}
|
||||
TraitItemKind::Method(_, _) => {
|
||||
AssocItemKind::Method(_, _) => {
|
||||
visit::walk_assoc_item(this, trait_item)
|
||||
}
|
||||
TraitItemKind::TyAlias(..) => {
|
||||
AssocItemKind::TyAlias(..) => {
|
||||
visit::walk_assoc_item(this, trait_item)
|
||||
}
|
||||
TraitItemKind::Macro(_) => {
|
||||
AssocItemKind::Macro(_) => {
|
||||
panic!("unexpanded macro in resolve!")
|
||||
}
|
||||
};
|
||||
@ -989,13 +989,13 @@ fn with_current_self_item<T>(&mut self, self_item: &Item, f: impl FnOnce(&mut Se
|
||||
/// When evaluating a `trait` use its associated types' idents for suggestionsa in E0412.
|
||||
fn with_trait_items<T>(
|
||||
&mut self,
|
||||
trait_items: &Vec<TraitItem>,
|
||||
trait_items: &Vec<AssocItem>,
|
||||
f: impl FnOnce(&mut Self) -> T,
|
||||
) -> T {
|
||||
let trait_assoc_types = replace(
|
||||
&mut self.diagnostic_metadata.current_trait_assoc_types,
|
||||
trait_items.iter().filter_map(|item| match &item.kind {
|
||||
TraitItemKind::TyAlias(bounds, _) if bounds.len() == 0 => Some(item.ident),
|
||||
AssocItemKind::TyAlias(bounds, _) if bounds.len() == 0 => Some(item.ident),
|
||||
_ => None,
|
||||
}).collect(),
|
||||
);
|
||||
@ -1063,7 +1063,7 @@ fn resolve_implementation(&mut self,
|
||||
opt_trait_reference: &Option<TraitRef>,
|
||||
self_type: &Ty,
|
||||
item_id: NodeId,
|
||||
impl_items: &[ImplItem]) {
|
||||
impl_items: &[AssocItem]) {
|
||||
debug!("resolve_implementation");
|
||||
// If applicable, create a rib for the type parameters.
|
||||
self.with_generic_param_rib(generics, ItemRibKind(HasGenericParams::Yes), |this| {
|
||||
@ -1092,9 +1092,9 @@ fn resolve_implementation(&mut self,
|
||||
|this| {
|
||||
use crate::ResolutionError::*;
|
||||
match impl_item.kind {
|
||||
ImplItemKind::Const(..) => {
|
||||
AssocItemKind::Const(..) => {
|
||||
debug!(
|
||||
"resolve_implementation ImplItemKind::Const",
|
||||
"resolve_implementation AssocItemKind::Const",
|
||||
);
|
||||
// If this is a trait impl, ensure the const
|
||||
// exists in trait
|
||||
@ -1109,7 +1109,7 @@ fn resolve_implementation(&mut self,
|
||||
visit::walk_assoc_item(this, impl_item)
|
||||
});
|
||||
}
|
||||
ImplItemKind::Method(..) => {
|
||||
AssocItemKind::Method(..) => {
|
||||
// If this is a trait impl, ensure the method
|
||||
// exists in trait
|
||||
this.check_trait_item(impl_item.ident,
|
||||
@ -1119,7 +1119,7 @@ fn resolve_implementation(&mut self,
|
||||
|
||||
visit::walk_assoc_item(this, impl_item);
|
||||
}
|
||||
ImplItemKind::TyAlias(_, Some(ref ty)) => {
|
||||
AssocItemKind::TyAlias(_, Some(ref ty)) => {
|
||||
// If this is a trait impl, ensure the type
|
||||
// exists in trait
|
||||
this.check_trait_item(impl_item.ident,
|
||||
@ -1129,8 +1129,8 @@ fn resolve_implementation(&mut self,
|
||||
|
||||
this.visit_ty(ty);
|
||||
}
|
||||
ImplItemKind::TyAlias(_, None) => {}
|
||||
ImplItemKind::Macro(_) =>
|
||||
AssocItemKind::TyAlias(_, None) => {}
|
||||
AssocItemKind::Macro(_) =>
|
||||
panic!("unexpanded macro in resolve!"),
|
||||
}
|
||||
});
|
||||
|
@ -676,7 +676,7 @@ fn process_impl(
|
||||
generics: &'l ast::Generics,
|
||||
trait_ref: &'l Option<ast::TraitRef>,
|
||||
typ: &'l ast::Ty,
|
||||
impl_items: &'l [ast::ImplItem],
|
||||
impl_items: &'l [ast::AssocItem],
|
||||
) {
|
||||
if let Some(impl_data) = self.save_ctxt.get_item_data(item) {
|
||||
if !self.span.filter_generated(item.span) {
|
||||
@ -707,7 +707,7 @@ fn process_trait(
|
||||
item: &'l ast::Item,
|
||||
generics: &'l ast::Generics,
|
||||
trait_refs: &'l ast::GenericBounds,
|
||||
methods: &'l [ast::TraitItem],
|
||||
methods: &'l [ast::AssocItem],
|
||||
) {
|
||||
let name = item.ident.to_string();
|
||||
let qualname = format!("::{}",
|
||||
@ -1029,11 +1029,11 @@ fn process_macro_use(&mut self, _span: Span) {
|
||||
// }
|
||||
}
|
||||
|
||||
fn process_trait_item(&mut self, trait_item: &'l ast::TraitItem, trait_id: DefId) {
|
||||
fn process_trait_item(&mut self, trait_item: &'l ast::AssocItem, trait_id: DefId) {
|
||||
self.process_macro_use(trait_item.span);
|
||||
let vis_span = trait_item.span.shrink_to_lo();
|
||||
match trait_item.kind {
|
||||
ast::TraitItemKind::Const(ref ty, ref expr) => {
|
||||
ast::AssocItemKind::Const(ref ty, ref expr) => {
|
||||
self.process_assoc_const(
|
||||
trait_item.id,
|
||||
trait_item.ident,
|
||||
@ -1044,7 +1044,7 @@ fn process_trait_item(&mut self, trait_item: &'l ast::TraitItem, trait_id: DefId
|
||||
&trait_item.attrs,
|
||||
);
|
||||
}
|
||||
ast::TraitItemKind::Method(ref sig, ref body) => {
|
||||
ast::AssocItemKind::Method(ref sig, ref body) => {
|
||||
self.process_method(
|
||||
sig,
|
||||
body.as_ref().map(|x| &**x),
|
||||
@ -1055,7 +1055,7 @@ fn process_trait_item(&mut self, trait_item: &'l ast::TraitItem, trait_id: DefId
|
||||
trait_item.span,
|
||||
);
|
||||
}
|
||||
ast::TraitItemKind::TyAlias(ref bounds, ref default_ty) => {
|
||||
ast::AssocItemKind::TyAlias(ref bounds, ref default_ty) => {
|
||||
// FIXME do something with _bounds (for type refs)
|
||||
let name = trait_item.ident.name.to_string();
|
||||
let qualname = format!("::{}",
|
||||
@ -1097,14 +1097,14 @@ fn process_trait_item(&mut self, trait_item: &'l ast::TraitItem, trait_id: DefId
|
||||
self.visit_ty(default_ty)
|
||||
}
|
||||
}
|
||||
ast::TraitItemKind::Macro(_) => {}
|
||||
ast::AssocItemKind::Macro(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn process_impl_item(&mut self, impl_item: &'l ast::ImplItem, impl_id: DefId) {
|
||||
fn process_impl_item(&mut self, impl_item: &'l ast::AssocItem, impl_id: DefId) {
|
||||
self.process_macro_use(impl_item.span);
|
||||
match impl_item.kind {
|
||||
ast::ImplItemKind::Const(ref ty, ref expr) => {
|
||||
ast::AssocItemKind::Const(ref ty, ref expr) => {
|
||||
self.process_assoc_const(
|
||||
impl_item.id,
|
||||
impl_item.ident,
|
||||
@ -1115,7 +1115,7 @@ fn process_impl_item(&mut self, impl_item: &'l ast::ImplItem, impl_id: DefId) {
|
||||
&impl_item.attrs,
|
||||
);
|
||||
}
|
||||
ast::ImplItemKind::Method(ref sig, ref body) => {
|
||||
ast::AssocItemKind::Method(ref sig, ref body) => {
|
||||
self.process_method(
|
||||
sig,
|
||||
body.as_deref(),
|
||||
@ -1126,14 +1126,14 @@ fn process_impl_item(&mut self, impl_item: &'l ast::ImplItem, impl_id: DefId) {
|
||||
impl_item.span,
|
||||
);
|
||||
}
|
||||
ast::ImplItemKind::TyAlias(_, None) => {}
|
||||
ast::ImplItemKind::TyAlias(_, Some(ref ty)) => {
|
||||
ast::AssocItemKind::TyAlias(_, None) => {}
|
||||
ast::AssocItemKind::TyAlias(_, Some(ref ty)) => {
|
||||
// FIXME: uses of the assoc type should ideally point to this
|
||||
// 'def' and the name here should be a ref to the def in the
|
||||
// trait.
|
||||
self.visit_ty(ty)
|
||||
}
|
||||
ast::ImplItemKind::Macro(_) => {}
|
||||
ast::AssocItemKind::Macro(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1603,16 +1603,10 @@ pub struct FnSig {
|
||||
pub decl: P<FnDecl>,
|
||||
}
|
||||
|
||||
// FIXME(Centril): Remove all of these.
|
||||
pub type TraitItem = AssocItem<AssocItemKind>;
|
||||
pub type TraitItemKind = AssocItemKind;
|
||||
pub type ImplItem = AssocItem<AssocItemKind>;
|
||||
pub type ImplItemKind = AssocItemKind;
|
||||
|
||||
/// Represents associated items.
|
||||
/// These include items in `impl` and `trait` definitions.
|
||||
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
||||
pub struct AssocItem<K = ImplItemKind> {
|
||||
pub struct AssocItem {
|
||||
pub attrs: Vec<Attribute>,
|
||||
pub id: NodeId,
|
||||
pub span: Span,
|
||||
@ -1621,7 +1615,7 @@ pub struct AssocItem<K = ImplItemKind> {
|
||||
|
||||
pub defaultness: Defaultness,
|
||||
pub generics: Generics,
|
||||
pub kind: K,
|
||||
pub kind: AssocItemKind,
|
||||
/// See `Item::tokens` for what this is.
|
||||
pub tokens: Option<TokenStream>,
|
||||
}
|
||||
@ -2598,7 +2592,7 @@ pub enum ItemKind {
|
||||
/// A trait declaration (`trait`).
|
||||
///
|
||||
/// E.g., `trait Foo { .. }`, `trait Foo<T> { .. }` or `auto trait Foo {}`.
|
||||
Trait(IsAuto, Unsafety, Generics, GenericBounds, Vec<TraitItem>),
|
||||
Trait(IsAuto, Unsafety, Generics, GenericBounds, Vec<AssocItem>),
|
||||
/// Trait alias
|
||||
///
|
||||
/// E.g., `trait Foo = Bar + Quux;`.
|
||||
@ -2613,7 +2607,7 @@ pub enum ItemKind {
|
||||
Generics,
|
||||
Option<TraitRef>, // (optional) trait this impl implements
|
||||
P<Ty>, // self
|
||||
Vec<ImplItem>,
|
||||
Vec<AssocItem>,
|
||||
),
|
||||
/// A macro invocation.
|
||||
///
|
||||
|
@ -571,9 +571,9 @@ fn visit_assoc_ty_constraint(&mut self, constraint: &'a AssocTyConstraint) {
|
||||
visit::walk_assoc_ty_constraint(self, constraint)
|
||||
}
|
||||
|
||||
fn visit_trait_item(&mut self, ti: &'a ast::TraitItem) {
|
||||
fn visit_trait_item(&mut self, ti: &'a ast::AssocItem) {
|
||||
match ti.kind {
|
||||
ast::TraitItemKind::Method(ref sig, ref block) => {
|
||||
ast::AssocItemKind::Method(ref sig, ref block) => {
|
||||
if block.is_none() {
|
||||
self.check_extern(sig.header.ext);
|
||||
}
|
||||
@ -581,7 +581,7 @@ fn visit_trait_item(&mut self, ti: &'a ast::TraitItem) {
|
||||
gate_feature_post!(&self, const_fn, ti.span, "const fn is unstable");
|
||||
}
|
||||
}
|
||||
ast::TraitItemKind::TyAlias(_, ref default) => {
|
||||
ast::AssocItemKind::TyAlias(_, ref default) => {
|
||||
if let Some(_) = default {
|
||||
gate_feature_post!(
|
||||
&self, associated_type_defaults, ti.span,
|
||||
|
@ -685,8 +685,8 @@ pub enum Nonterminal {
|
||||
// Used only for passing items to proc macro attributes (they are not
|
||||
// strictly necessary for that, `Annotatable` can be converted into
|
||||
// tokens directly, but doing that naively regresses pretty-printing).
|
||||
NtTraitItem(ast::TraitItem),
|
||||
NtImplItem(ast::ImplItem),
|
||||
NtTraitItem(ast::AssocItem),
|
||||
NtImplItem(ast::AssocItem),
|
||||
NtForeignItem(ast::ForeignItem),
|
||||
}
|
||||
|
||||
|
@ -31,8 +31,8 @@
|
||||
#[derive(Debug,Clone)]
|
||||
pub enum Annotatable {
|
||||
Item(P<ast::Item>),
|
||||
TraitItem(P<ast::TraitItem>),
|
||||
ImplItem(P<ast::ImplItem>),
|
||||
TraitItem(P<ast::AssocItem>),
|
||||
ImplItem(P<ast::AssocItem>),
|
||||
ForeignItem(P<ast::ForeignItem>),
|
||||
Stmt(P<ast::Stmt>),
|
||||
Expr(P<ast::Expr>),
|
||||
@ -137,14 +137,14 @@ pub fn map_item_or<F, G>(self, mut f: F, mut or: G) -> Annotatable
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_trait_item(self) -> ast::TraitItem {
|
||||
pub fn expect_trait_item(self) -> ast::AssocItem {
|
||||
match self {
|
||||
Annotatable::TraitItem(i) => i.into_inner(),
|
||||
_ => panic!("expected Item")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_impl_item(self) -> ast::ImplItem {
|
||||
pub fn expect_impl_item(self) -> ast::AssocItem {
|
||||
match self {
|
||||
Annotatable::ImplItem(i) => i.into_inner(),
|
||||
_ => panic!("expected Item")
|
||||
@ -382,12 +382,12 @@ fn make_expr(self: Box<Self>) -> Option<P<ast::Expr>> {
|
||||
}
|
||||
|
||||
/// Creates zero or more impl items.
|
||||
fn make_impl_items(self: Box<Self>) -> Option<SmallVec<[ast::ImplItem; 1]>> {
|
||||
fn make_impl_items(self: Box<Self>) -> Option<SmallVec<[ast::AssocItem; 1]>> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Creates zero or more trait items.
|
||||
fn make_trait_items(self: Box<Self>) -> Option<SmallVec<[ast::TraitItem; 1]>> {
|
||||
fn make_trait_items(self: Box<Self>) -> Option<SmallVec<[ast::AssocItem; 1]>> {
|
||||
None
|
||||
}
|
||||
|
||||
@ -468,8 +468,8 @@ pub fn $fld(v: $t) -> Box<dyn MacResult> {
|
||||
expr: P<ast::Expr>,
|
||||
pat: P<ast::Pat>,
|
||||
items: SmallVec<[P<ast::Item>; 1]>,
|
||||
impl_items: SmallVec<[ast::ImplItem; 1]>,
|
||||
trait_items: SmallVec<[ast::TraitItem; 1]>,
|
||||
impl_items: SmallVec<[ast::AssocItem; 1]>,
|
||||
trait_items: SmallVec<[ast::AssocItem; 1]>,
|
||||
foreign_items: SmallVec<[ast::ForeignItem; 1]>,
|
||||
stmts: SmallVec<[ast::Stmt; 1]>,
|
||||
ty: P<ast::Ty>,
|
||||
@ -484,11 +484,11 @@ fn make_expr(self: Box<Self>) -> Option<P<ast::Expr>> {
|
||||
self.items
|
||||
}
|
||||
|
||||
fn make_impl_items(self: Box<Self>) -> Option<SmallVec<[ast::ImplItem; 1]>> {
|
||||
fn make_impl_items(self: Box<Self>) -> Option<SmallVec<[ast::AssocItem; 1]>> {
|
||||
self.impl_items
|
||||
}
|
||||
|
||||
fn make_trait_items(self: Box<Self>) -> Option<SmallVec<[ast::TraitItem; 1]>> {
|
||||
fn make_trait_items(self: Box<Self>) -> Option<SmallVec<[ast::AssocItem; 1]>> {
|
||||
self.trait_items
|
||||
}
|
||||
|
||||
@ -588,11 +588,11 @@ fn make_pat(self: Box<DummyResult>) -> Option<P<ast::Pat>> {
|
||||
Some(SmallVec::new())
|
||||
}
|
||||
|
||||
fn make_impl_items(self: Box<DummyResult>) -> Option<SmallVec<[ast::ImplItem; 1]>> {
|
||||
fn make_impl_items(self: Box<DummyResult>) -> Option<SmallVec<[ast::AssocItem; 1]>> {
|
||||
Some(SmallVec::new())
|
||||
}
|
||||
|
||||
fn make_trait_items(self: Box<DummyResult>) -> Option<SmallVec<[ast::TraitItem; 1]>> {
|
||||
fn make_trait_items(self: Box<DummyResult>) -> Option<SmallVec<[ast::AssocItem; 1]>> {
|
||||
Some(SmallVec::new())
|
||||
}
|
||||
|
||||
|
@ -155,10 +155,10 @@ impl<'a> MacResult for crate::mbe::macro_rules::ParserAnyMacro<'a> {
|
||||
Items(SmallVec<[P<ast::Item>; 1]>) {
|
||||
"item"; many fn flat_map_item; fn visit_item; fn make_items;
|
||||
}
|
||||
TraitItems(SmallVec<[ast::TraitItem; 1]>) {
|
||||
TraitItems(SmallVec<[ast::AssocItem; 1]>) {
|
||||
"trait item"; many fn flat_map_trait_item; fn visit_trait_item; fn make_trait_items;
|
||||
}
|
||||
ImplItems(SmallVec<[ast::ImplItem; 1]>) {
|
||||
ImplItems(SmallVec<[ast::AssocItem; 1]>) {
|
||||
"impl item"; many fn flat_map_impl_item; fn visit_impl_item; fn make_impl_items;
|
||||
}
|
||||
ForeignItems(SmallVec<[ast::ForeignItem; 1]>) {
|
||||
|
@ -50,15 +50,15 @@ fn mac_placeholder() -> ast::Mac {
|
||||
kind: ast::ItemKind::Mac(mac_placeholder()),
|
||||
tokens: None,
|
||||
})]),
|
||||
AstFragmentKind::TraitItems => AstFragment::TraitItems(smallvec![ast::TraitItem {
|
||||
AstFragmentKind::TraitItems => AstFragment::TraitItems(smallvec![ast::AssocItem {
|
||||
id, span, ident, vis, attrs, generics,
|
||||
kind: ast::TraitItemKind::Macro(mac_placeholder()),
|
||||
kind: ast::AssocItemKind::Macro(mac_placeholder()),
|
||||
defaultness: ast::Defaultness::Final,
|
||||
tokens: None,
|
||||
}]),
|
||||
AstFragmentKind::ImplItems => AstFragment::ImplItems(smallvec![ast::ImplItem {
|
||||
AstFragmentKind::ImplItems => AstFragment::ImplItems(smallvec![ast::AssocItem {
|
||||
id, span, ident, vis, attrs, generics,
|
||||
kind: ast::ImplItemKind::Macro(mac_placeholder()),
|
||||
kind: ast::AssocItemKind::Macro(mac_placeholder()),
|
||||
defaultness: ast::Defaultness::Final,
|
||||
tokens: None,
|
||||
}]),
|
||||
|
@ -504,13 +504,13 @@ fn create_derived_impl(&self,
|
||||
type_ident: Ident,
|
||||
generics: &Generics,
|
||||
field_tys: Vec<P<ast::Ty>>,
|
||||
methods: Vec<ast::ImplItem>)
|
||||
methods: Vec<ast::AssocItem>)
|
||||
-> P<ast::Item> {
|
||||
let trait_path = self.path.to_path(cx, self.span, type_ident, generics);
|
||||
|
||||
// Transform associated types from `deriving::ty::Ty` into `ast::ImplItem`
|
||||
// Transform associated types from `deriving::ty::Ty` into `ast::AssocItem`
|
||||
let associated_types = self.associated_types.iter().map(|&(ident, ref type_def)| {
|
||||
ast::ImplItem {
|
||||
ast::AssocItem {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
span: self.span,
|
||||
ident,
|
||||
@ -518,7 +518,7 @@ fn create_derived_impl(&self,
|
||||
defaultness: ast::Defaultness::Final,
|
||||
attrs: Vec::new(),
|
||||
generics: Generics::default(),
|
||||
kind: ast::ImplItemKind::TyAlias(
|
||||
kind: ast::AssocItemKind::TyAlias(
|
||||
Vec::new(),
|
||||
Some(type_def.to_ty(cx, self.span, type_ident, generics)),
|
||||
),
|
||||
@ -912,7 +912,7 @@ fn create_method(&self,
|
||||
explicit_self: Option<ast::ExplicitSelf>,
|
||||
arg_types: Vec<(Ident, P<ast::Ty>)>,
|
||||
body: P<Expr>)
|
||||
-> ast::ImplItem {
|
||||
-> ast::AssocItem {
|
||||
// Create the generics that aren't for `Self`.
|
||||
let fn_generics = self.generics.to_generics(cx, trait_.span, type_ident, generics);
|
||||
|
||||
@ -950,7 +950,7 @@ fn create_method(&self,
|
||||
};
|
||||
|
||||
// Create the method.
|
||||
ast::ImplItem {
|
||||
ast::AssocItem {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
attrs: self.attributes.clone(),
|
||||
generics: fn_generics,
|
||||
@ -958,7 +958,7 @@ fn create_method(&self,
|
||||
vis: respan(trait_lo_sp, ast::VisibilityKind::Inherited),
|
||||
defaultness: ast::Defaultness::Final,
|
||||
ident: method_ident,
|
||||
kind: ast::ImplItemKind::Method(sig, Some(body_block)),
|
||||
kind: ast::AssocItemKind::Method(sig, Some(body_block)),
|
||||
tokens: None,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user