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:
mcarton 2016-01-03 14:36:24 +01:00
parent 52fbf1989d
commit 7a4d6aa8b7
1 changed files with 13 additions and 6 deletions

View File

@ -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));
} }
} }