Skip to content

Commit 3e52031

Browse files
committed
unwrap_used: Fix help, "an None" -> "None"
1 parent 6ee03e2 commit 3e52031

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

clippy_lints/src/methods/expect_used.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr
1212
let obj_ty = cx.typeck_results().expr_ty(recv).peel_refs();
1313

1414
let mess = if is_type_diagnostic_item(cx, obj_ty, sym::Option) {
15-
Some((EXPECT_USED, "an Option", "None"))
15+
Some((EXPECT_USED, "an Option", "None", ""))
1616
} else if is_type_diagnostic_item(cx, obj_ty, sym::Result) {
17-
Some((EXPECT_USED, "a Result", "Err"))
17+
Some((EXPECT_USED, "a Result", "Err", "an "))
1818
} else {
1919
None
2020
};
@@ -23,14 +23,14 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr
2323
return;
2424
}
2525

26-
if let Some((lint, kind, none_value)) = mess {
26+
if let Some((lint, kind, none_value, none_prefix)) = mess {
2727
span_lint_and_help(
2828
cx,
2929
lint,
3030
expr.span,
31-
&format!("used `expect()` on `{}` value", kind,),
31+
&format!("used `expect()` on `{kind}` value"),
3232
None,
33-
&format!("if this value is an `{}`, it will panic", none_value,),
33+
&format!("if this value is {none_prefix}`{none_value}`, it will panic"),
3434
);
3535
}
3636
}

clippy_lints/src/methods/unwrap_used.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr
1212
let obj_ty = cx.typeck_results().expr_ty(recv).peel_refs();
1313

1414
let mess = if is_type_diagnostic_item(cx, obj_ty, sym::Option) {
15-
Some((UNWRAP_USED, "an Option", "None"))
15+
Some((UNWRAP_USED, "an Option", "None", ""))
1616
} else if is_type_diagnostic_item(cx, obj_ty, sym::Result) {
17-
Some((UNWRAP_USED, "a Result", "Err"))
17+
Some((UNWRAP_USED, "a Result", "Err", "an "))
1818
} else {
1919
None
2020
};
@@ -23,14 +23,14 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr
2323
return;
2424
}
2525

26-
if let Some((lint, kind, none_value)) = mess {
26+
if let Some((lint, kind, none_value, none_prefix)) = mess {
2727
let help = if is_lint_allowed(cx, EXPECT_USED, expr.hir_id) {
2828
format!(
2929
"if you don't want to handle the `{none_value}` case gracefully, consider \
3030
using `expect()` to provide a better panic message"
3131
)
3232
} else {
33-
format!("if this value is an `{none_value}`, it will panic")
33+
format!("if this value is {none_prefix}`{none_value}`, it will panic")
3434
};
3535

3636
span_lint_and_help(

tests/ui-toml/expect_used/expect_used.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let _ = opt.expect("");
55
| ^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::expect-used` implied by `-D warnings`
8-
= help: if this value is an `None`, it will panic
8+
= help: if this value is `None`, it will panic
99

1010
error: used `expect()` on `a Result` value
1111
--> $DIR/expect_used.rs:11:13

tests/ui/expect.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let _ = opt.expect("");
55
| ^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::expect-used` implied by `-D warnings`
8-
= help: if this value is an `None`, it will panic
8+
= help: if this value is `None`, it will panic
99

1010
error: used `expect()` on `a Result` value
1111
--> $DIR/expect.rs:10:13

tests/ui/unwrap_expect_used.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | Some(3).unwrap();
55
| ^^^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::unwrap-used` implied by `-D warnings`
8-
= help: if this value is an `None`, it will panic
8+
= help: if this value is `None`, it will panic
99

1010
error: used `expect()` on `an Option` value
1111
--> $DIR/unwrap_expect_used.rs:5:5
@@ -14,7 +14,7 @@ LL | Some(3).expect("Hello world!");
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1515
|
1616
= note: `-D clippy::expect-used` implied by `-D warnings`
17-
= help: if this value is an `None`, it will panic
17+
= help: if this value is `None`, it will panic
1818

1919
error: used `unwrap()` on `a Result` value
2020
--> $DIR/unwrap_expect_used.rs:8:5

0 commit comments

Comments
 (0)