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