fix a bug that the closure arguments are not displayed
This commit is contained in:
parent
bbffe825ed
commit
02e0726149
|
@ -21,7 +21,7 @@ fn reduce_unit_expression<'a>(
|
||||||
match block.expr {
|
match block.expr {
|
||||||
Some(inner_expr) => {
|
Some(inner_expr) => {
|
||||||
// If block only contains an expression,
|
// If block only contains an expression,
|
||||||
// reduce `{ X }` to `X`
|
// reduce `|x| { x + 1 }` to `|x| x + 1`
|
||||||
reduce_unit_expression(cx, inner_expr)
|
reduce_unit_expression(cx, inner_expr)
|
||||||
},
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -51,7 +51,6 @@ pub(super) fn check<'tcx>(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// let (lint_name, msg, instead, hint) = {
|
|
||||||
let default_arg_is_none = if let hir::ExprKind::Path(ref qpath) = def_arg.kind {
|
let default_arg_is_none = if let hir::ExprKind::Path(ref qpath) = def_arg.kind {
|
||||||
is_lang_ctor(cx, qpath, OptionNone)
|
is_lang_ctor(cx, qpath, OptionNone)
|
||||||
} else {
|
} else {
|
||||||
|
@ -71,7 +70,8 @@ pub(super) fn check<'tcx>(
|
||||||
|
|
||||||
if is_option {
|
if is_option {
|
||||||
let self_snippet = snippet(cx, recv.span, "..");
|
let self_snippet = snippet(cx, recv.span, "..");
|
||||||
if let hir::ExprKind::Closure(_, _, id, _, _) = map_arg.kind {
|
if let hir::ExprKind::Closure(_, _, id, span, _) = map_arg.kind {
|
||||||
|
let arg_snippet = snippet(cx, span, "..");
|
||||||
if_chain! {
|
if_chain! {
|
||||||
let body = cx.tcx.hir().body(id);
|
let body = cx.tcx.hir().body(id);
|
||||||
if let Some((func, arg_char)) = reduce_unit_expression(cx, &body.value);
|
if let Some((func, arg_char)) = reduce_unit_expression(cx, &body.value);
|
||||||
|
@ -89,7 +89,7 @@ pub(super) fn check<'tcx>(
|
||||||
expr.span,
|
expr.span,
|
||||||
msg,
|
msg,
|
||||||
"try using `map` instead",
|
"try using `map` instead",
|
||||||
format!("{0}.map({1})", self_snippet, func_snippet),
|
format!("{0}.map({1} {2})", self_snippet, arg_snippet,func_snippet),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,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. This can be done more directly by calling \
|
||||||
`and_then(..)` instead";
|
`and_then(..)` instead";
|
||||||
span_lint_and_sugg(
|
return span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
OPTION_MAP_OR_NONE,
|
OPTION_MAP_OR_NONE,
|
||||||
expr.span,
|
expr.span,
|
||||||
|
@ -107,12 +107,12 @@ pub(super) fn check<'tcx>(
|
||||||
"try using `and_then` instead",
|
"try using `and_then` instead",
|
||||||
format!("{0}.and_then({1})", self_snippet, func_snippet),
|
format!("{0}.and_then({1})", self_snippet, func_snippet),
|
||||||
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. This can be done more directly by calling \
|
||||||
`ok()` instead";
|
`ok()` instead";
|
||||||
let self_snippet = snippet(cx, recv.span, "..");
|
let self_snippet = snippet(cx, recv.span, "..");
|
||||||
span_lint_and_sugg(
|
return span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
RESULT_MAP_OR_INTO_OPTION,
|
RESULT_MAP_OR_INTO_OPTION,
|
||||||
expr.span,
|
expr.span,
|
||||||
|
@ -120,9 +120,6 @@ pub(super) fn check<'tcx>(
|
||||||
"try using `ok` instead",
|
"try using `ok` instead",
|
||||||
format!("{0}.ok()", self_snippet),
|
format!("{0}.ok()", self_snippet),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
)
|
);
|
||||||
} else {
|
|
||||||
// nothing to lint!
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,14 +13,7 @@ LL | let _ :Option<i32> = opt.map_or(None, |x| {
|
||||||
| __________________________^
|
| __________________________^
|
||||||
LL | | Some(x + 1)
|
LL | | Some(x + 1)
|
||||||
LL | | });
|
LL | | });
|
||||||
| |_________________________^
|
| |_________________________^ help: try using `map` instead: `opt.map(|x| x + 1)`
|
||||||
|
|
|
||||||
help: try using `map` instead
|
|
||||||
|
|
|
||||||
LL ~ let _ :Option<i32> = opt.map(|x| {
|
|
||||||
LL + x + 1
|
|
||||||
LL ~ });
|
|
||||||
|
|
|
||||||
|
|
||||||
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. This can be done more directly by calling `and_then(..)` instead
|
||||||
--> $DIR/option_map_or_none.rs:20:26
|
--> $DIR/option_map_or_none.rs:20:26
|
||||||
|
|
Loading…
Reference in a new issue