@@ -21,29 +21,23 @@ use rustc_span::Span;
2121use syntax:: ast:: Attribute ;
2222use syntax:: attr;
2323
24- pub ( crate ) trait TargetExt {
25- fn from_impl_item < ' tcx > ( tcx : TyCtxt < ' tcx > , impl_item : & hir:: ImplItem < ' _ > ) -> Target ;
26- }
27-
28- impl TargetExt for Target {
29- fn from_impl_item < ' tcx > ( tcx : TyCtxt < ' tcx > , impl_item : & hir:: ImplItem < ' _ > ) -> Target {
30- match impl_item. kind {
31- hir:: ImplItemKind :: Const ( ..) => Target :: AssocConst ,
32- hir:: ImplItemKind :: Method ( ..) => {
33- let parent_hir_id = tcx. hir ( ) . get_parent_item ( impl_item. hir_id ) ;
34- let containing_item = tcx. hir ( ) . expect_item ( parent_hir_id) ;
35- let containing_impl_is_for_trait = match & containing_item. kind {
36- hir:: ItemKind :: Impl { ref of_trait, .. } => of_trait. is_some ( ) ,
37- _ => bug ! ( "parent of an ImplItem must be an Impl" ) ,
38- } ;
39- if containing_impl_is_for_trait {
40- Target :: Method ( MethodKind :: Trait { body : true } )
41- } else {
42- Target :: Method ( MethodKind :: Inherent )
43- }
24+ fn target_from_impl_item < ' tcx > ( tcx : TyCtxt < ' tcx > , impl_item : & hir:: ImplItem < ' _ > ) -> Target {
25+ match impl_item. kind {
26+ hir:: ImplItemKind :: Const ( ..) => Target :: AssocConst ,
27+ hir:: ImplItemKind :: Method ( ..) => {
28+ let parent_hir_id = tcx. hir ( ) . get_parent_item ( impl_item. hir_id ) ;
29+ let containing_item = tcx. hir ( ) . expect_item ( parent_hir_id) ;
30+ let containing_impl_is_for_trait = match & containing_item. kind {
31+ hir:: ItemKind :: Impl { ref of_trait, .. } => of_trait. is_some ( ) ,
32+ _ => bug ! ( "parent of an ImplItem must be an Impl" ) ,
33+ } ;
34+ if containing_impl_is_for_trait {
35+ Target :: Method ( MethodKind :: Trait { body : true } )
36+ } else {
37+ Target :: Method ( MethodKind :: Inherent )
4438 }
45- hir:: ImplItemKind :: TyAlias ( ..) | hir:: ImplItemKind :: OpaqueTy ( ..) => Target :: AssocTy ,
4639 }
40+ hir:: ImplItemKind :: TyAlias ( ..) | hir:: ImplItemKind :: OpaqueTy ( ..) => Target :: AssocTy ,
4741 }
4842}
4943
@@ -437,7 +431,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
437431 }
438432
439433 fn visit_impl_item ( & mut self , impl_item : & ' tcx hir:: ImplItem < ' tcx > ) {
440- let target = Target :: from_impl_item ( self . tcx , impl_item) ;
434+ let target = target_from_impl_item ( self . tcx , impl_item) ;
441435 self . check_attributes ( impl_item. hir_id , & impl_item. attrs , & impl_item. span , target, None ) ;
442436 intravisit:: walk_impl_item ( self , impl_item)
443437 }
0 commit comments