@@ -2,12 +2,13 @@ use super::FILTER_MAP_BOOL_THEN;
22use clippy_utils:: diagnostics:: span_lint_and_sugg;
33use clippy_utils:: paths:: BOOL_THEN ;
44use clippy_utils:: source:: snippet_opt;
5- use clippy_utils:: ty:: { is_copy, peel_mid_ty_refs_is_mutable } ;
5+ use clippy_utils:: ty:: is_copy;
66use clippy_utils:: { is_from_proc_macro, is_trait_method, match_def_path, peel_blocks} ;
77use rustc_errors:: Applicability ;
88use rustc_hir:: { Expr , ExprKind } ;
99use rustc_lint:: { LateContext , LintContext } ;
1010use rustc_middle:: lint:: in_external_macro;
11+ use rustc_middle:: ty:: adjustment:: Adjust ;
1112use rustc_middle:: ty:: Binder ;
1213use rustc_span:: { sym, Span } ;
1314
@@ -36,11 +37,11 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, arg: &
3637 && let Some ( def_id) = cx. typeck_results ( ) . type_dependent_def_id ( value. hir_id )
3738 && match_def_path ( cx, def_id, & BOOL_THEN )
3839 && !is_from_proc_macro ( cx, expr)
39- // Peel all refs (e.g. `&&&&mut &&&bool` -> `bool`) and get its count so we can suggest the exact
40- // amount of derefs to get to the bool in the filter.
41- // `peel_mid_ty_refs` alone doesn't handle mutable reference, so we use `_is_mutable`
42- // instead which counts them too and just ignore the resulting mutability
43- && let ( _ , needed_derefs , _ ) = peel_mid_ty_refs_is_mutable ( cx . typeck_results ( ) . expr_ty ( recv ) )
40+ // Count the number of derefs needed to get to the bool because we need those in the suggestion
41+ && let needed_derefs = cx . typeck_results ( ) . expr_adjustments ( recv )
42+ . iter ( )
43+ . filter ( |adj| matches ! ( adj . kind , Adjust :: Deref ( _ ) ) )
44+ . count ( )
4445 && let Some ( param_snippet) = snippet_opt ( cx, param. span )
4546 && let Some ( filter) = snippet_opt ( cx, recv. span )
4647 && let Some ( map) = snippet_opt ( cx, then_body. span )
0 commit comments