@@ -8,7 +8,7 @@ use rustc_errors::Applicability;
8
8
use rustc_hir:: { Expr , ExprKind } ;
9
9
use rustc_lint:: { LateContext , LintContext } ;
10
10
use rustc_middle:: lint:: in_external_macro;
11
- use rustc_middle:: ty:: Binder ;
11
+ use rustc_middle:: ty:: { self , Binder } ;
12
12
use rustc_span:: { sym, Span } ;
13
13
14
14
pub ( super ) fn check < ' tcx > ( cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' tcx > , arg : & Expr < ' _ > , call_span : Span ) {
@@ -36,6 +36,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, arg: &
36
36
&& let Some ( def_id) = cx. typeck_results ( ) . type_dependent_def_id ( value. hir_id )
37
37
&& match_def_path ( cx, def_id, & BOOL_THEN )
38
38
&& !is_from_proc_macro ( cx, expr)
39
+ && let ref_bool = matches ! ( cx. typeck_results( ) . expr_ty( recv) . kind( ) , ty:: Ref ( ..) )
39
40
&& let Some ( param_snippet) = snippet_opt ( cx, param. span )
40
41
&& let Some ( filter) = snippet_opt ( cx, recv. span )
41
42
&& let Some ( map) = snippet_opt ( cx, then_body. span )
@@ -46,7 +47,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, arg: &
46
47
call_span,
47
48
"usage of `bool::then` in `filter_map`" ,
48
49
"use `filter` then `map` instead" ,
49
- format ! ( "filter(|&{param_snippet}| {filter}).map(|{param_snippet}| {map})" ) ,
50
+ format ! ( "filter(|&{param_snippet}| {}{ filter}).map(|{param_snippet}| {map})" , if ref_bool { "*" } else { "" } ) ,
50
51
Applicability :: MachineApplicable ,
51
52
) ;
52
53
}
0 commit comments