Skip to content

Commit 01f40ce

Browse files
committed
Auto merge of rust-lang#9863 - smoelius:expect-unwrap-used-typo, r=flip1995
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
2 parents dfe37f1 + 00ae5e1 commit 01f40ce

File tree

8 files changed

+46
-46
lines changed

8 files changed

+46
-46
lines changed

clippy_lints/src/methods/expect_used.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ pub(super) fn check(
1818
let obj_ty = cx.typeck_results().expr_ty(recv).peel_refs();
1919

2020
let mess = if is_type_diagnostic_item(cx, obj_ty, sym::Option) && !is_err {
21-
Some((EXPECT_USED, "an Option", "None", ""))
21+
Some((EXPECT_USED, "an `Option`", "None", ""))
2222
} else if is_type_diagnostic_item(cx, obj_ty, sym::Result) {
23-
Some((EXPECT_USED, "a Result", if is_err { "Ok" } else { "Err" }, "an "))
23+
Some((EXPECT_USED, "a `Result`", if is_err { "Ok" } else { "Err" }, "an "))
2424
} else {
2525
None
2626
};
@@ -36,7 +36,7 @@ pub(super) fn check(
3636
cx,
3737
lint,
3838
expr.span,
39-
&format!("used `{method}()` on `{kind}` value"),
39+
&format!("used `{method}()` on {kind} value"),
4040
None,
4141
&format!("if this value is {none_prefix}`{none_value}`, it will panic"),
4242
);

clippy_lints/src/methods/unwrap_used.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ pub(super) fn check(
1818
let obj_ty = cx.typeck_results().expr_ty(recv).peel_refs();
1919

2020
let mess = if is_type_diagnostic_item(cx, obj_ty, sym::Option) && !is_err {
21-
Some((UNWRAP_USED, "an Option", "None", ""))
21+
Some((UNWRAP_USED, "an `Option`", "None", ""))
2222
} else if is_type_diagnostic_item(cx, obj_ty, sym::Result) {
23-
Some((UNWRAP_USED, "a Result", if is_err { "Ok" } else { "Err" }, "an "))
23+
Some((UNWRAP_USED, "a `Result`", if is_err { "Ok" } else { "Err" }, "an "))
2424
} else {
2525
None
2626
};
@@ -45,7 +45,7 @@ pub(super) fn check(
4545
cx,
4646
lint,
4747
expr.span,
48-
&format!("used `unwrap{method_suffix}()` on `{kind}` value"),
48+
&format!("used `unwrap{method_suffix}()` on {kind} value"),
4949
None,
5050
&help,
5151
);

tests/ui-toml/expect_used/expect_used.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: used `expect()` on `an Option` value
1+
error: used `expect()` on an `Option` value
22
--> $DIR/expect_used.rs:6:13
33
|
44
LL | let _ = opt.expect("");
@@ -7,7 +7,7 @@ LL | let _ = opt.expect("");
77
= help: if this value is `None`, it will panic
88
= note: `-D clippy::expect-used` implied by `-D warnings`
99

10-
error: used `expect()` on `a Result` value
10+
error: used `expect()` on a `Result` value
1111
--> $DIR/expect_used.rs:11:13
1212
|
1313
LL | let _ = res.expect("");

tests/ui-toml/unwrap_used/unwrap_used.stderr

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ note: the lint level is defined here
1010
LL | #![deny(clippy::get_unwrap)]
1111
| ^^^^^^^^^^^^^^^^^^
1212

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

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

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

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

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

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

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

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

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

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

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

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

182-
error: used `unwrap()` on `an Option` value
182+
error: used `unwrap()` on an `Option` value
183183
--> $DIR/unwrap_used.rs:65:17
184184
|
185185
LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec();

tests/ui/expect.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: used `expect()` on `an Option` value
1+
error: used `expect()` on an `Option` value
22
--> $DIR/expect.rs:5:13
33
|
44
LL | let _ = opt.expect("");
@@ -7,15 +7,15 @@ LL | let _ = opt.expect("");
77
= help: if this value is `None`, it will panic
88
= note: `-D clippy::expect-used` implied by `-D warnings`
99

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

18-
error: used `expect_err()` on `a Result` value
18+
error: used `expect_err()` on a `Result` value
1919
--> $DIR/expect.rs:11:13
2020
|
2121
LL | let _ = res.expect_err("");

tests/ui/get_unwrap.stderr

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ note: the lint level is defined here
1010
LL | #![deny(clippy::get_unwrap)]
1111
| ^^^^^^^^^^^^^^^^^^
1212

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

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

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

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

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

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

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

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

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

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

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

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

182-
error: used `unwrap()` on `an Option` value
182+
error: used `unwrap()` on an `Option` value
183183
--> $DIR/get_unwrap.rs:65:17
184184
|
185185
LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec();

tests/ui/unwrap.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: used `unwrap()` on `an Option` value
1+
error: used `unwrap()` on an `Option` value
22
--> $DIR/unwrap.rs:5:13
33
|
44
LL | let _ = opt.unwrap();
@@ -7,15 +7,15 @@ LL | let _ = opt.unwrap();
77
= help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
88
= note: `-D clippy::unwrap-used` implied by `-D warnings`
99

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

18-
error: used `unwrap_err()` on `a Result` value
18+
error: used `unwrap_err()` on a `Result` value
1919
--> $DIR/unwrap.rs:11:13
2020
|
2121
LL | let _ = res.unwrap_err();

tests/ui/unwrap_expect_used.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: used `unwrap()` on `an Option` value
1+
error: used `unwrap()` on an `Option` value
22
--> $DIR/unwrap_expect_used.rs:23:5
33
|
44
LL | Some(3).unwrap();
@@ -7,7 +7,7 @@ LL | Some(3).unwrap();
77
= help: if this value is `None`, it will panic
88
= note: `-D clippy::unwrap-used` implied by `-D warnings`
99

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

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

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

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

43-
error: used `expect_err()` on `a Result` value
43+
error: used `expect_err()` on a `Result` value
4444
--> $DIR/unwrap_expect_used.rs:34:5
4545
|
4646
LL | a.expect_err("Hello error!");

0 commit comments

Comments
 (0)