Skip to content

Commit 447ed5c

Browse files
committed
add attributes
1 parent df6ef60 commit 447ed5c

File tree

3 files changed

+29
-53
lines changed

3 files changed

+29
-53
lines changed

tests/ui/get_unwrap.fixed

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ fn main() {
3939
let _ = &some_vecdeque[0];
4040
let _ = &some_hashmap[&1];
4141
let _ = &some_btreemap[&1];
42+
#[allow(clippy::unwrap_used)]
4243
let _ = false_positive.get(0).unwrap();
4344
// Test with deref
4445
let _: u8 = boxed_slice[1];
@@ -51,9 +52,12 @@ fn main() {
5152
some_vec[0] = 1;
5253
some_vecdeque[0] = 1;
5354
// Check false positives
54-
*some_hashmap.get_mut(&1).unwrap() = 'b';
55-
*some_btreemap.get_mut(&1).unwrap() = 'b';
56-
*false_positive.get_mut(0).unwrap() = 1;
55+
#[allow(clippy::unwrap_used)]
56+
{
57+
*some_hashmap.get_mut(&1).unwrap() = 'b';
58+
*some_btreemap.get_mut(&1).unwrap() = 'b';
59+
*false_positive.get_mut(0).unwrap() = 1;
60+
}
5761
}
5862

5963
{

tests/ui/get_unwrap.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ fn main() {
3939
let _ = some_vecdeque.get(0).unwrap();
4040
let _ = some_hashmap.get(&1).unwrap();
4141
let _ = some_btreemap.get(&1).unwrap();
42+
#[allow(clippy::unwrap_used)]
4243
let _ = false_positive.get(0).unwrap();
4344
// Test with deref
4445
let _: u8 = *boxed_slice.get(1).unwrap();
@@ -51,9 +52,12 @@ fn main() {
5152
*some_vec.get_mut(0).unwrap() = 1;
5253
*some_vecdeque.get_mut(0).unwrap() = 1;
5354
// Check false positives
54-
*some_hashmap.get_mut(&1).unwrap() = 'b';
55-
*some_btreemap.get_mut(&1).unwrap() = 'b';
56-
*false_positive.get_mut(0).unwrap() = 1;
55+
#[allow(clippy::unwrap_used)]
56+
{
57+
*some_hashmap.get_mut(&1).unwrap() = 'b';
58+
*some_btreemap.get_mut(&1).unwrap() = 'b';
59+
*false_positive.get_mut(0).unwrap() = 1;
60+
}
5761
}
5862

5963
{

tests/ui/get_unwrap.stderr

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -89,135 +89,103 @@ LL | let _ = some_btreemap.get(&1).unwrap();
8989
|
9090
= help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
9191

92-
error: used `unwrap()` on `an Option` value
93-
--> $DIR/get_unwrap.rs:42:17
94-
|
95-
LL | let _ = false_positive.get(0).unwrap();
96-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
97-
|
98-
= help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
99-
10092
error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
101-
--> $DIR/get_unwrap.rs:44:21
93+
--> $DIR/get_unwrap.rs:45:21
10294
|
10395
LL | let _: u8 = *boxed_slice.get(1).unwrap();
10496
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `boxed_slice[1]`
10597

10698
error: used `unwrap()` on `an Option` value
107-
--> $DIR/get_unwrap.rs:44:22
99+
--> $DIR/get_unwrap.rs:45:22
108100
|
109101
LL | let _: u8 = *boxed_slice.get(1).unwrap();
110102
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
111103
|
112104
= help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
113105

114106
error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise
115-
--> $DIR/get_unwrap.rs:49:9
107+
--> $DIR/get_unwrap.rs:50:9
116108
|
117109
LL | *boxed_slice.get_mut(0).unwrap() = 1;
118110
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `boxed_slice[0]`
119111

120112
error: used `unwrap()` on `an Option` value
121-
--> $DIR/get_unwrap.rs:49:10
113+
--> $DIR/get_unwrap.rs:50:10
122114
|
123115
LL | *boxed_slice.get_mut(0).unwrap() = 1;
124116
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
125117
|
126118
= help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
127119

128120
error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise
129-
--> $DIR/get_unwrap.rs:50:9
121+
--> $DIR/get_unwrap.rs:51:9
130122
|
131123
LL | *some_slice.get_mut(0).unwrap() = 1;
132124
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_slice[0]`
133125

134126
error: used `unwrap()` on `an Option` value
135-
--> $DIR/get_unwrap.rs:50:10
127+
--> $DIR/get_unwrap.rs:51:10
136128
|
137129
LL | *some_slice.get_mut(0).unwrap() = 1;
138130
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
139131
|
140132
= help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
141133

142134
error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise
143-
--> $DIR/get_unwrap.rs:51:9
135+
--> $DIR/get_unwrap.rs:52:9
144136
|
145137
LL | *some_vec.get_mut(0).unwrap() = 1;
146138
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0]`
147139

148140
error: used `unwrap()` on `an Option` value
149-
--> $DIR/get_unwrap.rs:51:10
141+
--> $DIR/get_unwrap.rs:52:10
150142
|
151143
LL | *some_vec.get_mut(0).unwrap() = 1;
152144
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
153145
|
154146
= help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
155147

156148
error: called `.get_mut().unwrap()` on a VecDeque. Using `[]` is more clear and more concise
157-
--> $DIR/get_unwrap.rs:52:9
149+
--> $DIR/get_unwrap.rs:53:9
158150
|
159151
LL | *some_vecdeque.get_mut(0).unwrap() = 1;
160152
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vecdeque[0]`
161153

162154
error: used `unwrap()` on `an Option` value
163-
--> $DIR/get_unwrap.rs:52:10
155+
--> $DIR/get_unwrap.rs:53:10
164156
|
165157
LL | *some_vecdeque.get_mut(0).unwrap() = 1;
166158
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
167159
|
168160
= help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
169161

170-
error: used `unwrap()` on `an Option` value
171-
--> $DIR/get_unwrap.rs:54:10
172-
|
173-
LL | *some_hashmap.get_mut(&1).unwrap() = 'b';
174-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
175-
|
176-
= help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
177-
178-
error: used `unwrap()` on `an Option` value
179-
--> $DIR/get_unwrap.rs:55:10
180-
|
181-
LL | *some_btreemap.get_mut(&1).unwrap() = 'b';
182-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
183-
|
184-
= help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
185-
186-
error: used `unwrap()` on `an Option` value
187-
--> $DIR/get_unwrap.rs:56:10
188-
|
189-
LL | *false_positive.get_mut(0).unwrap() = 1;
190-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
191-
|
192-
= help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
193-
194162
error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise
195-
--> $DIR/get_unwrap.rs:61:17
163+
--> $DIR/get_unwrap.rs:65:17
196164
|
197165
LL | let _ = some_vec.get(0..1).unwrap().to_vec();
198166
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0..1]`
199167

200168
error: used `unwrap()` on `an Option` value
201-
--> $DIR/get_unwrap.rs:61:17
169+
--> $DIR/get_unwrap.rs:65:17
202170
|
203171
LL | let _ = some_vec.get(0..1).unwrap().to_vec();
204172
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
205173
|
206174
= help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
207175

208176
error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise
209-
--> $DIR/get_unwrap.rs:62:17
177+
--> $DIR/get_unwrap.rs:66:17
210178
|
211179
LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec();
212180
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0..1]`
213181

214182
error: used `unwrap()` on `an Option` value
215-
--> $DIR/get_unwrap.rs:62:17
183+
--> $DIR/get_unwrap.rs:66:17
216184
|
217185
LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec();
218186
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
219187
|
220188
= help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
221189

222-
error: aborting due to 30 previous errors
190+
error: aborting due to 26 previous errors
223191

0 commit comments

Comments
 (0)