Improve error messages format
This commit is contained in:
parent
840e227bb6
commit
6c84b96886
@ -44,11 +44,9 @@ pub(super) fn check<'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"
|
||||||
`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"
|
||||||
`.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_arg.span, "..");
|
let map_snippet = snippet(cx, map_arg.span, "..");
|
||||||
|
@ -99,10 +99,7 @@ pub(super) fn check(
|
|||||||
let hint = format!("{}.{method_hint}()", snippet(cx, as_ref_recv.span, ".."));
|
let hint = format!("{}.{method_hint}()", snippet(cx, as_ref_recv.span, ".."));
|
||||||
let suggestion = format!("try using {method_hint} instead");
|
let suggestion = format!("try using {method_hint} instead");
|
||||||
|
|
||||||
let msg = format!(
|
let msg = format!("called `{current_method}` on an `Option` value");
|
||||||
"called `{current_method}` on an Option value. This can be done more directly \
|
|
||||||
by calling `{hint}` instead"
|
|
||||||
);
|
|
||||||
span_lint_and_sugg(
|
span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
OPTION_AS_REF_DEREF,
|
OPTION_AS_REF_DEREF,
|
||||||
|
@ -66,8 +66,7 @@ pub(super) fn check<'tcx>(
|
|||||||
&& Some(id) == cx.tcx.lang_items().option_some_variant()
|
&& Some(id) == cx.tcx.lang_items().option_some_variant()
|
||||||
{
|
{
|
||||||
let func_snippet = snippet(cx, arg_char.span, "..");
|
let func_snippet = snippet(cx, arg_char.span, "..");
|
||||||
let msg = "called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling \
|
let msg = "called `map_or(None, ..)` on an `Option` value";
|
||||||
`map(..)` instead";
|
|
||||||
return span_lint_and_sugg(
|
return span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
OPTION_MAP_OR_NONE,
|
OPTION_MAP_OR_NONE,
|
||||||
@ -80,8 +79,7 @@ pub(super) fn check<'tcx>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let func_snippet = snippet(cx, map_arg.span, "..");
|
let func_snippet = snippet(cx, map_arg.span, "..");
|
||||||
let msg = "called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling \
|
let msg = "called `map_or(None, ..)` on an `Option` value";
|
||||||
`and_then(..)` instead";
|
|
||||||
span_lint_and_sugg(
|
span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
OPTION_MAP_OR_NONE,
|
OPTION_MAP_OR_NONE,
|
||||||
@ -92,8 +90,7 @@ pub(super) fn check<'tcx>(
|
|||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
} else if f_arg_is_some {
|
} else if f_arg_is_some {
|
||||||
let msg = "called `map_or(None, Some)` on a `Result` value. This can be done more directly by calling \
|
let msg = "called `map_or(None, Some)` on a `Result` value";
|
||||||
`ok()` instead";
|
|
||||||
let self_snippet = snippet(cx, recv.span, "..");
|
let self_snippet = snippet(cx, recv.span, "..");
|
||||||
span_lint_and_sugg(
|
span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
|
@ -97,10 +97,7 @@ pub(super) fn check<'tcx>(
|
|||||||
} else {
|
} else {
|
||||||
"map_or(<a>, <f>)"
|
"map_or(<a>, <f>)"
|
||||||
};
|
};
|
||||||
let msg = &format!(
|
let msg = &format!("called `map(<f>).unwrap_or({arg})` on an `Option` value");
|
||||||
"called `map(<f>).unwrap_or({arg})` on an `Option` value. \
|
|
||||||
This can be done more directly by calling `{suggest}` instead"
|
|
||||||
);
|
|
||||||
|
|
||||||
span_lint_and_then(cx, MAP_UNWRAP_OR, expr.span, msg, |diag| {
|
span_lint_and_then(cx, MAP_UNWRAP_OR, expr.span, msg, |diag| {
|
||||||
let map_arg_span = map_arg.span;
|
let map_arg_span = map_arg.span;
|
||||||
|
@ -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
|
||||||
--> $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)
|
||||||
@ -15,7 +15,7 @@ LL - let _ = opt.map(|x| x + 1)
|
|||||||
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
|
||||||
--> $DIR/map_unwrap_or.rs:21:13
|
--> $DIR/map_unwrap_or.rs:21:13
|
||||||
|
|
|
|
||||||
LL | let _ = opt.map(|x| {
|
LL | let _ = opt.map(|x| {
|
||||||
@ -33,7 +33,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
|
||||||
--> $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)
|
||||||
@ -50,7 +50,7 @@ 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
|
||||||
--> $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);
|
||||||
@ -62,7 +62,7 @@ LL - let _ = opt.map(|x| Some(x + 1)).unwrap_or(None);
|
|||||||
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
|
||||||
--> $DIR/map_unwrap_or.rs:32:13
|
--> $DIR/map_unwrap_or.rs:32:13
|
||||||
|
|
|
|
||||||
LL | let _ = opt.map(|x| {
|
LL | let _ = opt.map(|x| {
|
||||||
@ -80,7 +80,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
|
||||||
--> $DIR/map_unwrap_or.rs:36:13
|
--> $DIR/map_unwrap_or.rs:36:13
|
||||||
|
|
|
|
||||||
LL | let _ = opt
|
LL | let _ = opt
|
||||||
@ -95,7 +95,7 @@ LL - .map(|x| Some(x + 1))
|
|||||||
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
|
||||||
--> $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);
|
||||||
@ -107,7 +107,7 @@ LL - let _ = Some("prefix").map(|p| format!("{}.", p)).unwrap_or(id);
|
|||||||
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
|
||||||
--> $DIR/map_unwrap_or.rs:51:13
|
--> $DIR/map_unwrap_or.rs:51:13
|
||||||
|
|
|
|
||||||
LL | let _ = opt.map(|x| {
|
LL | let _ = opt.map(|x| {
|
||||||
@ -117,7 +117,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
|
||||||
--> $DIR/map_unwrap_or.rs:55:13
|
--> $DIR/map_unwrap_or.rs:55:13
|
||||||
|
|
|
|
||||||
LL | let _ = opt.map(|x| x + 1)
|
LL | let _ = opt.map(|x| x + 1)
|
||||||
@ -127,7 +127,7 @@ LL | | 0
|
|||||||
LL | | );
|
LL | | );
|
||||||
| |_________^
|
| |_________^
|
||||||
|
|
||||||
error: called `map(<f>).unwrap_or(false)` on an `Option` value. This can be done more directly by calling `is_some_and(<f>)` instead
|
error: called `map(<f>).unwrap_or(false)` on an `Option` value
|
||||||
--> $DIR/map_unwrap_or.rs:61:13
|
--> $DIR/map_unwrap_or.rs:61:13
|
||||||
|
|
|
|
||||||
LL | let _ = opt.map(|x| x > 5).unwrap_or(false);
|
LL | let _ = opt.map(|x| x > 5).unwrap_or(false);
|
||||||
@ -139,7 +139,7 @@ LL - let _ = opt.map(|x| x > 5).unwrap_or(false);
|
|||||||
LL + let _ = opt.is_some_and(|x| x > 5);
|
LL + let _ = opt.is_some_and(|x| x > 5);
|
||||||
|
|
|
|
||||||
|
|
||||||
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
|
||||||
--> $DIR/map_unwrap_or.rs:71:13
|
--> $DIR/map_unwrap_or.rs:71:13
|
||||||
|
|
|
|
||||||
LL | let _ = res.map(|x| {
|
LL | let _ = res.map(|x| {
|
||||||
@ -149,7 +149,7 @@ LL | | }
|
|||||||
LL | | ).unwrap_or_else(|_e| 0);
|
LL | | ).unwrap_or_else(|_e| 0);
|
||||||
| |____________________________^
|
| |____________________________^
|
||||||
|
|
||||||
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
|
||||||
--> $DIR/map_unwrap_or.rs:75:13
|
--> $DIR/map_unwrap_or.rs:75:13
|
||||||
|
|
|
|
||||||
LL | let _ = res.map(|x| x + 1)
|
LL | let _ = res.map(|x| x + 1)
|
||||||
@ -159,13 +159,13 @@ 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
|
||||||
--> $DIR/map_unwrap_or.rs:99:13
|
--> $DIR/map_unwrap_or.rs:99: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);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `res.map_or_else(|_e| 0, |x| x + 1)`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `res.map_or_else(|_e| 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
|
||||||
--> $DIR/map_unwrap_or.rs:106:13
|
--> $DIR/map_unwrap_or.rs:106:13
|
||||||
|
|
|
|
||||||
LL | let _ = opt.map(|x| x > 5).unwrap_or(false);
|
LL | let _ = opt.map(|x| x > 5).unwrap_or(false);
|
||||||
@ -177,7 +177,7 @@ LL - let _ = opt.map(|x| x > 5).unwrap_or(false);
|
|||||||
LL + let _ = opt.map_or(false, |x| x > 5);
|
LL + let _ = opt.map_or(false, |x| x > 5);
|
||||||
|
|
|
|
||||||
|
|
||||||
error: called `map(<f>).unwrap_or(false)` on an `Option` value. This can be done more directly by calling `is_some_and(<f>)` instead
|
error: called `map(<f>).unwrap_or(false)` on an `Option` value
|
||||||
--> $DIR/map_unwrap_or.rs:113:13
|
--> $DIR/map_unwrap_or.rs:113:13
|
||||||
|
|
|
|
||||||
LL | let _ = opt.map(|x| x > 5).unwrap_or(false);
|
LL | let _ = opt.map(|x| x > 5).unwrap_or(false);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
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
|
||||||
--> $DIR/map_unwrap_or_fixable.rs:16:13
|
--> $DIR/map_unwrap_or_fixable.rs:16:13
|
||||||
|
|
|
|
||||||
LL | let _ = opt.map(|x| x + 1)
|
LL | let _ = opt.map(|x| x + 1)
|
||||||
@ -10,7 +10,7 @@ LL | | .unwrap_or_else(|| 0);
|
|||||||
= note: `-D clippy::map-unwrap-or` implied by `-D warnings`
|
= note: `-D clippy::map-unwrap-or` implied by `-D warnings`
|
||||||
= help: to override `-D warnings` add `#[allow(clippy::map_unwrap_or)]`
|
= help: to override `-D warnings` add `#[allow(clippy::map_unwrap_or)]`
|
||||||
|
|
||||||
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
|
||||||
--> $DIR/map_unwrap_or_fixable.rs:46:13
|
--> $DIR/map_unwrap_or_fixable.rs:46:13
|
||||||
|
|
|
|
||||||
LL | let _ = res.map(|x| x + 1)
|
LL | let _ = res.map(|x| x + 1)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
error: called `.as_ref().map(Deref::deref)` on an Option value. This can be done more directly by calling `opt.clone().as_deref()` instead
|
error: called `.as_ref().map(Deref::deref)` on an `Option` value
|
||||||
--> $DIR/option_as_ref_deref.rs:11:13
|
--> $DIR/option_as_ref_deref.rs:11:13
|
||||||
|
|
|
|
||||||
LL | let _ = opt.clone().as_ref().map(Deref::deref).map(str::len);
|
LL | let _ = opt.clone().as_ref().map(Deref::deref).map(str::len);
|
||||||
@ -7,7 +7,7 @@ LL | let _ = opt.clone().as_ref().map(Deref::deref).map(str::len);
|
|||||||
= note: `-D clippy::option-as-ref-deref` implied by `-D warnings`
|
= note: `-D clippy::option-as-ref-deref` implied by `-D warnings`
|
||||||
= help: to override `-D warnings` add `#[allow(clippy::option_as_ref_deref)]`
|
= help: to override `-D warnings` add `#[allow(clippy::option_as_ref_deref)]`
|
||||||
|
|
||||||
error: called `.as_ref().map(Deref::deref)` on an Option value. This can be done more directly by calling `opt.clone().as_deref()` instead
|
error: called `.as_ref().map(Deref::deref)` on an `Option` value
|
||||||
--> $DIR/option_as_ref_deref.rs:14:13
|
--> $DIR/option_as_ref_deref.rs:14:13
|
||||||
|
|
|
|
||||||
LL | let _ = opt.clone()
|
LL | let _ = opt.clone()
|
||||||
@ -17,97 +17,97 @@ LL | | Deref::deref
|
|||||||
LL | | )
|
LL | | )
|
||||||
| |_________^ help: try using as_deref instead: `opt.clone().as_deref()`
|
| |_________^ help: try using as_deref instead: `opt.clone().as_deref()`
|
||||||
|
|
||||||
error: called `.as_mut().map(DerefMut::deref_mut)` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead
|
error: called `.as_mut().map(DerefMut::deref_mut)` on an `Option` value
|
||||||
--> $DIR/option_as_ref_deref.rs:20:13
|
--> $DIR/option_as_ref_deref.rs:20:13
|
||||||
|
|
|
|
||||||
LL | let _ = opt.as_mut().map(DerefMut::deref_mut);
|
LL | let _ = opt.as_mut().map(DerefMut::deref_mut);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()`
|
||||||
|
|
||||||
error: called `.as_ref().map(String::as_str)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
|
error: called `.as_ref().map(String::as_str)` on an `Option` value
|
||||||
--> $DIR/option_as_ref_deref.rs:22:13
|
--> $DIR/option_as_ref_deref.rs:22:13
|
||||||
|
|
|
|
||||||
LL | let _ = opt.as_ref().map(String::as_str);
|
LL | let _ = opt.as_ref().map(String::as_str);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
|
||||||
|
|
||||||
error: called `.as_ref().map(|x| x.as_str())` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
|
error: called `.as_ref().map(|x| x.as_str())` on an `Option` value
|
||||||
--> $DIR/option_as_ref_deref.rs:23:13
|
--> $DIR/option_as_ref_deref.rs:23:13
|
||||||
|
|
|
|
||||||
LL | let _ = opt.as_ref().map(|x| x.as_str());
|
LL | let _ = opt.as_ref().map(|x| x.as_str());
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
|
||||||
|
|
||||||
error: called `.as_mut().map(String::as_mut_str)` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead
|
error: called `.as_mut().map(String::as_mut_str)` on an `Option` value
|
||||||
--> $DIR/option_as_ref_deref.rs:24:13
|
--> $DIR/option_as_ref_deref.rs:24:13
|
||||||
|
|
|
|
||||||
LL | let _ = opt.as_mut().map(String::as_mut_str);
|
LL | let _ = opt.as_mut().map(String::as_mut_str);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()`
|
||||||
|
|
||||||
error: called `.as_mut().map(|x| x.as_mut_str())` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead
|
error: called `.as_mut().map(|x| x.as_mut_str())` on an `Option` value
|
||||||
--> $DIR/option_as_ref_deref.rs:25:13
|
--> $DIR/option_as_ref_deref.rs:25:13
|
||||||
|
|
|
|
||||||
LL | let _ = opt.as_mut().map(|x| x.as_mut_str());
|
LL | let _ = opt.as_mut().map(|x| x.as_mut_str());
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()`
|
||||||
|
|
||||||
error: called `.as_ref().map(CString::as_c_str)` on an Option value. This can be done more directly by calling `Some(CString::new(vec![]).unwrap()).as_deref()` instead
|
error: called `.as_ref().map(CString::as_c_str)` on an `Option` value
|
||||||
--> $DIR/option_as_ref_deref.rs:26:13
|
--> $DIR/option_as_ref_deref.rs:26:13
|
||||||
|
|
|
|
||||||
LL | let _ = Some(CString::new(vec![]).unwrap()).as_ref().map(CString::as_c_str);
|
LL | let _ = Some(CString::new(vec![]).unwrap()).as_ref().map(CString::as_c_str);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(CString::new(vec![]).unwrap()).as_deref()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(CString::new(vec![]).unwrap()).as_deref()`
|
||||||
|
|
||||||
error: called `.as_ref().map(OsString::as_os_str)` on an Option value. This can be done more directly by calling `Some(OsString::new()).as_deref()` instead
|
error: called `.as_ref().map(OsString::as_os_str)` on an `Option` value
|
||||||
--> $DIR/option_as_ref_deref.rs:27:13
|
--> $DIR/option_as_ref_deref.rs:27:13
|
||||||
|
|
|
|
||||||
LL | let _ = Some(OsString::new()).as_ref().map(OsString::as_os_str);
|
LL | let _ = Some(OsString::new()).as_ref().map(OsString::as_os_str);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(OsString::new()).as_deref()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(OsString::new()).as_deref()`
|
||||||
|
|
||||||
error: called `.as_ref().map(PathBuf::as_path)` on an Option value. This can be done more directly by calling `Some(PathBuf::new()).as_deref()` instead
|
error: called `.as_ref().map(PathBuf::as_path)` on an `Option` value
|
||||||
--> $DIR/option_as_ref_deref.rs:28:13
|
--> $DIR/option_as_ref_deref.rs:28:13
|
||||||
|
|
|
|
||||||
LL | let _ = Some(PathBuf::new()).as_ref().map(PathBuf::as_path);
|
LL | let _ = Some(PathBuf::new()).as_ref().map(PathBuf::as_path);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(PathBuf::new()).as_deref()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(PathBuf::new()).as_deref()`
|
||||||
|
|
||||||
error: called `.as_ref().map(Vec::as_slice)` on an Option value. This can be done more directly by calling `Some(Vec::<()>::new()).as_deref()` instead
|
error: called `.as_ref().map(Vec::as_slice)` on an `Option` value
|
||||||
--> $DIR/option_as_ref_deref.rs:29:13
|
--> $DIR/option_as_ref_deref.rs:29:13
|
||||||
|
|
|
|
||||||
LL | let _ = Some(Vec::<()>::new()).as_ref().map(Vec::as_slice);
|
LL | let _ = Some(Vec::<()>::new()).as_ref().map(Vec::as_slice);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(Vec::<()>::new()).as_deref()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(Vec::<()>::new()).as_deref()`
|
||||||
|
|
||||||
error: called `.as_mut().map(Vec::as_mut_slice)` on an Option value. This can be done more directly by calling `Some(Vec::<()>::new()).as_deref_mut()` instead
|
error: called `.as_mut().map(Vec::as_mut_slice)` on an `Option` value
|
||||||
--> $DIR/option_as_ref_deref.rs:30:13
|
--> $DIR/option_as_ref_deref.rs:30:13
|
||||||
|
|
|
|
||||||
LL | let _ = Some(Vec::<()>::new()).as_mut().map(Vec::as_mut_slice);
|
LL | let _ = Some(Vec::<()>::new()).as_mut().map(Vec::as_mut_slice);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `Some(Vec::<()>::new()).as_deref_mut()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `Some(Vec::<()>::new()).as_deref_mut()`
|
||||||
|
|
||||||
error: called `.as_ref().map(|x| x.deref())` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
|
error: called `.as_ref().map(|x| x.deref())` on an `Option` value
|
||||||
--> $DIR/option_as_ref_deref.rs:32:13
|
--> $DIR/option_as_ref_deref.rs:32:13
|
||||||
|
|
|
|
||||||
LL | let _ = opt.as_ref().map(|x| x.deref());
|
LL | let _ = opt.as_ref().map(|x| x.deref());
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
|
||||||
|
|
||||||
error: called `.as_mut().map(|x| x.deref_mut())` on an Option value. This can be done more directly by calling `opt.clone().as_deref_mut()` instead
|
error: called `.as_mut().map(|x| x.deref_mut())` on an `Option` value
|
||||||
--> $DIR/option_as_ref_deref.rs:33:13
|
--> $DIR/option_as_ref_deref.rs:33:13
|
||||||
|
|
|
|
||||||
LL | let _ = opt.clone().as_mut().map(|x| x.deref_mut()).map(|x| x.len());
|
LL | let _ = opt.clone().as_mut().map(|x| x.deref_mut()).map(|x| x.len());
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.clone().as_deref_mut()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.clone().as_deref_mut()`
|
||||||
|
|
||||||
error: called `.as_ref().map(|x| &**x)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
|
error: called `.as_ref().map(|x| &**x)` on an `Option` value
|
||||||
--> $DIR/option_as_ref_deref.rs:40:13
|
--> $DIR/option_as_ref_deref.rs:40:13
|
||||||
|
|
|
|
||||||
LL | let _ = opt.as_ref().map(|x| &**x);
|
LL | let _ = opt.as_ref().map(|x| &**x);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
|
||||||
|
|
||||||
error: called `.as_mut().map(|x| &mut **x)` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead
|
error: called `.as_mut().map(|x| &mut **x)` on an `Option` value
|
||||||
--> $DIR/option_as_ref_deref.rs:41:13
|
--> $DIR/option_as_ref_deref.rs:41:13
|
||||||
|
|
|
|
||||||
LL | let _ = opt.as_mut().map(|x| &mut **x);
|
LL | let _ = opt.as_mut().map(|x| &mut **x);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()`
|
||||||
|
|
||||||
error: called `.as_ref().map(std::ops::Deref::deref)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
|
error: called `.as_ref().map(std::ops::Deref::deref)` on an `Option` value
|
||||||
--> $DIR/option_as_ref_deref.rs:44:13
|
--> $DIR/option_as_ref_deref.rs:44:13
|
||||||
|
|
|
|
||||||
LL | let _ = opt.as_ref().map(std::ops::Deref::deref);
|
LL | let _ = opt.as_ref().map(std::ops::Deref::deref);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
|
||||||
|
|
||||||
error: called `.as_ref().map(String::as_str)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
|
error: called `.as_ref().map(String::as_str)` on an `Option` value
|
||||||
--> $DIR/option_as_ref_deref.rs:56:13
|
--> $DIR/option_as_ref_deref.rs:56:13
|
||||||
|
|
|
|
||||||
LL | let _ = opt.as_ref().map(String::as_str);
|
LL | let _ = opt.as_ref().map(String::as_str);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `map(..)` instead
|
error: called `map_or(None, ..)` on an `Option` value
|
||||||
--> $DIR/option_map_or_none.rs:10:26
|
--> $DIR/option_map_or_none.rs:10:26
|
||||||
|
|
|
|
||||||
LL | let _: Option<i32> = opt.map_or(None, |x| Some(x + 1));
|
LL | let _: Option<i32> = opt.map_or(None, |x| Some(x + 1));
|
||||||
@ -7,7 +7,7 @@ LL | let _: Option<i32> = 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`
|
||||||
= help: to override `-D warnings` add `#[allow(clippy::option_map_or_none)]`
|
= help: to override `-D warnings` add `#[allow(clippy::option_map_or_none)]`
|
||||||
|
|
||||||
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `map(..)` instead
|
error: called `map_or(None, ..)` on an `Option` value
|
||||||
--> $DIR/option_map_or_none.rs:13:26
|
--> $DIR/option_map_or_none.rs:13:26
|
||||||
|
|
|
|
||||||
LL | let _: Option<i32> = opt.map_or(None, |x| {
|
LL | let _: Option<i32> = opt.map_or(None, |x| {
|
||||||
@ -16,13 +16,13 @@ LL | | Some(x + 1)
|
|||||||
LL | | });
|
LL | | });
|
||||||
| |_________________________^ help: try using `map` instead: `opt.map(|x| x + 1)`
|
| |_________________________^ help: try using `map` instead: `opt.map(|x| x + 1)`
|
||||||
|
|
||||||
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `and_then(..)` instead
|
error: called `map_or(None, ..)` on an `Option` value
|
||||||
--> $DIR/option_map_or_none.rs:17:26
|
--> $DIR/option_map_or_none.rs:17:26
|
||||||
|
|
|
|
||||||
LL | let _: Option<i32> = opt.map_or(None, bar);
|
LL | let _: Option<i32> = opt.map_or(None, bar);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try using `and_then` instead: `opt.and_then(bar)`
|
| ^^^^^^^^^^^^^^^^^^^^^ help: try using `and_then` instead: `opt.and_then(bar)`
|
||||||
|
|
||||||
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `and_then(..)` instead
|
error: called `map_or(None, ..)` on an `Option` value
|
||||||
--> $DIR/option_map_or_none.rs:18:26
|
--> $DIR/option_map_or_none.rs:18:26
|
||||||
|
|
|
|
||||||
LL | let _: Option<i32> = opt.map_or(None, |x| {
|
LL | let _: Option<i32> = opt.map_or(None, |x| {
|
||||||
@ -42,7 +42,7 @@ LL + Some(offset + height)
|
|||||||
LL ~ });
|
LL ~ });
|
||||||
|
|
|
|
||||||
|
|
||||||
error: called `map_or(None, Some)` on a `Result` value. This can be done more directly by calling `ok()` instead
|
error: called `map_or(None, Some)` on a `Result` value
|
||||||
--> $DIR/option_map_or_none.rs:25:26
|
--> $DIR/option_map_or_none.rs:25:26
|
||||||
|
|
|
|
||||||
LL | let _: Option<i32> = r.map_or(None, Some);
|
LL | let _: Option<i32> = r.map_or(None, Some);
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
let opt: Result<u32, &str> = Ok(1);
|
let opt: Result<u32, &str> = Ok(1);
|
||||||
let _ = opt.ok();
|
let _ = opt.ok();
|
||||||
//~^ ERROR: called `map_or(None, Some)` on a `Result` value.
|
//~^ ERROR: called `map_or(None, Some)` on a `Result` value
|
||||||
let _ = opt.ok();
|
let _ = opt.ok();
|
||||||
//~^ ERROR: called `map_or_else(|_| None, Some)` on a `Result` value
|
//~^ ERROR: called `map_or_else(|_| None, Some)` on a `Result` value
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
let opt: Result<u32, &str> = Ok(1);
|
let opt: Result<u32, &str> = Ok(1);
|
||||||
let _ = opt.map_or(None, Some);
|
let _ = opt.map_or(None, Some);
|
||||||
//~^ ERROR: called `map_or(None, Some)` on a `Result` value.
|
//~^ ERROR: called `map_or(None, Some)` on a `Result` value
|
||||||
let _ = opt.map_or_else(|_| None, Some);
|
let _ = opt.map_or_else(|_| None, Some);
|
||||||
//~^ ERROR: called `map_or_else(|_| None, Some)` on a `Result` value
|
//~^ ERROR: called `map_or_else(|_| None, Some)` on a `Result` value
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
error: called `map_or(None, Some)` on a `Result` value. This can be done more directly by calling `ok()` instead
|
error: called `map_or(None, Some)` on a `Result` value
|
||||||
--> $DIR/result_map_or_into_option.rs:5:13
|
--> $DIR/result_map_or_into_option.rs:5:13
|
||||||
|
|
|
|
||||||
LL | let _ = opt.map_or(None, Some);
|
LL | let _ = opt.map_or(None, Some);
|
||||||
|
Loading…
Reference in New Issue
Block a user