@@ -32,8 +32,7 @@ use crate::utils::{
32
32
is_copy, is_expn_of, is_type_diagnostic_item, iter_input_pats, last_path_segment, match_def_path, match_qpath,
33
33
match_trait_method, match_type, match_var, method_calls, method_chain_args, paths, remove_blocks, return_ty,
34
34
single_segment_path, snippet, snippet_with_applicability, snippet_with_macro_callsite, span_lint,
35
- span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then, sugg, walk_ptrs_ty_depth,
36
- SpanlessEq ,
35
+ span_lint_and_help, span_lint_and_sugg, span_lint_and_then, sugg, walk_ptrs_ty_depth, SpanlessEq ,
37
36
} ;
38
37
39
38
declare_clippy_lint ! {
@@ -2753,16 +2752,15 @@ fn lint_map_unwrap_or_else<'tcx>(
2753
2752
let multiline = map_snippet. lines ( ) . count ( ) > 1 || unwrap_snippet. lines ( ) . count ( ) > 1 ;
2754
2753
let same_span = map_args[ 1 ] . span . ctxt ( ) == unwrap_args[ 1 ] . span . ctxt ( ) ;
2755
2754
if same_span && !multiline {
2756
- span_lint_and_note (
2755
+ let var_snippet = snippet ( cx, map_args[ 0 ] . span , ".." ) ;
2756
+ span_lint_and_sugg (
2757
2757
cx,
2758
2758
MAP_UNWRAP_OR ,
2759
2759
expr. span ,
2760
2760
msg,
2761
- None ,
2762
- & format ! (
2763
- "replace `map({0}).unwrap_or_else({1})` with `map_or_else({1}, {0})`" ,
2764
- map_snippet, unwrap_snippet,
2765
- ) ,
2761
+ "try this" ,
2762
+ format ! ( "{}.map_or_else({}, {})" , var_snippet, unwrap_snippet, map_snippet) ,
2763
+ Applicability :: MachineApplicable ,
2766
2764
) ;
2767
2765
return true ;
2768
2766
} else if same_span && multiline {
@@ -2852,14 +2850,16 @@ fn lint_filter_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, fil
2852
2850
`.find(..)` instead.";
2853
2851
let filter_snippet = snippet ( cx, filter_args[ 1 ] . span , ".." ) ;
2854
2852
if filter_snippet. lines ( ) . count ( ) <= 1 {
2853
+ let iter_snippet = snippet ( cx, filter_args[ 0 ] . span , ".." ) ;
2855
2854
// add note if not multi-line
2856
- span_lint_and_note (
2855
+ span_lint_and_sugg (
2857
2856
cx,
2858
2857
FILTER_NEXT ,
2859
2858
expr. span ,
2860
2859
msg,
2861
- None ,
2862
- & format ! ( "replace `filter({0}).next()` with `find({0})`" , filter_snippet) ,
2860
+ "try this" ,
2861
+ format ! ( "{}.find({})" , iter_snippet, filter_snippet) ,
2862
+ Applicability :: MachineApplicable ,
2863
2863
) ;
2864
2864
} else {
2865
2865
span_lint ( cx, FILTER_NEXT , expr. span , msg) ;
@@ -2908,13 +2908,15 @@ fn lint_filter_map_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>,
2908
2908
`.find_map(..)` instead.";
2909
2909
let filter_snippet = snippet ( cx, filter_args[ 1 ] . span , ".." ) ;
2910
2910
if filter_snippet. lines ( ) . count ( ) <= 1 {
2911
- span_lint_and_note (
2911
+ let iter_snippet = snippet ( cx, filter_args[ 0 ] . span , ".." ) ;
2912
+ span_lint_and_sugg (
2912
2913
cx,
2913
2914
FILTER_MAP_NEXT ,
2914
2915
expr. span ,
2915
2916
msg,
2916
- None ,
2917
- & format ! ( "replace `filter_map({0}).next()` with `find_map({0})`" , filter_snippet) ,
2917
+ "try this" ,
2918
+ format ! ( "{}.find_map({})" , iter_snippet, filter_snippet) ,
2919
+ Applicability :: MachineApplicable ,
2918
2920
) ;
2919
2921
} else {
2920
2922
span_lint ( cx, FILTER_MAP_NEXT , expr. span , msg) ;
0 commit comments