Skip to content

Commit 716837c

Browse files
committed
Move get_unwrap to restriction
fixes #3862
1 parent 920112d commit 716837c

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

clippy_lints/src/lib.rs

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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.rs

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

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

tests/ui/get_unwrap.stderr

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,79 @@
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
|
77
= note: `-D clippy::get-unwrap` implied by `-D warnings`
88

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

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

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

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

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

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

4545
error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise
46-
--> $DIR/get_unwrap.rs:46:9
46+
--> $DIR/get_unwrap.rs:47:9
4747
|
4848
LL | *boxed_slice.get_mut(0).unwrap() = 1;
4949
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `boxed_slice[0]`
5050

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

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

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

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

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

0 commit comments

Comments
 (0)