Skip to content

Commit 9308df7

Browse files
committed
Auto merge of #3863 - rust-lang:get_unwrap, r=oli-obk
Move get_unwrap to restriction fixes #3862 r? @oli-obk
2 parents 920112d + 038ec7f commit 9308df7

File tree

5 files changed

+22
-17
lines changed

5 files changed

+22
-17
lines changed

clippy_lints/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
583583
matches::WILDCARD_ENUM_MATCH_ARM,
584584
mem_forget::MEM_FORGET,
585585
methods::CLONE_ON_REF_PTR,
586+
methods::GET_UNWRAP,
586587
methods::OPTION_UNWRAP_USED,
587588
methods::RESULT_UNWRAP_USED,
588589
methods::WRONG_PUB_SELF_CONVENTION,
@@ -749,7 +750,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
749750
methods::CLONE_ON_COPY,
750751
methods::EXPECT_FUN_CALL,
751752
methods::FILTER_NEXT,
752-
methods::GET_UNWRAP,
753753
methods::INTO_ITER_ON_ARRAY,
754754
methods::INTO_ITER_ON_REF,
755755
methods::ITER_CLONED_COLLECT,
@@ -908,7 +908,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
908908
matches::SINGLE_MATCH,
909909
mem_replace::MEM_REPLACE_OPTION_WITH_NONE,
910910
methods::CHARS_LAST_CMP,
911-
methods::GET_UNWRAP,
912911
methods::INTO_ITER_ON_REF,
913912
methods::ITER_CLONED_COLLECT,
914913
methods::ITER_SKIP_NEXT,

clippy_lints/src/methods/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ declare_clippy_lint! {
579579
/// some_vec[0] = 1;
580580
/// ```
581581
pub GET_UNWRAP,
582-
style,
582+
restriction,
583583
"using `.get().unwrap()` or `.get_mut().unwrap()` when using `[]` would work instead"
584584
}
585585

tests/ui/get_unwrap.fixed

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// run-rustfix
22
#![allow(unused_mut)]
3+
#![deny(clippy::get_unwrap)]
34

45
use std::collections::BTreeMap;
56
use std::collections::HashMap;

tests/ui/get_unwrap.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// run-rustfix
22
#![allow(unused_mut)]
3+
#![deny(clippy::get_unwrap)]
34

45
use std::collections::BTreeMap;
56
use std::collections::HashMap;

tests/ui/get_unwrap.stderr

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,83 @@
11
error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
2-
--> $DIR/get_unwrap.rs:33:17
2+
--> $DIR/get_unwrap.rs:34:17
33
|
44
LL | let _ = boxed_slice.get(1).unwrap();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&boxed_slice[1]`
66
|
7-
= note: `-D clippy::get-unwrap` implied by `-D warnings`
7+
note: lint level defined here
8+
--> $DIR/get_unwrap.rs:3:9
9+
|
10+
LL | #![deny(clippy::get_unwrap)]
11+
| ^^^^^^^^^^^^^^^^^^
812

913
error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
10-
--> $DIR/get_unwrap.rs:34:17
14+
--> $DIR/get_unwrap.rs:35:17
1115
|
1216
LL | let _ = some_slice.get(0).unwrap();
1317
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_slice[0]`
1418

1519
error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise
16-
--> $DIR/get_unwrap.rs:35:17
20+
--> $DIR/get_unwrap.rs:36:17
1721
|
1822
LL | let _ = some_vec.get(0).unwrap();
1923
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_vec[0]`
2024

2125
error: called `.get().unwrap()` on a VecDeque. Using `[]` is more clear and more concise
22-
--> $DIR/get_unwrap.rs:36:17
26+
--> $DIR/get_unwrap.rs:37:17
2327
|
2428
LL | let _ = some_vecdeque.get(0).unwrap();
2529
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_vecdeque[0]`
2630

2731
error: called `.get().unwrap()` on a HashMap. Using `[]` is more clear and more concise
28-
--> $DIR/get_unwrap.rs:37:17
32+
--> $DIR/get_unwrap.rs:38:17
2933
|
3034
LL | let _ = some_hashmap.get(&1).unwrap();
3135
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_hashmap[&1]`
3236

3337
error: called `.get().unwrap()` on a BTreeMap. Using `[]` is more clear and more concise
34-
--> $DIR/get_unwrap.rs:38:17
38+
--> $DIR/get_unwrap.rs:39:17
3539
|
3640
LL | let _ = some_btreemap.get(&1).unwrap();
3741
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_btreemap[&1]`
3842

3943
error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
40-
--> $DIR/get_unwrap.rs:41:21
44+
--> $DIR/get_unwrap.rs:42:21
4145
|
4246
LL | let _: u8 = *boxed_slice.get(1).unwrap();
4347
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `boxed_slice[1]`
4448

4549
error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise
46-
--> $DIR/get_unwrap.rs:46:9
50+
--> $DIR/get_unwrap.rs:47:9
4751
|
4852
LL | *boxed_slice.get_mut(0).unwrap() = 1;
4953
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `boxed_slice[0]`
5054

5155
error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise
52-
--> $DIR/get_unwrap.rs:47:9
56+
--> $DIR/get_unwrap.rs:48:9
5357
|
5458
LL | *some_slice.get_mut(0).unwrap() = 1;
5559
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_slice[0]`
5660

5761
error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise
58-
--> $DIR/get_unwrap.rs:48:9
62+
--> $DIR/get_unwrap.rs:49:9
5963
|
6064
LL | *some_vec.get_mut(0).unwrap() = 1;
6165
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0]`
6266

6367
error: called `.get_mut().unwrap()` on a VecDeque. Using `[]` is more clear and more concise
64-
--> $DIR/get_unwrap.rs:49:9
68+
--> $DIR/get_unwrap.rs:50:9
6569
|
6670
LL | *some_vecdeque.get_mut(0).unwrap() = 1;
6771
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vecdeque[0]`
6872

6973
error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise
70-
--> $DIR/get_unwrap.rs:58:17
74+
--> $DIR/get_unwrap.rs:59:17
7175
|
7276
LL | let _ = some_vec.get(0..1).unwrap().to_vec();
7377
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0..1]`
7478

7579
error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise
76-
--> $DIR/get_unwrap.rs:59:17
80+
--> $DIR/get_unwrap.rs:60:17
7781
|
7882
LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec();
7983
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0..1]`

0 commit comments

Comments
 (0)