@@ -2133,14 +2133,12 @@ fn lint_iter_nth<'a, 'tcx>(
2133
2133
return ; // caller is not a type that we want to lint
2134
2134
} ;
2135
2135
2136
- span_lint (
2136
+ span_help_and_lint (
2137
2137
cx,
2138
2138
ITER_NTH ,
2139
2139
expr. span ,
2140
- & format ! (
2141
- "called `.iter{0}().nth()` on a {1}. Calling `.get{0}()` is both faster and more readable" ,
2142
- mut_str, caller_type
2143
- ) ,
2140
+ & format ! ( "called `.iter{0}().nth()` on a {1}" , mut_str, caller_type) ,
2141
+ & format ! ( "Calling `.get{}()` is both faster and more readable" , mut_str) ,
2144
2142
) ;
2145
2143
}
2146
2144
@@ -2244,11 +2242,12 @@ fn lint_get_unwrap<'a, 'tcx>(
2244
2242
fn lint_iter_skip_next ( cx : & LateContext < ' _ , ' _ > , expr : & hir:: Expr < ' _ > ) {
2245
2243
// lint if caller of skip is an Iterator
2246
2244
if match_trait_method ( cx, expr, & paths:: ITERATOR ) {
2247
- span_lint (
2245
+ span_help_and_lint (
2248
2246
cx,
2249
2247
ITER_SKIP_NEXT ,
2250
2248
expr. span ,
2251
- "called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)`" ,
2249
+ "called `skip(x).next()` on an iterator" ,
2250
+ "This is more succinctly expressed by calling `nth(x)`." ,
2252
2251
) ;
2253
2252
}
2254
2253
}
@@ -2304,15 +2303,15 @@ fn lint_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, unwrap_args: &[hi
2304
2303
} ;
2305
2304
2306
2305
if let Some ( ( lint, kind, none_value) ) = mess {
2307
- span_lint (
2306
+ span_help_and_lint (
2308
2307
cx,
2309
2308
lint,
2310
2309
expr. span ,
2310
+ & format ! ( "used `unwrap()` on `{}` value" , kind, ) ,
2311
2311
& format ! (
2312
- "used `unwrap()` on `{}` value. If you don't want to handle the `{}` case gracefully, consider \
2313
- using `expect()` to provide a better panic \
2314
- message",
2315
- kind, none_value
2312
+ "If you don't want to handle the `{}` case gracefully, consider \
2313
+ using `expect()` to provide a better panic message.",
2314
+ none_value,
2316
2315
) ,
2317
2316
) ;
2318
2317
}
@@ -2331,14 +2330,12 @@ fn lint_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, expect_args: &[hi
2331
2330
} ;
2332
2331
2333
2332
if let Some ( ( lint, kind, none_value) ) = mess {
2334
- span_lint (
2333
+ span_help_and_lint (
2335
2334
cx,
2336
2335
lint,
2337
2336
expr. span ,
2338
- & format ! (
2339
- "used `expect()` on `{}` value. If this value is an `{}` it will panic" ,
2340
- kind, none_value
2341
- ) ,
2337
+ & format ! ( "used `expect()` on `{}` value" , kind, ) ,
2338
+ & format ! ( "If this value is an `{}`, it will panic." , none_value, ) ,
2342
2339
) ;
2343
2340
}
2344
2341
}
@@ -2353,11 +2350,12 @@ fn lint_ok_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, ok_args: &[hir
2353
2350
if has_debug_impl( error_type, cx) ;
2354
2351
2355
2352
then {
2356
- span_lint (
2353
+ span_help_and_lint (
2357
2354
cx,
2358
2355
OK_EXPECT ,
2359
2356
expr. span,
2360
- "called `ok().expect()` on a `Result` value. You can call `expect()` directly on the `Result`" ,
2357
+ "called `ok().expect()` on a `Result` value" ,
2358
+ "You can call `expect()` directly on the `Result`" ,
2361
2359
) ;
2362
2360
}
2363
2361
}
@@ -2372,14 +2370,15 @@ fn lint_map_flatten<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<
2372
2370
let self_snippet = snippet ( cx, map_args[ 0 ] . span , ".." ) ;
2373
2371
let func_snippet = snippet ( cx, map_args[ 1 ] . span , ".." ) ;
2374
2372
let hint = format ! ( "{0}.flat_map({1})" , self_snippet, func_snippet) ;
2375
- span_lint_and_then ( cx, MAP_FLATTEN , expr. span , msg, |db| {
2376
- db. span_suggestion (
2377
- expr. span ,
2378
- "try using `flat_map` instead" ,
2379
- hint,
2380
- Applicability :: MachineApplicable ,
2381
- ) ;
2382
- } ) ;
2373
+ span_lint_and_sugg (
2374
+ cx,
2375
+ MAP_FLATTEN ,
2376
+ expr. span ,
2377
+ msg,
2378
+ "try using `flat_map` instead" ,
2379
+ hint,
2380
+ Applicability :: MachineApplicable ,
2381
+ ) ;
2383
2382
}
2384
2383
}
2385
2384
@@ -2474,14 +2473,15 @@ fn lint_map_or_none<'a, 'tcx>(
2474
2473
let map_or_self_snippet = snippet ( cx, map_or_args[ 0 ] . span , ".." ) ;
2475
2474
let map_or_func_snippet = snippet ( cx, map_or_args[ 2 ] . span , ".." ) ;
2476
2475
let hint = format ! ( "{0}.and_then({1})" , map_or_self_snippet, map_or_func_snippet) ;
2477
- span_lint_and_then ( cx, OPTION_MAP_OR_NONE , expr. span , msg, |db| {
2478
- db. span_suggestion (
2479
- expr. span ,
2480
- "try using `and_then` instead" ,
2481
- hint,
2482
- Applicability :: MachineApplicable , // snippet
2483
- ) ;
2484
- } ) ;
2476
+ span_lint_and_sugg (
2477
+ cx,
2478
+ OPTION_MAP_OR_NONE ,
2479
+ expr. span ,
2480
+ msg,
2481
+ "try using `and_then` instead" ,
2482
+ hint,
2483
+ Applicability :: MachineApplicable ,
2484
+ ) ;
2485
2485
}
2486
2486
}
2487
2487
}
@@ -2607,9 +2607,9 @@ fn lint_filter_map<'a, 'tcx>(
2607
2607
) {
2608
2608
// lint if caller of `.filter().map()` is an Iterator
2609
2609
if match_trait_method ( cx, expr, & paths:: ITERATOR ) {
2610
- let msg = "called `filter(p).map(q)` on an `Iterator`. \
2611
- This is more succinctly expressed by calling `.filter_map(..)` instead.";
2612
- span_lint ( cx, FILTER_MAP , expr. span , msg) ;
2610
+ let msg = "called `filter(p).map(q)` on an `Iterator`" ;
2611
+ let hint = " This is more succinctly expressed by calling `.filter_map(..)` instead.";
2612
+ span_help_and_lint ( cx, FILTER_MAP , expr. span , msg, hint ) ;
2613
2613
}
2614
2614
}
2615
2615
@@ -2647,9 +2647,9 @@ fn lint_find_map<'a, 'tcx>(
2647
2647
) {
2648
2648
// lint if caller of `.filter().map()` is an Iterator
2649
2649
if match_trait_method ( cx, & map_args[ 0 ] , & paths:: ITERATOR ) {
2650
- let msg = "called `find(p).map(q)` on an `Iterator`. \
2651
- This is more succinctly expressed by calling `.find_map(..)` instead.";
2652
- span_lint ( cx, FIND_MAP , expr. span , msg) ;
2650
+ let msg = "called `find(p).map(q)` on an `Iterator`" ;
2651
+ let hint = " This is more succinctly expressed by calling `.find_map(..)` instead.";
2652
+ span_help_and_lint ( cx, FIND_MAP , expr. span , msg, hint ) ;
2653
2653
}
2654
2654
}
2655
2655
@@ -2662,9 +2662,9 @@ fn lint_filter_map_map<'a, 'tcx>(
2662
2662
) {
2663
2663
// lint if caller of `.filter().map()` is an Iterator
2664
2664
if match_trait_method ( cx, expr, & paths:: ITERATOR ) {
2665
- let msg = "called `filter_map(p).map(q)` on an `Iterator`. \
2666
- This is more succinctly expressed by only calling `.filter_map(..)` instead.";
2667
- span_lint ( cx, FILTER_MAP , expr. span , msg) ;
2665
+ let msg = "called `filter_map(p).map(q)` on an `Iterator`" ;
2666
+ let hint = " This is more succinctly expressed by only calling `.filter_map(..)` instead.";
2667
+ span_help_and_lint ( cx, FILTER_MAP , expr. span , msg, hint ) ;
2668
2668
}
2669
2669
}
2670
2670
@@ -2677,10 +2677,10 @@ fn lint_filter_flat_map<'a, 'tcx>(
2677
2677
) {
2678
2678
// lint if caller of `.filter().flat_map()` is an Iterator
2679
2679
if match_trait_method ( cx, expr, & paths:: ITERATOR ) {
2680
- let msg = "called `filter(p).flat_map(q)` on an `Iterator`. \
2681
- This is more succinctly expressed by calling `.flat_map(..)` \
2682
- and filtering by returning an empty Iterator.";
2683
- span_lint ( cx, FILTER_MAP , expr. span , msg) ;
2680
+ let msg = "called `filter(p).flat_map(q)` on an `Iterator`" ;
2681
+ let hint = " This is more succinctly expressed by calling `.flat_map(..)` \
2682
+ and filtering by returning an empty Iterator.";
2683
+ span_help_and_lint ( cx, FILTER_MAP , expr. span , msg, hint ) ;
2684
2684
}
2685
2685
}
2686
2686
@@ -2693,10 +2693,10 @@ fn lint_filter_map_flat_map<'a, 'tcx>(
2693
2693
) {
2694
2694
// lint if caller of `.filter_map().flat_map()` is an Iterator
2695
2695
if match_trait_method ( cx, expr, & paths:: ITERATOR ) {
2696
- let msg = "called `filter_map(p).flat_map(q)` on an `Iterator`. \
2697
- This is more succinctly expressed by calling `.flat_map(..)` \
2698
- and filtering by returning an empty Iterator.";
2699
- span_lint ( cx, FILTER_MAP , expr. span , msg) ;
2696
+ let msg = "called `filter_map(p).flat_map(q)` on an `Iterator`" ;
2697
+ let hint = " This is more succinctly expressed by calling `.flat_map(..)` \
2698
+ and filtering by returning an empty Iterator.";
2699
+ span_help_and_lint ( cx, FILTER_MAP , expr. span , msg, hint ) ;
2700
2700
}
2701
2701
}
2702
2702
0 commit comments