Use better placeholders for some methods lint messages

This commit is contained in:
ThibsG 2020-10-18 13:09:06 +02:00
parent bf1c6f9871
commit 2911d9c7de
10 changed files with 73 additions and 73 deletions

View file

@ -1748,7 +1748,7 @@ fn lint_or_fun_call<'tcx>(
"try this", "try this",
format!( format!(
"{}.unwrap_or_default()", "{}.unwrap_or_default()",
snippet_with_applicability(cx, self_expr.span, "_", &mut applicability) snippet_with_applicability(cx, self_expr.span, "..", &mut applicability)
), ),
applicability, applicability,
); );
@ -2155,7 +2155,7 @@ fn lint_clone_on_ref_ptr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::
return; return;
}; };
let snippet = snippet_with_macro_callsite(cx, arg.span, "_"); let snippet = snippet_with_macro_callsite(cx, arg.span, "..");
span_lint_and_sugg( span_lint_and_sugg(
cx, cx,
@ -2191,9 +2191,9 @@ fn lint_string_extend(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::E
"try this", "try this",
format!( format!(
"{}.push_str({}{})", "{}.push_str({}{})",
snippet_with_applicability(cx, args[0].span, "_", &mut applicability), snippet_with_applicability(cx, args[0].span, "..", &mut applicability),
ref_str, ref_str,
snippet_with_applicability(cx, target.span, "_", &mut applicability) snippet_with_applicability(cx, target.span, "..", &mut applicability)
), ),
applicability, applicability,
); );
@ -2460,7 +2460,7 @@ fn lint_get_unwrap<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, get_args:
let mut applicability = Applicability::MachineApplicable; let mut applicability = Applicability::MachineApplicable;
let expr_ty = cx.typeck_results().expr_ty(&get_args[0]); let expr_ty = cx.typeck_results().expr_ty(&get_args[0]);
let get_args_str = if get_args.len() > 1 { let get_args_str = if get_args.len() > 1 {
snippet_with_applicability(cx, get_args[1].span, "_", &mut applicability) snippet_with_applicability(cx, get_args[1].span, "..", &mut applicability)
} else { } else {
return; // not linting on a .get().unwrap() chain or variant return; // not linting on a .get().unwrap() chain or variant
}; };
@ -2520,7 +2520,7 @@ fn lint_get_unwrap<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, get_args:
format!( format!(
"{}{}[{}]", "{}{}[{}]",
borrow_str, borrow_str,
snippet_with_applicability(cx, get_args[0].span, "_", &mut applicability), snippet_with_applicability(cx, get_args[0].span, "..", &mut applicability),
get_args_str get_args_str
), ),
applicability, applicability,
@ -2536,7 +2536,7 @@ fn lint_iter_skip_next(cx: &LateContext<'_>, expr: &hir::Expr<'_>, skip_args: &[
cx, cx,
ITER_SKIP_NEXT, ITER_SKIP_NEXT,
expr.span.trim_start(caller.span).unwrap(), expr.span.trim_start(caller.span).unwrap(),
"called `skip(x).next()` on an iterator", "called `skip(..).next()` on an iterator",
"use `nth` instead", "use `nth` instead",
hint, hint,
Applicability::MachineApplicable, Applicability::MachineApplicable,
@ -2739,11 +2739,11 @@ fn lint_map_unwrap_or_else<'tcx>(
// lint message // lint message
let msg = if is_option { let msg = if is_option {
"called `map(f).unwrap_or_else(g)` on an `Option` value. This can be done more directly by calling \ "called `map(<f>).unwrap_or_else(<g>)` on an `Option` value. This can be done more directly by calling \
`map_or_else(g, f)` instead" `map_or_else(<g>, <f>)` instead"
} else { } else {
"called `map(f).unwrap_or_else(g)` on a `Result` value. This can be done more directly by calling \ "called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling \
`.map_or_else(g, f)` instead" `.map_or_else(<g>, <f>)` instead"
}; };
// get snippets for args to map() and unwrap_or_else() // get snippets for args to map() and unwrap_or_else()
let map_snippet = snippet(cx, map_args[1].span, ".."); 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
if is_option { if is_option {
let self_snippet = snippet(cx, map_or_args[0].span, ".."); let self_snippet = snippet(cx, map_or_args[0].span, "..");
let func_snippet = snippet(cx, map_or_args[2].span, ".."); let func_snippet = snippet(cx, map_or_args[2].span, "..");
let msg = "called `map_or(None, f)` on an `Option` value. This can be done more directly by calling \ let msg = "called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling \
`and_then(f)` instead"; `and_then(..)` instead";
( (
OPTION_MAP_OR_NONE, OPTION_MAP_OR_NONE,
msg, msg,
@ -2848,8 +2848,8 @@ fn lint_map_or_none<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, map
fn lint_filter_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, filter_args: &'tcx [hir::Expr<'_>]) { fn lint_filter_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, filter_args: &'tcx [hir::Expr<'_>]) {
// lint if caller of `.filter().next()` is an Iterator // lint if caller of `.filter().next()` is an Iterator
if match_trait_method(cx, expr, &paths::ITERATOR) { if match_trait_method(cx, expr, &paths::ITERATOR) {
let msg = "called `filter(p).next()` on an `Iterator`. This is more succinctly expressed by calling \ let msg = "called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling \
`.find(p)` instead."; `.find(..)` instead.";
let filter_snippet = snippet(cx, filter_args[1].span, ".."); let filter_snippet = snippet(cx, filter_args[1].span, "..");
if filter_snippet.lines().count() <= 1 { if filter_snippet.lines().count() <= 1 {
// add note if not multi-line // add note if not multi-line
@ -2879,9 +2879,9 @@ fn lint_skip_while_next<'tcx>(
cx, cx,
SKIP_WHILE_NEXT, SKIP_WHILE_NEXT,
expr.span, expr.span,
"called `skip_while(p).next()` on an `Iterator`", "called `skip_while(<p>).next()` on an `Iterator`",
None, None,
"this is more succinctly expressed by calling `.find(!p)` instead", "this is more succinctly expressed by calling `.find(!<p>)` instead",
); );
} }
} }
@ -2895,7 +2895,7 @@ fn lint_filter_map<'tcx>(
) { ) {
// lint if caller of `.filter().map()` is an Iterator // lint if caller of `.filter().map()` is an Iterator
if match_trait_method(cx, expr, &paths::ITERATOR) { if match_trait_method(cx, expr, &paths::ITERATOR) {
let msg = "called `filter(p).map(q)` on an `Iterator`"; let msg = "called `filter(..).map(..)` on an `Iterator`";
let hint = "this is more succinctly expressed by calling `.filter_map(..)` instead"; let hint = "this is more succinctly expressed by calling `.filter_map(..)` instead";
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint); span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint);
} }
@ -2904,8 +2904,8 @@ fn lint_filter_map<'tcx>(
/// lint use of `filter_map().next()` for `Iterators` /// lint use of `filter_map().next()` for `Iterators`
fn lint_filter_map_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, filter_args: &'tcx [hir::Expr<'_>]) { fn lint_filter_map_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, filter_args: &'tcx [hir::Expr<'_>]) {
if match_trait_method(cx, expr, &paths::ITERATOR) { if match_trait_method(cx, expr, &paths::ITERATOR) {
let msg = "called `filter_map(p).next()` on an `Iterator`. This is more succinctly expressed by calling \ let msg = "called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling \
`.find_map(p)` instead."; `.find_map(..)` instead.";
let filter_snippet = snippet(cx, filter_args[1].span, ".."); let filter_snippet = snippet(cx, filter_args[1].span, "..");
if filter_snippet.lines().count() <= 1 { if filter_snippet.lines().count() <= 1 {
span_lint_and_note( span_lint_and_note(
@ -2931,7 +2931,7 @@ fn lint_find_map<'tcx>(
) { ) {
// lint if caller of `.filter().map()` is an Iterator // lint if caller of `.filter().map()` is an Iterator
if match_trait_method(cx, &map_args[0], &paths::ITERATOR) { if match_trait_method(cx, &map_args[0], &paths::ITERATOR) {
let msg = "called `find(p).map(q)` on an `Iterator`"; let msg = "called `find(..).map(..)` on an `Iterator`";
let hint = "this is more succinctly expressed by calling `.find_map(..)` instead"; let hint = "this is more succinctly expressed by calling `.find_map(..)` instead";
span_lint_and_help(cx, FIND_MAP, expr.span, msg, None, hint); span_lint_and_help(cx, FIND_MAP, expr.span, msg, None, hint);
} }
@ -2946,7 +2946,7 @@ fn lint_filter_map_map<'tcx>(
) { ) {
// lint if caller of `.filter().map()` is an Iterator // lint if caller of `.filter().map()` is an Iterator
if match_trait_method(cx, expr, &paths::ITERATOR) { if match_trait_method(cx, expr, &paths::ITERATOR) {
let msg = "called `filter_map(p).map(q)` on an `Iterator`"; let msg = "called `filter_map(..).map(..)` on an `Iterator`";
let hint = "this is more succinctly expressed by only calling `.filter_map(..)` instead"; let hint = "this is more succinctly expressed by only calling `.filter_map(..)` instead";
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint); span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint);
} }
@ -2961,7 +2961,7 @@ fn lint_filter_flat_map<'tcx>(
) { ) {
// lint if caller of `.filter().flat_map()` is an Iterator // lint if caller of `.filter().flat_map()` is an Iterator
if match_trait_method(cx, expr, &paths::ITERATOR) { if match_trait_method(cx, expr, &paths::ITERATOR) {
let msg = "called `filter(p).flat_map(q)` on an `Iterator`"; let msg = "called `filter(..).flat_map(..)` on an `Iterator`";
let hint = "this is more succinctly expressed by calling `.flat_map(..)` \ let hint = "this is more succinctly expressed by calling `.flat_map(..)` \
and filtering by returning `iter::empty()`"; and filtering by returning `iter::empty()`";
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint); span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint);
@ -2977,7 +2977,7 @@ fn lint_filter_map_flat_map<'tcx>(
) { ) {
// lint if caller of `.filter_map().flat_map()` is an Iterator // lint if caller of `.filter_map().flat_map()` is an Iterator
if match_trait_method(cx, expr, &paths::ITERATOR) { if match_trait_method(cx, expr, &paths::ITERATOR) {
let msg = "called `filter_map(p).flat_map(q)` on an `Iterator`"; let msg = "called `filter_map(..).flat_map(..)` on an `Iterator`";
let hint = "this is more succinctly expressed by calling `.flat_map(..)` \ let hint = "this is more succinctly expressed by calling `.flat_map(..)` \
and filtering by returning `iter::empty()`"; and filtering by returning `iter::empty()`";
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint); span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint);
@ -3148,9 +3148,9 @@ fn lint_chars_cmp(
"like this", "like this",
format!("{}{}.{}({})", format!("{}{}.{}({})",
if info.eq { "" } else { "!" }, if info.eq { "" } else { "!" },
snippet_with_applicability(cx, args[0][0].span, "_", &mut applicability), snippet_with_applicability(cx, args[0][0].span, "..", &mut applicability),
suggest, suggest,
snippet_with_applicability(cx, arg_char[0].span, "_", &mut applicability)), snippet_with_applicability(cx, arg_char[0].span, "..", &mut applicability)),
applicability, applicability,
); );
@ -3197,7 +3197,7 @@ fn lint_chars_cmp_with_unwrap<'tcx>(
"like this", "like this",
format!("{}{}.{}('{}')", format!("{}{}.{}('{}')",
if info.eq { "" } else { "!" }, if info.eq { "" } else { "!" },
snippet_with_applicability(cx, args[0][0].span, "_", &mut applicability), snippet_with_applicability(cx, args[0][0].span, "..", &mut applicability),
suggest, suggest,
c), c),
applicability, applicability,
@ -3272,7 +3272,7 @@ fn lint_single_char_pattern(cx: &LateContext<'_>, _expr: &hir::Expr<'_>, arg: &h
fn lint_single_char_push_string(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { fn lint_single_char_push_string(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) {
let mut applicability = Applicability::MachineApplicable; let mut applicability = Applicability::MachineApplicable;
if let Some(extension_string) = get_hint_if_single_char_arg(cx, &args[1], &mut applicability) { if let Some(extension_string) = get_hint_if_single_char_arg(cx, &args[1], &mut applicability) {
let base_string_snippet = snippet_with_applicability(cx, args[0].span, "_", &mut applicability); let base_string_snippet = snippet_with_applicability(cx, args[0].span, "..", &mut applicability);
let sugg = format!("{}.push({})", base_string_snippet, extension_string); let sugg = format!("{}.push({})", base_string_snippet, extension_string);
span_lint_and_sugg( span_lint_and_sugg(
cx, cx,
@ -3315,7 +3315,7 @@ fn lint_asref(cx: &LateContext<'_>, expr: &hir::Expr<'_>, call_name: &str, as_re
expr.span, expr.span,
&format!("this call to `{}` does nothing", call_name), &format!("this call to `{}` does nothing", call_name),
"try this", "try this",
snippet_with_applicability(cx, recvr.span, "_", &mut applicability).to_string(), snippet_with_applicability(cx, recvr.span, "..", &mut applicability).to_string(),
applicability, applicability,
); );
} }

View file

@ -53,15 +53,15 @@ pub(super) fn lint<'tcx>(
// lint message // lint message
// comparing the snippet from source to raw text ("None") below is safe // comparing the snippet from source to raw text ("None") below is safe
// because we already have checked the type. // because we already have checked the type.
let arg = if unwrap_snippet == "None" { "None" } else { "a" }; let arg = if unwrap_snippet == "None" { "None" } else { "<a>" };
let unwrap_snippet_none = unwrap_snippet == "None"; let unwrap_snippet_none = unwrap_snippet == "None";
let suggest = if unwrap_snippet_none { let suggest = if unwrap_snippet_none {
"and_then(f)" "and_then(<f>)"
} else { } else {
"map_or(a, f)" "map_or(<a>, <f>)"
}; };
let msg = &format!( let msg = &format!(
"called `map(f).unwrap_or({})` on an `Option` value. \ "called `map(<f>).unwrap_or({})` on an `Option` value. \
This can be done more directly by calling `{}` instead", This can be done more directly by calling `{}` instead",
arg, suggest arg, suggest
); );

View file

@ -1,4 +1,4 @@
error: called `filter_map(p).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(p)` instead. error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead.
--> $DIR/filter_map_next.rs:6:32 --> $DIR/filter_map_next.rs:6:32
| |
LL | let element: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next(); 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
= note: `-D clippy::filter-map-next` implied by `-D warnings` = note: `-D clippy::filter-map-next` implied by `-D warnings`
= note: replace `filter_map(|s| s.parse().ok()).next()` with `find_map(|s| s.parse().ok())` = note: replace `filter_map(|s| s.parse().ok()).next()` with `find_map(|s| s.parse().ok())`
error: called `filter_map(p).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(p)` instead. error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead.
--> $DIR/filter_map_next.rs:10:26 --> $DIR/filter_map_next.rs:10:26
| |
LL | let _: Option<u32> = vec![1, 2, 3, 4, 5, 6] LL | let _: Option<u32> = vec![1, 2, 3, 4, 5, 6]

View file

@ -1,4 +1,4 @@
error: called `filter(p).map(q)` on an `Iterator` error: called `filter(..).map(..)` on an `Iterator`
--> $DIR/filter_methods.rs:5:21 --> $DIR/filter_methods.rs:5:21
| |
LL | let _: Vec<_> = vec![5; 6].into_iter().filter(|&x| x == 0).map(|x| x * 2).collect(); 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 *
= note: `-D clippy::filter-map` implied by `-D warnings` = note: `-D clippy::filter-map` implied by `-D warnings`
= help: this is more succinctly expressed by calling `.filter_map(..)` instead = help: this is more succinctly expressed by calling `.filter_map(..)` instead
error: called `filter(p).flat_map(q)` on an `Iterator` error: called `filter(..).flat_map(..)` on an `Iterator`
--> $DIR/filter_methods.rs:7:21 --> $DIR/filter_methods.rs:7:21
| |
LL | let _: Vec<_> = vec![5_i8; 6] LL | let _: Vec<_> = vec![5_i8; 6]
@ -19,7 +19,7 @@ LL | | .flat_map(|x| x.checked_mul(2))
| |
= help: this is more succinctly expressed by calling `.flat_map(..)` and filtering by returning `iter::empty()` = help: this is more succinctly expressed by calling `.flat_map(..)` and filtering by returning `iter::empty()`
error: called `filter_map(p).flat_map(q)` on an `Iterator` error: called `filter_map(..).flat_map(..)` on an `Iterator`
--> $DIR/filter_methods.rs:13:21 --> $DIR/filter_methods.rs:13:21
| |
LL | let _: Vec<_> = vec![5_i8; 6] LL | let _: Vec<_> = vec![5_i8; 6]
@ -31,7 +31,7 @@ LL | | .flat_map(|x| x.checked_mul(2))
| |
= help: this is more succinctly expressed by calling `.flat_map(..)` and filtering by returning `iter::empty()` = help: this is more succinctly expressed by calling `.flat_map(..)` and filtering by returning `iter::empty()`
error: called `filter_map(p).map(q)` on an `Iterator` error: called `filter_map(..).map(..)` on an `Iterator`
--> $DIR/filter_methods.rs:19:21 --> $DIR/filter_methods.rs:19:21
| |
LL | let _: Vec<_> = vec![5_i8; 6] LL | let _: Vec<_> = vec![5_i8; 6]

View file

@ -1,4 +1,4 @@
error: called `find(p).map(q)` on an `Iterator` error: called `find(..).map(..)` on an `Iterator`
--> $DIR/find_map.rs:20:26 --> $DIR/find_map.rs:20:26
| |
LL | let _: Option<i32> = a.iter().find(|s| s.parse::<i32>().is_ok()).map(|s| s.parse().unwrap()); 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
= note: `-D clippy::find-map` implied by `-D warnings` = note: `-D clippy::find-map` implied by `-D warnings`
= help: this is more succinctly expressed by calling `.find_map(..)` instead = help: this is more succinctly expressed by calling `.find_map(..)` instead
error: called `find(p).map(q)` on an `Iterator` error: called `find(..).map(..)` on an `Iterator`
--> $DIR/find_map.rs:23:29 --> $DIR/find_map.rs:23:29
| |
LL | let _: Option<Flavor> = desserts_of_the_week LL | let _: Option<Flavor> = desserts_of_the_week

View file

@ -1,4 +1,4 @@
error: called `skip(x).next()` on an iterator error: called `skip(..).next()` on an iterator
--> $DIR/iter_skip_next.rs:15:28 --> $DIR/iter_skip_next.rs:15:28
| |
LL | let _ = some_vec.iter().skip(42).next(); LL | let _ = some_vec.iter().skip(42).next();
@ -6,19 +6,19 @@ LL | let _ = some_vec.iter().skip(42).next();
| |
= note: `-D clippy::iter-skip-next` implied by `-D warnings` = note: `-D clippy::iter-skip-next` implied by `-D warnings`
error: called `skip(x).next()` on an iterator error: called `skip(..).next()` on an iterator
--> $DIR/iter_skip_next.rs:16:36 --> $DIR/iter_skip_next.rs:16:36
| |
LL | let _ = some_vec.iter().cycle().skip(42).next(); LL | let _ = some_vec.iter().cycle().skip(42).next();
| ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(42)` | ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(42)`
error: called `skip(x).next()` on an iterator error: called `skip(..).next()` on an iterator
--> $DIR/iter_skip_next.rs:17:20 --> $DIR/iter_skip_next.rs:17:20
| |
LL | let _ = (1..10).skip(10).next(); LL | let _ = (1..10).skip(10).next();
| ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(10)` | ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(10)`
error: called `skip(x).next()` on an iterator error: called `skip(..).next()` on an iterator
--> $DIR/iter_skip_next.rs:18:33 --> $DIR/iter_skip_next.rs:18:33
| |
LL | let _ = &some_vec[..].iter().skip(3).next(); LL | let _ = &some_vec[..].iter().skip(3).next();

View file

@ -1,4 +1,4 @@
error: called `map(f).unwrap_or(a)` on an `Option` value. This can be done more directly by calling `map_or(a, f)` instead error: called `map(<f>).unwrap_or(<a>)` on an `Option` value. This can be done more directly by calling `map_or(<a>, <f>)` instead
--> $DIR/map_unwrap_or.rs:17:13 --> $DIR/map_unwrap_or.rs:17:13
| |
LL | let _ = opt.map(|x| x + 1) LL | let _ = opt.map(|x| x + 1)
@ -8,12 +8,12 @@ LL | | .unwrap_or(0);
| |_____________________^ | |_____________________^
| |
= note: `-D clippy::map-unwrap-or` implied by `-D warnings` = note: `-D clippy::map-unwrap-or` implied by `-D warnings`
help: use `map_or(a, f)` instead help: use `map_or(<a>, <f>)` instead
| |
LL | let _ = opt.map_or(0, |x| x + 1); LL | let _ = opt.map_or(0, |x| x + 1);
| ^^^^^^ ^^ -- | ^^^^^^ ^^ --
error: called `map(f).unwrap_or(a)` on an `Option` value. This can be done more directly by calling `map_or(a, f)` instead error: called `map(<f>).unwrap_or(<a>)` on an `Option` value. This can be done more directly by calling `map_or(<a>, <f>)` instead
--> $DIR/map_unwrap_or.rs:21:13 --> $DIR/map_unwrap_or.rs:21:13
| |
LL | let _ = opt.map(|x| { LL | let _ = opt.map(|x| {
@ -23,7 +23,7 @@ LL | | }
LL | | ).unwrap_or(0); LL | | ).unwrap_or(0);
| |__________________^ | |__________________^
| |
help: use `map_or(a, f)` instead help: use `map_or(<a>, <f>)` instead
| |
LL | let _ = opt.map_or(0, |x| { LL | let _ = opt.map_or(0, |x| {
LL | x + 1 LL | x + 1
@ -31,7 +31,7 @@ LL | }
LL | ); LL | );
| |
error: called `map(f).unwrap_or(a)` on an `Option` value. This can be done more directly by calling `map_or(a, f)` instead error: called `map(<f>).unwrap_or(<a>)` on an `Option` value. This can be done more directly by calling `map_or(<a>, <f>)` instead
--> $DIR/map_unwrap_or.rs:25:13 --> $DIR/map_unwrap_or.rs:25:13
| |
LL | let _ = opt.map(|x| x + 1) LL | let _ = opt.map(|x| x + 1)
@ -41,25 +41,25 @@ LL | | 0
LL | | }); LL | | });
| |__________^ | |__________^
| |
help: use `map_or(a, f)` instead help: use `map_or(<a>, <f>)` instead
| |
LL | let _ = opt.map_or({ LL | let _ = opt.map_or({
LL | 0 LL | 0
LL | }, |x| x + 1); LL | }, |x| x + 1);
| |
error: called `map(f).unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then(f)` instead error: called `map(<f>).unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then(<f>)` instead
--> $DIR/map_unwrap_or.rs:30:13 --> $DIR/map_unwrap_or.rs:30:13
| |
LL | let _ = opt.map(|x| Some(x + 1)).unwrap_or(None); LL | let _ = opt.map(|x| Some(x + 1)).unwrap_or(None);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
help: use `and_then(f)` instead help: use `and_then(<f>)` instead
| |
LL | let _ = opt.and_then(|x| Some(x + 1)); LL | let _ = opt.and_then(|x| Some(x + 1));
| ^^^^^^^^ -- | ^^^^^^^^ --
error: called `map(f).unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then(f)` instead error: called `map(<f>).unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then(<f>)` instead
--> $DIR/map_unwrap_or.rs:32:13 --> $DIR/map_unwrap_or.rs:32:13
| |
LL | let _ = opt.map(|x| { LL | let _ = opt.map(|x| {
@ -69,7 +69,7 @@ LL | | }
LL | | ).unwrap_or(None); LL | | ).unwrap_or(None);
| |_____________________^ | |_____________________^
| |
help: use `and_then(f)` instead help: use `and_then(<f>)` instead
| |
LL | let _ = opt.and_then(|x| { LL | let _ = opt.and_then(|x| {
LL | Some(x + 1) LL | Some(x + 1)
@ -77,7 +77,7 @@ LL | }
LL | ); LL | );
| |
error: called `map(f).unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then(f)` instead error: called `map(<f>).unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then(<f>)` instead
--> $DIR/map_unwrap_or.rs:36:13 --> $DIR/map_unwrap_or.rs:36:13
| |
LL | let _ = opt LL | let _ = opt
@ -86,23 +86,23 @@ LL | | .map(|x| Some(x + 1))
LL | | .unwrap_or(None); LL | | .unwrap_or(None);
| |________________________^ | |________________________^
| |
help: use `and_then(f)` instead help: use `and_then(<f>)` instead
| |
LL | .and_then(|x| Some(x + 1)); LL | .and_then(|x| Some(x + 1));
| ^^^^^^^^ -- | ^^^^^^^^ --
error: called `map(f).unwrap_or(a)` on an `Option` value. This can be done more directly by calling `map_or(a, f)` instead error: called `map(<f>).unwrap_or(<a>)` on an `Option` value. This can be done more directly by calling `map_or(<a>, <f>)` instead
--> $DIR/map_unwrap_or.rs:47:13 --> $DIR/map_unwrap_or.rs:47:13
| |
LL | let _ = Some("prefix").map(|p| format!("{}.", p)).unwrap_or(id); LL | let _ = Some("prefix").map(|p| format!("{}.", p)).unwrap_or(id);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
help: use `map_or(a, f)` instead help: use `map_or(<a>, <f>)` instead
| |
LL | let _ = Some("prefix").map_or(id, |p| format!("{}.", p)); LL | let _ = Some("prefix").map_or(id, |p| format!("{}.", p));
| ^^^^^^ ^^^ -- | ^^^^^^ ^^^ --
error: called `map(f).unwrap_or_else(g)` on an `Option` value. This can be done more directly by calling `map_or_else(g, f)` instead error: called `map(<f>).unwrap_or_else(<g>)` on an `Option` value. This can be done more directly by calling `map_or_else(<g>, <f>)` instead
--> $DIR/map_unwrap_or.rs:51:13 --> $DIR/map_unwrap_or.rs:51:13
| |
LL | let _ = opt.map(|x| x + 1) LL | let _ = opt.map(|x| x + 1)
@ -113,7 +113,7 @@ LL | | .unwrap_or_else(|| 0);
| |
= note: replace `map(|x| x + 1).unwrap_or_else(|| 0)` with `map_or_else(|| 0, |x| x + 1)` = note: replace `map(|x| x + 1).unwrap_or_else(|| 0)` with `map_or_else(|| 0, |x| x + 1)`
error: called `map(f).unwrap_or_else(g)` on an `Option` value. This can be done more directly by calling `map_or_else(g, f)` instead error: called `map(<f>).unwrap_or_else(<g>)` on an `Option` value. This can be done more directly by calling `map_or_else(<g>, <f>)` instead
--> $DIR/map_unwrap_or.rs:55:13 --> $DIR/map_unwrap_or.rs:55:13
| |
LL | let _ = opt.map(|x| { LL | let _ = opt.map(|x| {
@ -123,7 +123,7 @@ LL | | }
LL | | ).unwrap_or_else(|| 0); LL | | ).unwrap_or_else(|| 0);
| |__________________________^ | |__________________________^
error: called `map(f).unwrap_or_else(g)` on an `Option` value. This can be done more directly by calling `map_or_else(g, f)` instead error: called `map(<f>).unwrap_or_else(<g>)` on an `Option` value. This can be done more directly by calling `map_or_else(<g>, <f>)` instead
--> $DIR/map_unwrap_or.rs:59:13 --> $DIR/map_unwrap_or.rs:59:13
| |
LL | let _ = opt.map(|x| x + 1) LL | let _ = opt.map(|x| x + 1)
@ -133,7 +133,7 @@ LL | | 0
LL | | ); LL | | );
| |_________^ | |_________^
error: called `map(f).unwrap_or_else(g)` on a `Result` value. This can be done more directly by calling `.map_or_else(g, f)` instead error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling `.map_or_else(<g>, <f>)` instead
--> $DIR/map_unwrap_or.rs:88:13 --> $DIR/map_unwrap_or.rs:88:13
| |
LL | let _ = res.map(|x| x + 1).unwrap_or_else(|e| 0); // should lint even though this call is on a separate line LL | let _ = res.map(|x| x + 1).unwrap_or_else(|e| 0); // should lint even though this call is on a separate line
@ -141,7 +141,7 @@ LL | let _ = res.map(|x| x + 1).unwrap_or_else(|e| 0); // should lint even t
| |
= note: replace `map(|x| x + 1).unwrap_or_else(|e| 0)` with `map_or_else(|e| 0, |x| x + 1)` = note: replace `map(|x| x + 1).unwrap_or_else(|e| 0)` with `map_or_else(|e| 0, |x| x + 1)`
error: called `map(f).unwrap_or_else(g)` on a `Result` value. This can be done more directly by calling `.map_or_else(g, f)` instead error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling `.map_or_else(<g>, <f>)` instead
--> $DIR/map_unwrap_or.rs:90:13 --> $DIR/map_unwrap_or.rs:90:13
| |
LL | let _ = res.map(|x| x + 1).unwrap_or_else(|e| 0); LL | let _ = res.map(|x| x + 1).unwrap_or_else(|e| 0);
@ -149,7 +149,7 @@ LL | let _ = res.map(|x| x + 1).unwrap_or_else(|e| 0);
| |
= note: replace `map(|x| x + 1).unwrap_or_else(|e| 0)` with `map_or_else(|e| 0, |x| x + 1)` = note: replace `map(|x| x + 1).unwrap_or_else(|e| 0)` with `map_or_else(|e| 0, |x| x + 1)`
error: called `map(f).unwrap_or_else(g)` on a `Result` value. This can be done more directly by calling `.map_or_else(g, f)` instead error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling `.map_or_else(<g>, <f>)` instead
--> $DIR/map_unwrap_or.rs:91:13 --> $DIR/map_unwrap_or.rs:91:13
| |
LL | let _ = res.map(|x| x + 1).unwrap_or_else(|e| 0); LL | let _ = res.map(|x| x + 1).unwrap_or_else(|e| 0);

View file

@ -8,7 +8,7 @@ LL | | }
| |
= note: `-D clippy::new-ret-no-self` implied by `-D warnings` = note: `-D clippy::new-ret-no-self` implied by `-D warnings`
error: called `filter(p).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(p)` instead. error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead.
--> $DIR/methods.rs:126:13 --> $DIR/methods.rs:126:13
| |
LL | let _ = v.iter().filter(|&x| *x < 0).next(); LL | let _ = v.iter().filter(|&x| *x < 0).next();
@ -17,7 +17,7 @@ LL | let _ = v.iter().filter(|&x| *x < 0).next();
= note: `-D clippy::filter-next` implied by `-D warnings` = note: `-D clippy::filter-next` implied by `-D warnings`
= note: replace `filter(|&x| *x < 0).next()` with `find(|&x| *x < 0)` = note: replace `filter(|&x| *x < 0).next()` with `find(|&x| *x < 0)`
error: called `filter(p).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(p)` instead. error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead.
--> $DIR/methods.rs:129:13 --> $DIR/methods.rs:129:13
| |
LL | let _ = v.iter().filter(|&x| { LL | let _ = v.iter().filter(|&x| {

View file

@ -1,4 +1,4 @@
error: called `map_or(None, f)` on an `Option` value. This can be done more directly by calling `and_then(f)` instead error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `and_then(..)` instead
--> $DIR/option_map_or_none.rs:10:13 --> $DIR/option_map_or_none.rs:10:13
| |
LL | let _ = opt.map_or(None, |x| Some(x + 1)); LL | let _ = opt.map_or(None, |x| Some(x + 1));
@ -6,7 +6,7 @@ LL | let _ = opt.map_or(None, |x| Some(x + 1));
| |
= note: `-D clippy::option-map-or-none` implied by `-D warnings` = note: `-D clippy::option-map-or-none` implied by `-D warnings`
error: called `map_or(None, f)` on an `Option` value. This can be done more directly by calling `and_then(f)` instead error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `and_then(..)` instead
--> $DIR/option_map_or_none.rs:13:13 --> $DIR/option_map_or_none.rs:13:13
| |
LL | let _ = opt.map_or(None, |x| { LL | let _ = opt.map_or(None, |x| {

View file

@ -1,13 +1,13 @@
error: called `skip_while(p).next()` on an `Iterator` error: called `skip_while(<p>).next()` on an `Iterator`
--> $DIR/skip_while_next.rs:14:13 --> $DIR/skip_while_next.rs:14:13
| |
LL | let _ = v.iter().skip_while(|&x| *x < 0).next(); LL | let _ = v.iter().skip_while(|&x| *x < 0).next();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
= note: `-D clippy::skip-while-next` implied by `-D warnings` = note: `-D clippy::skip-while-next` implied by `-D warnings`
= help: this is more succinctly expressed by calling `.find(!p)` instead = help: this is more succinctly expressed by calling `.find(!<p>)` instead
error: called `skip_while(p).next()` on an `Iterator` error: called `skip_while(<p>).next()` on an `Iterator`
--> $DIR/skip_while_next.rs:17:13 --> $DIR/skip_while_next.rs:17:13
| |
LL | let _ = v.iter().skip_while(|&x| { LL | let _ = v.iter().skip_while(|&x| {
@ -17,7 +17,7 @@ LL | | }
LL | | ).next(); LL | | ).next();
| |___________________________^ | |___________________________^
| |
= help: this is more succinctly expressed by calling `.find(!p)` instead = help: this is more succinctly expressed by calling `.find(!<p>)` instead
error: aborting due to 2 previous errors error: aborting due to 2 previous errors