@@ -8,9 +8,10 @@ use clippy_utils::diagnostics::span_lint_and_note;
8
8
use clippy_utils:: is_cfg_test;
9
9
use rustc_attr_data_structures:: AttributeKind ;
10
10
use rustc_hir:: {
11
- AssocItemKind , Attribute , FieldDef , HirId , ImplItemRef , IsAuto , Item , ItemKind , Mod , QPath , TraitItemRef , TyKind ,
11
+ Attribute , FieldDef , HirId , ImplItemRef , IsAuto , Item , ItemKind , Mod , OwnerId , QPath , TraitItemRef , TyKind ,
12
12
Variant , VariantData ,
13
13
} ;
14
+ use rustc_middle:: ty:: AssocKind ;
14
15
use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
15
16
use rustc_session:: impl_lint_pass;
16
17
@@ -315,9 +316,9 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
315
316
}
316
317
317
318
if let Some ( cur_t) = cur_t {
318
- let cur_t_kind = convert_assoc_item_kind ( cur_t. kind ) ;
319
+ let cur_t_kind = convert_assoc_item_kind ( cx , cur_t. id . owner_id ) ;
319
320
let cur_t_kind_index = self . assoc_types_order . index_of ( & cur_t_kind) ;
320
- let item_kind = convert_assoc_item_kind ( item. kind ) ;
321
+ let item_kind = convert_assoc_item_kind ( cx , item. id . owner_id ) ;
321
322
let item_kind_index = self . assoc_types_order . index_of ( & item_kind) ;
322
323
323
324
if cur_t_kind == item_kind && cur_t. ident . name . as_str ( ) > item. ident . name . as_str ( ) {
@@ -338,9 +339,9 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
338
339
}
339
340
340
341
if let Some ( cur_t) = cur_t {
341
- let cur_t_kind = convert_assoc_item_kind ( cur_t. kind ) ;
342
+ let cur_t_kind = convert_assoc_item_kind ( cx , cur_t. id . owner_id ) ;
342
343
let cur_t_kind_index = self . assoc_types_order . index_of ( & cur_t_kind) ;
343
- let item_kind = convert_assoc_item_kind ( item. kind ) ;
344
+ let item_kind = convert_assoc_item_kind ( cx , item. id . owner_id ) ;
344
345
let item_kind_index = self . assoc_types_order . index_of ( & item_kind) ;
345
346
346
347
if cur_t_kind == item_kind && cur_t. ident . name . as_str ( ) > item. ident . name . as_str ( ) {
@@ -458,18 +459,19 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
458
459
}
459
460
}
460
461
461
- /// Converts a [`rustc_hir::AssocItemKind`] to a
462
- /// [`SourceItemOrderingTraitAssocItemKind`].
462
+ /// Converts a [`ty::AssocKind`] to a [`SourceItemOrderingTraitAssocItemKind`].
463
463
///
464
464
/// This is implemented here because `rustc_hir` is not a dependency of
465
465
/// `clippy_config`.
466
- fn convert_assoc_item_kind ( value : AssocItemKind ) -> SourceItemOrderingTraitAssocItemKind {
466
+ fn convert_assoc_item_kind ( cx : & LateContext < ' _ > , owner_id : OwnerId ) -> SourceItemOrderingTraitAssocItemKind {
467
+ let kind = cx. tcx . associated_item ( owner_id. def_id ) . kind ;
468
+
467
469
#[ allow( clippy:: enum_glob_use) ] // Very local glob use for legibility.
468
470
use SourceItemOrderingTraitAssocItemKind :: * ;
469
- match value {
470
- AssocItemKind :: Const => Const ,
471
- AssocItemKind :: Type => Type ,
472
- AssocItemKind :: Fn { .. } => Fn ,
471
+ match kind {
472
+ AssocKind :: Const { .. } => Const ,
473
+ AssocKind :: Type { .. } => Type ,
474
+ AssocKind :: Fn { .. } => Fn ,
473
475
}
474
476
}
475
477
0 commit comments