Use same error message for OPTION_UNWRAP_USED and RESULT_UNWRAP_USED
IIRC, Result::expect wasn't stable until quite recently, which might be why there was 2 different error messages.
This commit is contained in:
parent
52fbf1989d
commit
7a4d6aa8b7
|
@ -258,14 +258,21 @@ impl LateLintPass for MethodsPass {
|
||||||
fn lint_unwrap(cx: &LateContext, expr: &Expr, unwrap_args: &MethodArgs) {
|
fn lint_unwrap(cx: &LateContext, expr: &Expr, unwrap_args: &MethodArgs) {
|
||||||
let (obj_ty, _) = walk_ptrs_ty_depth(cx.tcx.expr_ty(&unwrap_args[0]));
|
let (obj_ty, _) = walk_ptrs_ty_depth(cx.tcx.expr_ty(&unwrap_args[0]));
|
||||||
|
|
||||||
if match_type(cx, obj_ty, &OPTION_PATH) {
|
let mess = if match_type(cx, obj_ty, &OPTION_PATH) {
|
||||||
span_lint(cx, OPTION_UNWRAP_USED, expr.span,
|
Some((OPTION_UNWRAP_USED, "an Option", "None"))
|
||||||
"used unwrap() on an Option value. If you don't want to handle the None case \
|
|
||||||
gracefully, consider using expect() to provide a better panic message");
|
|
||||||
}
|
}
|
||||||
else if match_type(cx, obj_ty, &RESULT_PATH) {
|
else if match_type(cx, obj_ty, &RESULT_PATH) {
|
||||||
span_lint(cx, RESULT_UNWRAP_USED, expr.span,
|
Some((RESULT_UNWRAP_USED, "a Result", "Err"))
|
||||||
"used unwrap() on a Result value. Graceful handling of Err values is preferred");
|
}
|
||||||
|
else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some((lint, kind, none_value)) = mess {
|
||||||
|
span_lint(cx, lint, expr.span,
|
||||||
|
&format!("used unwrap() on {} value. If you don't want to handle the {} \
|
||||||
|
case gracefully, consider using expect() to provide a better panic
|
||||||
|
message", kind, none_value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue