@@ -17,9 +17,9 @@ use rustc_middle::mir::ConstValue;
1717use rustc_middle:: traits:: EvaluationResult ;
1818use rustc_middle:: ty:: layout:: ValidityRequirement ;
1919use rustc_middle:: ty:: {
20- self , AdtDef , AliasTy , AssocKind , Binder , BoundRegion , FnSig , GenericArg , GenericArgKind , GenericArgsRef ,
21- GenericParamDefKind , IntTy , ParamEnv , Region , RegionKind , TraitRef , Ty , TyCtxt , TypeSuperVisitable , TypeVisitable ,
22- TypeVisitableExt , TypeVisitor , UintTy , Upcast , VariantDef , VariantDiscr ,
20+ self , AdtDef , AliasTy , AssocItem , AssocKind , Binder , BoundRegion , FnSig , GenericArg , GenericArgKind ,
21+ GenericArgsRef , GenericParamDefKind , IntTy , List , ParamEnv , Region , RegionKind , ToPredicate , TraitRef , Ty , TyCtxt ,
22+ TypeSuperVisitable , TypeVisitable , TypeVisitableExt , TypeVisitor , UintTy , VariantDef , VariantDiscr ,
2323} ;
2424use rustc_span:: symbol:: Ident ;
2525use rustc_span:: { sym, Span , Symbol , DUMMY_SP } ;
@@ -1345,16 +1345,22 @@ pub fn deref_chain<'cx, 'tcx>(cx: &'cx LateContext<'tcx>, ty: Ty<'tcx>) -> impl
13451345/// Checks if a Ty<'_> has some inherent method Symbol.
13461346/// This does not look for impls in the type's `Deref::Target` type.
13471347/// If you need this, you should wrap this call in `clippy_utils::ty::deref_chain().any(...)`.
1348- pub fn adt_has_inherent_method ( cx : & LateContext < ' _ > , ty : Ty < ' _ > , method_name : Symbol ) -> bool {
1348+ pub fn get_adt_inherent_method < ' a > ( cx : & ' a LateContext < ' _ > , ty : Ty < ' _ > , method_name : Symbol ) -> Option < & ' a AssocItem > {
13491349 if let Some ( ty_did) = ty. ty_adt_def ( ) . map ( ty:: AdtDef :: did) {
1350- cx. tcx . inherent_impls ( ty_did) . into_iter ( ) . flatten ( ) . any ( |& did| {
1351- cx. tcx
1352- . associated_items ( did)
1353- . filter_by_name_unhygienic ( method_name)
1354- . next ( )
1355- . is_some_and ( |item| item. kind == ty:: AssocKind :: Fn )
1356- } )
1350+ cx. tcx
1351+ . inherent_impls ( ty_did)
1352+ . into_iter ( )
1353+ . flatten ( )
1354+ . map ( |& did| {
1355+ cx. tcx
1356+ . associated_items ( did)
1357+ . filter_by_name_unhygienic ( method_name)
1358+ . next ( )
1359+ . filter ( |item| item. kind == ty:: AssocKind :: Fn )
1360+ } )
1361+ . next ( )
1362+ . flatten ( )
13571363 } else {
1358- false
1364+ None
13591365 }
13601366}
0 commit comments