11use clippy_utils:: diagnostics:: { span_lint_and_help, span_lint_and_sugg, span_lint_and_then} ;
22use clippy_utils:: source:: { snippet, snippet_with_context} ;
33use clippy_utils:: sugg:: { DiagExt as _, Sugg } ;
4- use clippy_utils:: ty:: { is_copy, is_type_diagnostic_item, same_type_and_consts} ;
4+ use clippy_utils:: ty:: { get_type_diagnostic_name , is_copy, is_type_diagnostic_item, same_type_and_consts} ;
55use clippy_utils:: {
66 get_parent_expr, is_inherent_method_call, is_trait_item, is_trait_method, is_ty_alias, path_to_local,
77} ;
@@ -13,7 +13,7 @@ use rustc_infer::traits::Obligation;
1313use rustc_lint:: { LateContext , LateLintPass } ;
1414use rustc_middle:: traits:: ObligationCause ;
1515use rustc_middle:: ty:: adjustment:: { Adjust , AutoBorrow , AutoBorrowMutability } ;
16- use rustc_middle:: ty:: { self , AdtDef , EarlyBinder , GenericArg , GenericArgsRef , Ty , TypeVisitableExt } ;
16+ use rustc_middle:: ty:: { self , EarlyBinder , GenericArg , GenericArgsRef , Ty , TypeVisitableExt } ;
1717use rustc_session:: impl_lint_pass;
1818use rustc_span:: { Span , sym} ;
1919use rustc_trait_selection:: traits:: query:: evaluate_obligation:: InferCtxtExt ;
@@ -412,24 +412,14 @@ pub fn check_function_application(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &
412412}
413413
414414fn has_eligible_receiver ( cx : & LateContext < ' _ > , recv : & Expr < ' _ > , expr : & Expr < ' _ > ) -> bool {
415- let recv_ty = cx. typeck_results ( ) . expr_ty ( recv) ;
416- if is_inherent_method_call ( cx, expr)
417- && let Some ( recv_ty_defid) = recv_ty. ty_adt_def ( ) . map ( AdtDef :: did)
418- {
419- if let Some ( diag_name) = cx. tcx . get_diagnostic_name ( recv_ty_defid)
420- && matches ! ( diag_name, sym:: Option | sym:: Result )
421- {
422- return true ;
423- }
424-
425- if cx. tcx . is_diagnostic_item ( sym:: ControlFlow , recv_ty_defid) {
426- return true ;
427- }
428- }
429- if is_trait_method ( cx, expr, sym:: Iterator ) {
430- return true ;
415+ if is_inherent_method_call ( cx, expr) {
416+ matches ! (
417+ get_type_diagnostic_name( cx, cx. typeck_results( ) . expr_ty( recv) ) ,
418+ Some ( sym:: Option | sym:: Result | sym:: ControlFlow )
419+ )
420+ } else {
421+ is_trait_method ( cx, expr, sym:: Iterator )
431422 }
432- false
433423}
434424
435425fn adjustments ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> String {
0 commit comments