Skip to content

Commit

Permalink
Auto merge of rust-lang#9863 - smoelius:expect-unwrap-used-typo, r=fl…
Browse files Browse the repository at this point in the history
…ip1995

Fix typo in `expect_used` and `unwrap_used` warning messages

"\`an Option\`" -> "an \`Option\`" and "\`a Result\`" -> "a \`Result\`".

changelog: fix typo in `expect_used` and `unwrap_used` warning messages
  • Loading branch information
bors committed Nov 18, 2022
2 parents dfe37f1 + 00ae5e1 commit 01f40ce
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 46 deletions.
6 changes: 3 additions & 3 deletions clippy_lints/src/methods/expect_used.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ pub(super) fn check(
let obj_ty = cx.typeck_results().expr_ty(recv).peel_refs();

let mess = if is_type_diagnostic_item(cx, obj_ty, sym::Option) && !is_err {
Some((EXPECT_USED, "an Option", "None", ""))
Some((EXPECT_USED, "an `Option`", "None", ""))
} else if is_type_diagnostic_item(cx, obj_ty, sym::Result) {
Some((EXPECT_USED, "a Result", if is_err { "Ok" } else { "Err" }, "an "))
Some((EXPECT_USED, "a `Result`", if is_err { "Ok" } else { "Err" }, "an "))
} else {
None
};
Expand All @@ -36,7 +36,7 @@ pub(super) fn check(
cx,
lint,
expr.span,
&format!("used `{method}()` on `{kind}` value"),
&format!("used `{method}()` on {kind} value"),
None,
&format!("if this value is {none_prefix}`{none_value}`, it will panic"),
);
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/methods/unwrap_used.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ pub(super) fn check(
let obj_ty = cx.typeck_results().expr_ty(recv).peel_refs();

let mess = if is_type_diagnostic_item(cx, obj_ty, sym::Option) && !is_err {
Some((UNWRAP_USED, "an Option", "None", ""))
Some((UNWRAP_USED, "an `Option`", "None", ""))
} else if is_type_diagnostic_item(cx, obj_ty, sym::Result) {
Some((UNWRAP_USED, "a Result", if is_err { "Ok" } else { "Err" }, "an "))
Some((UNWRAP_USED, "a `Result`", if is_err { "Ok" } else { "Err" }, "an "))
} else {
None
};
Expand All @@ -45,7 +45,7 @@ pub(super) fn check(
cx,
lint,
expr.span,
&format!("used `unwrap{method_suffix}()` on `{kind}` value"),
&format!("used `unwrap{method_suffix}()` on {kind} value"),
None,
&help,
);
Expand Down
4 changes: 2 additions & 2 deletions tests/ui-toml/expect_used/expect_used.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: used `expect()` on `an Option` value
error: used `expect()` on an `Option` value
--> $DIR/expect_used.rs:6:13
|
LL | let _ = opt.expect("");
Expand All @@ -7,7 +7,7 @@ LL | let _ = opt.expect("");
= help: if this value is `None`, it will panic
= note: `-D clippy::expect-used` implied by `-D warnings`

error: used `expect()` on `a Result` value
error: used `expect()` on a `Result` value
--> $DIR/expect_used.rs:11:13
|
LL | let _ = res.expect("");
Expand Down
26 changes: 13 additions & 13 deletions tests/ui-toml/unwrap_used/unwrap_used.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ note: the lint level is defined here
LL | #![deny(clippy::get_unwrap)]
| ^^^^^^^^^^^^^^^^^^

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:35:17
|
LL | let _ = boxed_slice.get(1).unwrap();
Expand All @@ -25,7 +25,7 @@ error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more co
LL | let _ = some_slice.get(0).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_slice[0]`

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:36:17
|
LL | let _ = some_slice.get(0).unwrap();
Expand All @@ -39,7 +39,7 @@ error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more conc
LL | let _ = some_vec.get(0).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_vec[0]`

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:37:17
|
LL | let _ = some_vec.get(0).unwrap();
Expand All @@ -53,7 +53,7 @@ error: called `.get().unwrap()` on a VecDeque. Using `[]` is more clear and more
LL | let _ = some_vecdeque.get(0).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_vecdeque[0]`

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:38:17
|
LL | let _ = some_vecdeque.get(0).unwrap();
Expand All @@ -67,7 +67,7 @@ error: called `.get().unwrap()` on a HashMap. Using `[]` is more clear and more
LL | let _ = some_hashmap.get(&1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_hashmap[&1]`

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:39:17
|
LL | let _ = some_hashmap.get(&1).unwrap();
Expand All @@ -81,7 +81,7 @@ error: called `.get().unwrap()` on a BTreeMap. Using `[]` is more clear and more
LL | let _ = some_btreemap.get(&1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_btreemap[&1]`

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:40:17
|
LL | let _ = some_btreemap.get(&1).unwrap();
Expand All @@ -95,7 +95,7 @@ error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more co
LL | let _: u8 = *boxed_slice.get(1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `boxed_slice[1]`

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:44:22
|
LL | let _: u8 = *boxed_slice.get(1).unwrap();
Expand All @@ -109,7 +109,7 @@ error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and mor
LL | *boxed_slice.get_mut(0).unwrap() = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `boxed_slice[0]`

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:49:10
|
LL | *boxed_slice.get_mut(0).unwrap() = 1;
Expand All @@ -123,7 +123,7 @@ error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and mor
LL | *some_slice.get_mut(0).unwrap() = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_slice[0]`

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:50:10
|
LL | *some_slice.get_mut(0).unwrap() = 1;
Expand All @@ -137,7 +137,7 @@ error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more
LL | *some_vec.get_mut(0).unwrap() = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0]`

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:51:10
|
LL | *some_vec.get_mut(0).unwrap() = 1;
Expand All @@ -151,7 +151,7 @@ error: called `.get_mut().unwrap()` on a VecDeque. Using `[]` is more clear and
LL | *some_vecdeque.get_mut(0).unwrap() = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vecdeque[0]`

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:52:10
|
LL | *some_vecdeque.get_mut(0).unwrap() = 1;
Expand All @@ -165,7 +165,7 @@ error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more conc
LL | let _ = some_vec.get(0..1).unwrap().to_vec();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0..1]`

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:64:17
|
LL | let _ = some_vec.get(0..1).unwrap().to_vec();
Expand All @@ -179,7 +179,7 @@ error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more
LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0..1]`

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:65:17
|
LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec();
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/expect.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: used `expect()` on `an Option` value
error: used `expect()` on an `Option` value
--> $DIR/expect.rs:5:13
|
LL | let _ = opt.expect("");
Expand All @@ -7,15 +7,15 @@ LL | let _ = opt.expect("");
= help: if this value is `None`, it will panic
= note: `-D clippy::expect-used` implied by `-D warnings`

error: used `expect()` on `a Result` value
error: used `expect()` on a `Result` value
--> $DIR/expect.rs:10:13
|
LL | let _ = res.expect("");
| ^^^^^^^^^^^^^^
|
= help: if this value is an `Err`, it will panic

error: used `expect_err()` on `a Result` value
error: used `expect_err()` on a `Result` value
--> $DIR/expect.rs:11:13
|
LL | let _ = res.expect_err("");
Expand Down
26 changes: 13 additions & 13 deletions tests/ui/get_unwrap.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ note: the lint level is defined here
LL | #![deny(clippy::get_unwrap)]
| ^^^^^^^^^^^^^^^^^^

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:35:17
|
LL | let _ = boxed_slice.get(1).unwrap();
Expand All @@ -25,7 +25,7 @@ error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more co
LL | let _ = some_slice.get(0).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_slice[0]`

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:36:17
|
LL | let _ = some_slice.get(0).unwrap();
Expand All @@ -39,7 +39,7 @@ error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more conc
LL | let _ = some_vec.get(0).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_vec[0]`

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:37:17
|
LL | let _ = some_vec.get(0).unwrap();
Expand All @@ -53,7 +53,7 @@ error: called `.get().unwrap()` on a VecDeque. Using `[]` is more clear and more
LL | let _ = some_vecdeque.get(0).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_vecdeque[0]`

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:38:17
|
LL | let _ = some_vecdeque.get(0).unwrap();
Expand All @@ -67,7 +67,7 @@ error: called `.get().unwrap()` on a HashMap. Using `[]` is more clear and more
LL | let _ = some_hashmap.get(&1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_hashmap[&1]`

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:39:17
|
LL | let _ = some_hashmap.get(&1).unwrap();
Expand All @@ -81,7 +81,7 @@ error: called `.get().unwrap()` on a BTreeMap. Using `[]` is more clear and more
LL | let _ = some_btreemap.get(&1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_btreemap[&1]`

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:40:17
|
LL | let _ = some_btreemap.get(&1).unwrap();
Expand All @@ -95,7 +95,7 @@ error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more co
LL | let _: u8 = *boxed_slice.get(1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `boxed_slice[1]`

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:44:22
|
LL | let _: u8 = *boxed_slice.get(1).unwrap();
Expand All @@ -109,7 +109,7 @@ error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and mor
LL | *boxed_slice.get_mut(0).unwrap() = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `boxed_slice[0]`

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:49:10
|
LL | *boxed_slice.get_mut(0).unwrap() = 1;
Expand All @@ -123,7 +123,7 @@ error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and mor
LL | *some_slice.get_mut(0).unwrap() = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_slice[0]`

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:50:10
|
LL | *some_slice.get_mut(0).unwrap() = 1;
Expand All @@ -137,7 +137,7 @@ error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more
LL | *some_vec.get_mut(0).unwrap() = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0]`

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:51:10
|
LL | *some_vec.get_mut(0).unwrap() = 1;
Expand All @@ -151,7 +151,7 @@ error: called `.get_mut().unwrap()` on a VecDeque. Using `[]` is more clear and
LL | *some_vecdeque.get_mut(0).unwrap() = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vecdeque[0]`

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:52:10
|
LL | *some_vecdeque.get_mut(0).unwrap() = 1;
Expand All @@ -165,7 +165,7 @@ error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more conc
LL | let _ = some_vec.get(0..1).unwrap().to_vec();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0..1]`

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:64:17
|
LL | let _ = some_vec.get(0..1).unwrap().to_vec();
Expand All @@ -179,7 +179,7 @@ error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more
LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0..1]`

error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:65:17
|
LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec();
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/unwrap.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/unwrap.rs:5:13
|
LL | let _ = opt.unwrap();
Expand All @@ -7,15 +7,15 @@ LL | let _ = opt.unwrap();
= help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
= note: `-D clippy::unwrap-used` implied by `-D warnings`

error: used `unwrap()` on `a Result` value
error: used `unwrap()` on a `Result` value
--> $DIR/unwrap.rs:10:13
|
LL | let _ = res.unwrap();
| ^^^^^^^^^^^^
|
= help: if you don't want to handle the `Err` case gracefully, consider using `expect()` to provide a better panic message

error: used `unwrap_err()` on `a Result` value
error: used `unwrap_err()` on a `Result` value
--> $DIR/unwrap.rs:11:13
|
LL | let _ = res.unwrap_err();
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/unwrap_expect_used.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: used `unwrap()` on `an Option` value
error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_expect_used.rs:23:5
|
LL | Some(3).unwrap();
Expand All @@ -7,7 +7,7 @@ LL | Some(3).unwrap();
= help: if this value is `None`, it will panic
= note: `-D clippy::unwrap-used` implied by `-D warnings`

error: used `expect()` on `an Option` value
error: used `expect()` on an `Option` value
--> $DIR/unwrap_expect_used.rs:24:5
|
LL | Some(3).expect("Hello world!");
Expand All @@ -16,31 +16,31 @@ LL | Some(3).expect("Hello world!");
= help: if this value is `None`, it will panic
= note: `-D clippy::expect-used` implied by `-D warnings`

error: used `unwrap()` on `a Result` value
error: used `unwrap()` on a `Result` value
--> $DIR/unwrap_expect_used.rs:31:5
|
LL | a.unwrap();
| ^^^^^^^^^^
|
= help: if this value is an `Err`, it will panic

error: used `expect()` on `a Result` value
error: used `expect()` on a `Result` value
--> $DIR/unwrap_expect_used.rs:32:5
|
LL | a.expect("Hello world!");
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: if this value is an `Err`, it will panic

error: used `unwrap_err()` on `a Result` value
error: used `unwrap_err()` on a `Result` value
--> $DIR/unwrap_expect_used.rs:33:5
|
LL | a.unwrap_err();
| ^^^^^^^^^^^^^^
|
= help: if this value is an `Ok`, it will panic

error: used `expect_err()` on `a Result` value
error: used `expect_err()` on a `Result` value
--> $DIR/unwrap_expect_used.rs:34:5
|
LL | a.expect_err("Hello error!");
Expand Down

0 comments on commit 01f40ce

Please sign in to comment.