mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 10:13:54 +00:00
Make Target::from_impl_item a free function.
This commit is contained in:
parent
124fd9d2a4
commit
f9335e9908
@ -21,29 +21,23 @@ use rustc_span::Span;
|
|||||||
use syntax::ast::Attribute;
|
use syntax::ast::Attribute;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
|
|
||||||
pub(crate) trait TargetExt {
|
fn target_from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem<'_>) -> Target {
|
||||||
fn from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem<'_>) -> Target;
|
match impl_item.kind {
|
||||||
}
|
hir::ImplItemKind::Const(..) => Target::AssocConst,
|
||||||
|
hir::ImplItemKind::Method(..) => {
|
||||||
impl TargetExt for Target {
|
let parent_hir_id = tcx.hir().get_parent_item(impl_item.hir_id);
|
||||||
fn from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem<'_>) -> Target {
|
let containing_item = tcx.hir().expect_item(parent_hir_id);
|
||||||
match impl_item.kind {
|
let containing_impl_is_for_trait = match &containing_item.kind {
|
||||||
hir::ImplItemKind::Const(..) => Target::AssocConst,
|
hir::ItemKind::Impl { ref of_trait, .. } => of_trait.is_some(),
|
||||||
hir::ImplItemKind::Method(..) => {
|
_ => bug!("parent of an ImplItem must be an Impl"),
|
||||||
let parent_hir_id = tcx.hir().get_parent_item(impl_item.hir_id);
|
};
|
||||||
let containing_item = tcx.hir().expect_item(parent_hir_id);
|
if containing_impl_is_for_trait {
|
||||||
let containing_impl_is_for_trait = match &containing_item.kind {
|
Target::Method(MethodKind::Trait { body: true })
|
||||||
hir::ItemKind::Impl { ref of_trait, .. } => of_trait.is_some(),
|
} else {
|
||||||
_ => bug!("parent of an ImplItem must be an Impl"),
|
Target::Method(MethodKind::Inherent)
|
||||||
};
|
|
||||||
if containing_impl_is_for_trait {
|
|
||||||
Target::Method(MethodKind::Trait { body: true })
|
|
||||||
} else {
|
|
||||||
Target::Method(MethodKind::Inherent)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
hir::ImplItemKind::TyAlias(..) | hir::ImplItemKind::OpaqueTy(..) => Target::AssocTy,
|
|
||||||
}
|
}
|
||||||
|
hir::ImplItemKind::TyAlias(..) | hir::ImplItemKind::OpaqueTy(..) => Target::AssocTy,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -437,7 +431,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
|
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
|
||||||
let target = Target::from_impl_item(self.tcx, impl_item);
|
let target = target_from_impl_item(self.tcx, impl_item);
|
||||||
self.check_attributes(impl_item.hir_id, &impl_item.attrs, &impl_item.span, target, None);
|
self.check_attributes(impl_item.hir_id, &impl_item.attrs, &impl_item.span, target, None);
|
||||||
intravisit::walk_impl_item(self, impl_item)
|
intravisit::walk_impl_item(self, impl_item)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user