Skip to content

Commit 2911d9c

Browse files
committed
Use better placeholders for some methods lint messages
1 parent bf1c6f9 commit 2911d9c

10 files changed

+73
-73
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,7 +1748,7 @@ fn lint_or_fun_call<'tcx>(
17481748
"try this",
17491749
format!(
17501750
"{}.unwrap_or_default()",
1751-
snippet_with_applicability(cx, self_expr.span, "_", &mut applicability)
1751+
snippet_with_applicability(cx, self_expr.span, "..", &mut applicability)
17521752
),
17531753
applicability,
17541754
);
@@ -2155,7 +2155,7 @@ fn lint_clone_on_ref_ptr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::
21552155
return;
21562156
};
21572157

2158-
let snippet = snippet_with_macro_callsite(cx, arg.span, "_");
2158+
let snippet = snippet_with_macro_callsite(cx, arg.span, "..");
21592159

21602160
span_lint_and_sugg(
21612161
cx,
@@ -2191,9 +2191,9 @@ fn lint_string_extend(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::E
21912191
"try this",
21922192
format!(
21932193
"{}.push_str({}{})",
2194-
snippet_with_applicability(cx, args[0].span, "_", &mut applicability),
2194+
snippet_with_applicability(cx, args[0].span, "..", &mut applicability),
21952195
ref_str,
2196-
snippet_with_applicability(cx, target.span, "_", &mut applicability)
2196+
snippet_with_applicability(cx, target.span, "..", &mut applicability)
21972197
),
21982198
applicability,
21992199
);
@@ -2460,7 +2460,7 @@ fn lint_get_unwrap<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, get_args:
24602460
let mut applicability = Applicability::MachineApplicable;
24612461
let expr_ty = cx.typeck_results().expr_ty(&get_args[0]);
24622462
let get_args_str = if get_args.len() > 1 {
2463-
snippet_with_applicability(cx, get_args[1].span, "_", &mut applicability)
2463+
snippet_with_applicability(cx, get_args[1].span, "..", &mut applicability)
24642464
} else {
24652465
return; // not linting on a .get().unwrap() chain or variant
24662466
};
@@ -2520,7 +2520,7 @@ fn lint_get_unwrap<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, get_args:
25202520
format!(
25212521
"{}{}[{}]",
25222522
borrow_str,
2523-
snippet_with_applicability(cx, get_args[0].span, "_", &mut applicability),
2523+
snippet_with_applicability(cx, get_args[0].span, "..", &mut applicability),
25242524
get_args_str
25252525
),
25262526
applicability,
@@ -2536,7 +2536,7 @@ fn lint_iter_skip_next(cx: &LateContext<'_>, expr: &hir::Expr<'_>, skip_args: &[
25362536
cx,
25372537
ITER_SKIP_NEXT,
25382538
expr.span.trim_start(caller.span).unwrap(),
2539-
"called `skip(x).next()` on an iterator",
2539+
"called `skip(..).next()` on an iterator",
25402540
"use `nth` instead",
25412541
hint,
25422542
Applicability::MachineApplicable,
@@ -2739,11 +2739,11 @@ fn lint_map_unwrap_or_else<'tcx>(
27392739

27402740
// lint message
27412741
let msg = if is_option {
2742-
"called `map(f).unwrap_or_else(g)` on an `Option` value. This can be done more directly by calling \
2743-
`map_or_else(g, f)` instead"
2742+
"called `map(<f>).unwrap_or_else(<g>)` on an `Option` value. This can be done more directly by calling \
2743+
`map_or_else(<g>, <f>)` instead"
27442744
} else {
2745-
"called `map(f).unwrap_or_else(g)` on a `Result` value. This can be done more directly by calling \
2746-
`.map_or_else(g, f)` instead"
2745+
"called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling \
2746+
`.map_or_else(<g>, <f>)` instead"
27472747
};
27482748
// get snippets for args to map() and unwrap_or_else()
27492749
let map_snippet = snippet(cx, map_args[1].span, "..");
@@ -2809,8 +2809,8 @@ fn lint_map_or_none<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, map
28092809
if is_option {
28102810
let self_snippet = snippet(cx, map_or_args[0].span, "..");
28112811
let func_snippet = snippet(cx, map_or_args[2].span, "..");
2812-
let msg = "called `map_or(None, f)` on an `Option` value. This can be done more directly by calling \
2813-
`and_then(f)` instead";
2812+
let msg = "called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling \
2813+
`and_then(..)` instead";
28142814
(
28152815
OPTION_MAP_OR_NONE,
28162816
msg,
@@ -2848,8 +2848,8 @@ fn lint_map_or_none<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, map
28482848
fn lint_filter_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, filter_args: &'tcx [hir::Expr<'_>]) {
28492849
// lint if caller of `.filter().next()` is an Iterator
28502850
if match_trait_method(cx, expr, &paths::ITERATOR) {
2851-
let msg = "called `filter(p).next()` on an `Iterator`. This is more succinctly expressed by calling \
2852-
`.find(p)` instead.";
2851+
let msg = "called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling \
2852+
`.find(..)` instead.";
28532853
let filter_snippet = snippet(cx, filter_args[1].span, "..");
28542854
if filter_snippet.lines().count() <= 1 {
28552855
// add note if not multi-line
@@ -2879,9 +2879,9 @@ fn lint_skip_while_next<'tcx>(
28792879
cx,
28802880
SKIP_WHILE_NEXT,
28812881
expr.span,
2882-
"called `skip_while(p).next()` on an `Iterator`",
2882+
"called `skip_while(<p>).next()` on an `Iterator`",
28832883
None,
2884-
"this is more succinctly expressed by calling `.find(!p)` instead",
2884+
"this is more succinctly expressed by calling `.find(!<p>)` instead",
28852885
);
28862886
}
28872887
}
@@ -2895,7 +2895,7 @@ fn lint_filter_map<'tcx>(
28952895
) {
28962896
// lint if caller of `.filter().map()` is an Iterator
28972897
if match_trait_method(cx, expr, &paths::ITERATOR) {
2898-
let msg = "called `filter(p).map(q)` on an `Iterator`";
2898+
let msg = "called `filter(..).map(..)` on an `Iterator`";
28992899
let hint = "this is more succinctly expressed by calling `.filter_map(..)` instead";
29002900
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint);
29012901
}
@@ -2904,8 +2904,8 @@ fn lint_filter_map<'tcx>(
29042904
/// lint use of `filter_map().next()` for `Iterators`
29052905
fn lint_filter_map_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, filter_args: &'tcx [hir::Expr<'_>]) {
29062906
if match_trait_method(cx, expr, &paths::ITERATOR) {
2907-
let msg = "called `filter_map(p).next()` on an `Iterator`. This is more succinctly expressed by calling \
2908-
`.find_map(p)` instead.";
2907+
let msg = "called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling \
2908+
`.find_map(..)` instead.";
29092909
let filter_snippet = snippet(cx, filter_args[1].span, "..");
29102910
if filter_snippet.lines().count() <= 1 {
29112911
span_lint_and_note(
@@ -2931,7 +2931,7 @@ fn lint_find_map<'tcx>(
29312931
) {
29322932
// lint if caller of `.filter().map()` is an Iterator
29332933
if match_trait_method(cx, &map_args[0], &paths::ITERATOR) {
2934-
let msg = "called `find(p).map(q)` on an `Iterator`";
2934+
let msg = "called `find(..).map(..)` on an `Iterator`";
29352935
let hint = "this is more succinctly expressed by calling `.find_map(..)` instead";
29362936
span_lint_and_help(cx, FIND_MAP, expr.span, msg, None, hint);
29372937
}
@@ -2946,7 +2946,7 @@ fn lint_filter_map_map<'tcx>(
29462946
) {
29472947
// lint if caller of `.filter().map()` is an Iterator
29482948
if match_trait_method(cx, expr, &paths::ITERATOR) {
2949-
let msg = "called `filter_map(p).map(q)` on an `Iterator`";
2949+
let msg = "called `filter_map(..).map(..)` on an `Iterator`";
29502950
let hint = "this is more succinctly expressed by only calling `.filter_map(..)` instead";
29512951
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint);
29522952
}
@@ -2961,7 +2961,7 @@ fn lint_filter_flat_map<'tcx>(
29612961
) {
29622962
// lint if caller of `.filter().flat_map()` is an Iterator
29632963
if match_trait_method(cx, expr, &paths::ITERATOR) {
2964-
let msg = "called `filter(p).flat_map(q)` on an `Iterator`";
2964+
let msg = "called `filter(..).flat_map(..)` on an `Iterator`";
29652965
let hint = "this is more succinctly expressed by calling `.flat_map(..)` \
29662966
and filtering by returning `iter::empty()`";
29672967
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint);
@@ -2977,7 +2977,7 @@ fn lint_filter_map_flat_map<'tcx>(
29772977
) {
29782978
// lint if caller of `.filter_map().flat_map()` is an Iterator
29792979
if match_trait_method(cx, expr, &paths::ITERATOR) {
2980-
let msg = "called `filter_map(p).flat_map(q)` on an `Iterator`";
2980+
let msg = "called `filter_map(..).flat_map(..)` on an `Iterator`";
29812981
let hint = "this is more succinctly expressed by calling `.flat_map(..)` \
29822982
and filtering by returning `iter::empty()`";
29832983
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint);
@@ -3148,9 +3148,9 @@ fn lint_chars_cmp(
31483148
"like this",
31493149
format!("{}{}.{}({})",
31503150
if info.eq { "" } else { "!" },
3151-
snippet_with_applicability(cx, args[0][0].span, "_", &mut applicability),
3151+
snippet_with_applicability(cx, args[0][0].span, "..", &mut applicability),
31523152
suggest,
3153-
snippet_with_applicability(cx, arg_char[0].span, "_", &mut applicability)),
3153+
snippet_with_applicability(cx, arg_char[0].span, "..", &mut applicability)),
31543154
applicability,
31553155
);
31563156

@@ -3197,7 +3197,7 @@ fn lint_chars_cmp_with_unwrap<'tcx>(
31973197
"like this",
31983198
format!("{}{}.{}('{}')",
31993199
if info.eq { "" } else { "!" },
3200-
snippet_with_applicability(cx, args[0][0].span, "_", &mut applicability),
3200+
snippet_with_applicability(cx, args[0][0].span, "..", &mut applicability),
32013201
suggest,
32023202
c),
32033203
applicability,
@@ -3272,7 +3272,7 @@ fn lint_single_char_pattern(cx: &LateContext<'_>, _expr: &hir::Expr<'_>, arg: &h
32723272
fn lint_single_char_push_string(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) {
32733273
let mut applicability = Applicability::MachineApplicable;
32743274
if let Some(extension_string) = get_hint_if_single_char_arg(cx, &args[1], &mut applicability) {
3275-
let base_string_snippet = snippet_with_applicability(cx, args[0].span, "_", &mut applicability);
3275+
let base_string_snippet = snippet_with_applicability(cx, args[0].span, "..", &mut applicability);
32763276
let sugg = format!("{}.push({})", base_string_snippet, extension_string);
32773277
span_lint_and_sugg(
32783278
cx,
@@ -3315,7 +3315,7 @@ fn lint_asref(cx: &LateContext<'_>, expr: &hir::Expr<'_>, call_name: &str, as_re
33153315
expr.span,
33163316
&format!("this call to `{}` does nothing", call_name),
33173317
"try this",
3318-
snippet_with_applicability(cx, recvr.span, "_", &mut applicability).to_string(),
3318+
snippet_with_applicability(cx, recvr.span, "..", &mut applicability).to_string(),
33193319
applicability,
33203320
);
33213321
}

clippy_lints/src/methods/option_map_unwrap_or.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ pub(super) fn lint<'tcx>(
5353
// lint message
5454
// comparing the snippet from source to raw text ("None") below is safe
5555
// because we already have checked the type.
56-
let arg = if unwrap_snippet == "None" { "None" } else { "a" };
56+
let arg = if unwrap_snippet == "None" { "None" } else { "<a>" };
5757
let unwrap_snippet_none = unwrap_snippet == "None";
5858
let suggest = if unwrap_snippet_none {
59-
"and_then(f)"
59+
"and_then(<f>)"
6060
} else {
61-
"map_or(a, f)"
61+
"map_or(<a>, <f>)"
6262
};
6363
let msg = &format!(
64-
"called `map(f).unwrap_or({})` on an `Option` value. \
64+
"called `map(<f>).unwrap_or({})` on an `Option` value. \
6565
This can be done more directly by calling `{}` instead",
6666
arg, suggest
6767
);

tests/ui/filter_map_next.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: called `filter_map(p).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(p)` instead.
1+
error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead.
22
--> $DIR/filter_map_next.rs:6:32
33
|
44
LL | let element: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
@@ -7,7 +7,7 @@ LL | let element: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next
77
= note: `-D clippy::filter-map-next` implied by `-D warnings`
88
= note: replace `filter_map(|s| s.parse().ok()).next()` with `find_map(|s| s.parse().ok())`
99

10-
error: called `filter_map(p).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(p)` instead.
10+
error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead.
1111
--> $DIR/filter_map_next.rs:10:26
1212
|
1313
LL | let _: Option<u32> = vec![1, 2, 3, 4, 5, 6]

tests/ui/filter_methods.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: called `filter(p).map(q)` on an `Iterator`
1+
error: called `filter(..).map(..)` on an `Iterator`
22
--> $DIR/filter_methods.rs:5:21
33
|
44
LL | let _: Vec<_> = vec![5; 6].into_iter().filter(|&x| x == 0).map(|x| x * 2).collect();
@@ -7,7 +7,7 @@ LL | let _: Vec<_> = vec![5; 6].into_iter().filter(|&x| x == 0).map(|x| x *
77
= note: `-D clippy::filter-map` implied by `-D warnings`
88
= help: this is more succinctly expressed by calling `.filter_map(..)` instead
99

10-
error: called `filter(p).flat_map(q)` on an `Iterator`
10+
error: called `filter(..).flat_map(..)` on an `Iterator`
1111
--> $DIR/filter_methods.rs:7:21
1212
|
1313
LL | let _: Vec<_> = vec![5_i8; 6]
@@ -19,7 +19,7 @@ LL | | .flat_map(|x| x.checked_mul(2))
1919
|
2020
= help: this is more succinctly expressed by calling `.flat_map(..)` and filtering by returning `iter::empty()`
2121

22-
error: called `filter_map(p).flat_map(q)` on an `Iterator`
22+
error: called `filter_map(..).flat_map(..)` on an `Iterator`
2323
--> $DIR/filter_methods.rs:13:21
2424
|
2525
LL | let _: Vec<_> = vec![5_i8; 6]
@@ -31,7 +31,7 @@ LL | | .flat_map(|x| x.checked_mul(2))
3131
|
3232
= help: this is more succinctly expressed by calling `.flat_map(..)` and filtering by returning `iter::empty()`
3333

34-
error: called `filter_map(p).map(q)` on an `Iterator`
34+
error: called `filter_map(..).map(..)` on an `Iterator`
3535
--> $DIR/filter_methods.rs:19:21
3636
|
3737
LL | let _: Vec<_> = vec![5_i8; 6]

tests/ui/find_map.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: called `find(p).map(q)` on an `Iterator`
1+
error: called `find(..).map(..)` on an `Iterator`
22
--> $DIR/find_map.rs:20:26
33
|
44
LL | let _: Option<i32> = a.iter().find(|s| s.parse::<i32>().is_ok()).map(|s| s.parse().unwrap());
@@ -7,7 +7,7 @@ LL | let _: Option<i32> = a.iter().find(|s| s.parse::<i32>().is_ok()).map(|s
77
= note: `-D clippy::find-map` implied by `-D warnings`
88
= help: this is more succinctly expressed by calling `.find_map(..)` instead
99

10-
error: called `find(p).map(q)` on an `Iterator`
10+
error: called `find(..).map(..)` on an `Iterator`
1111
--> $DIR/find_map.rs:23:29
1212
|
1313
LL | let _: Option<Flavor> = desserts_of_the_week

tests/ui/iter_skip_next.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
error: called `skip(x).next()` on an iterator
1+
error: called `skip(..).next()` on an iterator
22
--> $DIR/iter_skip_next.rs:15:28
33
|
44
LL | let _ = some_vec.iter().skip(42).next();
55
| ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(42)`
66
|
77
= note: `-D clippy::iter-skip-next` implied by `-D warnings`
88

9-
error: called `skip(x).next()` on an iterator
9+
error: called `skip(..).next()` on an iterator
1010
--> $DIR/iter_skip_next.rs:16:36
1111
|
1212
LL | let _ = some_vec.iter().cycle().skip(42).next();
1313
| ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(42)`
1414

15-
error: called `skip(x).next()` on an iterator
15+
error: called `skip(..).next()` on an iterator
1616
--> $DIR/iter_skip_next.rs:17:20
1717
|
1818
LL | let _ = (1..10).skip(10).next();
1919
| ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(10)`
2020

21-
error: called `skip(x).next()` on an iterator
21+
error: called `skip(..).next()` on an iterator
2222
--> $DIR/iter_skip_next.rs:18:33
2323
|
2424
LL | let _ = &some_vec[..].iter().skip(3).next();

0 commit comments

Comments
 (0)