@@ -32,8 +32,7 @@ use crate::utils::{
3232 is_copy, is_expn_of, is_type_diagnostic_item, iter_input_pats, last_path_segment, match_def_path, match_qpath,
3333 match_trait_method, match_type, match_var, method_calls, method_chain_args, paths, remove_blocks, return_ty,
3434 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 ,
3736} ;
3837
3938declare_clippy_lint ! {
@@ -2753,16 +2752,15 @@ fn lint_map_unwrap_or_else<'tcx>(
27532752 let multiline = map_snippet. lines ( ) . count ( ) > 1 || unwrap_snippet. lines ( ) . count ( ) > 1 ;
27542753 let same_span = map_args[ 1 ] . span . ctxt ( ) == unwrap_args[ 1 ] . span . ctxt ( ) ;
27552754 if same_span && !multiline {
2756- span_lint_and_note (
2755+ let var_snippet = snippet ( cx, map_args[ 0 ] . span , ".." ) ;
2756+ span_lint_and_sugg (
27572757 cx,
27582758 MAP_UNWRAP_OR ,
27592759 expr. span ,
27602760 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 ,
27662764 ) ;
27672765 return true ;
27682766 } else if same_span && multiline {
@@ -2852,14 +2850,16 @@ fn lint_filter_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, fil
28522850 `.find(..)` instead.";
28532851 let filter_snippet = snippet ( cx, filter_args[ 1 ] . span , ".." ) ;
28542852 if filter_snippet. lines ( ) . count ( ) <= 1 {
2853+ let iter_snippet = snippet ( cx, filter_args[ 0 ] . span , ".." ) ;
28552854 // add note if not multi-line
2856- span_lint_and_note (
2855+ span_lint_and_sugg (
28572856 cx,
28582857 FILTER_NEXT ,
28592858 expr. span ,
28602859 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 ,
28632863 ) ;
28642864 } else {
28652865 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<'_>,
29082908 `.find_map(..)` instead.";
29092909 let filter_snippet = snippet ( cx, filter_args[ 1 ] . span , ".." ) ;
29102910 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 (
29122913 cx,
29132914 FILTER_MAP_NEXT ,
29142915 expr. span ,
29152916 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 ,
29182920 ) ;
29192921 } else {
29202922 span_lint ( cx, FILTER_MAP_NEXT , expr. span , msg) ;
0 commit comments