@@ -8,7 +8,7 @@ use std::borrow::Cow;
8
8
use std:: fmt;
9
9
use syntax:: codemap:: Span ;
10
10
use utils:: { get_trait_def_id, implements_trait, in_external_macro, in_macro, is_copy, match_path, match_trait_method,
11
- match_type, method_chain_args, return_ty, same_tys, snippet, span_lint, span_lint_and_then,
11
+ match_type, method_chain_args, return_ty, same_tys, snippet, span_lint, span_lint_and_then, span_lint_and_sugg ,
12
12
span_note_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth, last_path_segment, single_segment_path,
13
13
match_def_path, is_self, is_self_ty, iter_input_pats, match_path_old} ;
14
14
use utils:: paths;
@@ -725,15 +725,12 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[hir:
725
725
} ;
726
726
727
727
if implements_trait ( cx, arg_ty, default_trait_id, & [ ] ) {
728
- span_lint_and_then ( cx,
728
+ span_lint_and_sugg ( cx,
729
729
OR_FUN_CALL ,
730
730
span,
731
731
& format ! ( "use of `{}` followed by a call to `{}`" , name, path) ,
732
- |db| {
733
- db. span_suggestion ( span,
734
- "try this" ,
735
- format ! ( "{}.unwrap_or_default()" , snippet( cx, self_expr. span, "_" ) ) ) ;
736
- } ) ;
732
+ "try this" ,
733
+ format ! ( "{}.unwrap_or_default()" , snippet( cx, self_expr. span, "_" ) ) ) ;
737
734
return true ;
738
735
}
739
736
}
@@ -791,15 +788,12 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[hir:
791
788
( false , true ) => snippet ( cx, fun_span, ".." ) ,
792
789
} ;
793
790
794
- span_lint_and_then ( cx,
791
+ span_lint_and_sugg ( cx,
795
792
OR_FUN_CALL ,
796
793
span,
797
794
& format ! ( "use of `{}` followed by a function call" , name) ,
798
- |db| {
799
- db. span_suggestion ( span,
800
- "try this" ,
801
- format ! ( "{}.{}_{}({})" , snippet( cx, self_expr. span, "_" ) , name, suffix, sugg) ) ;
802
- } ) ;
795
+ "try this" ,
796
+ format ! ( "{}.{}_{}({})" , snippet( cx, self_expr. span, "_" ) , name, suffix, sugg) ) ;
803
797
}
804
798
805
799
if args. len ( ) == 2 {
@@ -865,14 +859,12 @@ fn lint_string_extend(cx: &LateContext, expr: &hir::Expr, args: &[hir::Expr]) {
865
859
return ;
866
860
} ;
867
861
868
- span_lint_and_then ( cx, STRING_EXTEND_CHARS , expr. span , "calling `.extend(_.chars())`" , |db| {
869
- db. span_suggestion ( expr. span ,
870
- "try this" ,
871
- format ! ( "{}.push_str({}{})" ,
872
- snippet( cx, args[ 0 ] . span, "_" ) ,
873
- ref_str,
874
- snippet( cx, target. span, "_" ) ) ) ;
875
- } ) ;
862
+ span_lint_and_sugg ( cx, STRING_EXTEND_CHARS , expr. span , "calling `.extend(_.chars())`" ,
863
+ "try this" ,
864
+ format ! ( "{}.push_str({}{})" ,
865
+ snippet( cx, args[ 0 ] . span, "_" ) ,
866
+ ref_str,
867
+ snippet( cx, target. span, "_" ) ) ) ;
876
868
}
877
869
}
878
870
@@ -951,20 +943,17 @@ fn lint_get_unwrap(cx: &LateContext, expr: &hir::Expr, get_args: &[hir::Expr], i
951
943
952
944
let mut_str = if is_mut { "_mut" } else { "" } ;
953
945
let borrow_str = if is_mut { "&mut " } else { "&" } ;
954
- span_lint_and_then ( cx,
946
+ span_lint_and_sugg ( cx,
955
947
GET_UNWRAP ,
956
948
expr. span ,
957
949
& format ! ( "called `.get{0}().unwrap()` on a {1}. Using `[]` is more clear and more concise" ,
958
950
mut_str,
959
951
caller_type) ,
960
- |db| {
961
- db. span_suggestion ( expr. span ,
962
- "try this" ,
963
- format ! ( "{}{}[{}]" ,
964
- borrow_str,
965
- snippet( cx, get_args[ 0 ] . span, "_" ) ,
966
- snippet( cx, get_args[ 1 ] . span, "_" ) ) ) ;
967
- } ) ;
952
+ "try this" ,
953
+ format ! ( "{}{}[{}]" ,
954
+ borrow_str,
955
+ snippet( cx, get_args[ 0 ] . span, "_" ) ,
956
+ snippet( cx, get_args[ 1 ] . span, "_" ) ) ) ;
968
957
}
969
958
970
959
fn lint_iter_skip_next ( cx : & LateContext , expr : & hir:: Expr ) {
@@ -1216,19 +1205,15 @@ fn lint_chars_next(cx: &LateContext, expr: &hir::Expr, chain: &hir::Expr, other:
1216
1205
return false ;
1217
1206
}
1218
1207
1219
- span_lint_and_then ( cx,
1208
+ span_lint_and_sugg ( cx,
1220
1209
CHARS_NEXT_CMP ,
1221
1210
expr. span,
1222
1211
"you should use the `starts_with` method" ,
1223
- |db| {
1224
- let sugg = format!( "{}{}.starts_with({})" ,
1225
- if eq { "" } else { "!" } ,
1226
- snippet( cx, args[ 0 ] [ 0 ] . span, "_" ) ,
1227
- snippet( cx, arg_char[ 0 ] . span, "_" )
1228
- ) ;
1229
-
1230
- db. span_suggestion( expr. span, "like this" , sugg) ;
1231
- } ) ;
1212
+ "like this" ,
1213
+ format!( "{}{}.starts_with({})" ,
1214
+ if eq { "" } else { "!" } ,
1215
+ snippet( cx, args[ 0 ] [ 0 ] . span, "_" ) ,
1216
+ snippet( cx, arg_char[ 0 ] . span, "_" ) ) ) ;
1232
1217
1233
1218
return true ;
1234
1219
} }
0 commit comments