Skip to content

Commit 8679dd3

Browse files
committed
unnecessary_unwrap, panicking_unwrap: make lints adhere to lint message convention
1 parent 9b7ab1d commit 8679dd3

File tree

4 files changed

+38
-38
lines changed

4 files changed

+38
-38
lines changed

clippy_lints/src/unwrap.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ impl<'a, 'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> {
181181
self.cx,
182182
UNNECESSARY_UNWRAP,
183183
expr.span,
184-
&format!("You checked before that `{}()` cannot fail. \
185-
Instead of checking and unwrapping, it's better to use `if let` or `match`.",
184+
&format!("you checked before that `{}()` cannot fail. \
185+
Instead of checking and unwrapping, it's better to use `if let` or `match`",
186186
method_name.ident.name),
187187
|diag| { diag.span_label(unwrappable.check.span, "the check is happening here"); },
188188
);
@@ -191,7 +191,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> {
191191
self.cx,
192192
PANICKING_UNWRAP,
193193
expr.span,
194-
&format!("This call to `{}()` will always panic.",
194+
&format!("this call to `{}()` will always panic",
195195
method_name.ident.name),
196196
|diag| { diag.span_label(unwrappable.check.span, "because of this check"); },
197197
);

tests/ui/checked_unwrap/complex_conditionals.stderr

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
1+
error: you checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`
22
--> $DIR/complex_conditionals.rs:8:9
33
|
44
LL | if x.is_ok() && y.is_err() {
@@ -12,7 +12,7 @@ note: the lint level is defined here
1212
LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1414

15-
error: This call to `unwrap_err()` will always panic.
15+
error: this call to `unwrap_err()` will always panic
1616
--> $DIR/complex_conditionals.rs:9:9
1717
|
1818
LL | if x.is_ok() && y.is_err() {
@@ -27,7 +27,7 @@ note: the lint level is defined here
2727
LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
2828
| ^^^^^^^^^^^^^^^^^^^^^^^^
2929

30-
error: This call to `unwrap()` will always panic.
30+
error: this call to `unwrap()` will always panic
3131
--> $DIR/complex_conditionals.rs:10:9
3232
|
3333
LL | if x.is_ok() && y.is_err() {
@@ -36,7 +36,7 @@ LL | if x.is_ok() && y.is_err() {
3636
LL | y.unwrap(); // will panic
3737
| ^^^^^^^^^^
3838

39-
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
39+
error: you checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`
4040
--> $DIR/complex_conditionals.rs:11:9
4141
|
4242
LL | if x.is_ok() && y.is_err() {
@@ -45,7 +45,7 @@ LL | if x.is_ok() && y.is_err() {
4545
LL | y.unwrap_err(); // unnecessary
4646
| ^^^^^^^^^^^^^^
4747

48-
error: This call to `unwrap()` will always panic.
48+
error: this call to `unwrap()` will always panic
4949
--> $DIR/complex_conditionals.rs:25:9
5050
|
5151
LL | if x.is_ok() || y.is_ok() {
@@ -54,7 +54,7 @@ LL | if x.is_ok() || y.is_ok() {
5454
LL | x.unwrap(); // will panic
5555
| ^^^^^^^^^^
5656

57-
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
57+
error: you checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`
5858
--> $DIR/complex_conditionals.rs:26:9
5959
|
6060
LL | if x.is_ok() || y.is_ok() {
@@ -63,7 +63,7 @@ LL | if x.is_ok() || y.is_ok() {
6363
LL | x.unwrap_err(); // unnecessary
6464
| ^^^^^^^^^^^^^^
6565

66-
error: This call to `unwrap()` will always panic.
66+
error: this call to `unwrap()` will always panic
6767
--> $DIR/complex_conditionals.rs:27:9
6868
|
6969
LL | if x.is_ok() || y.is_ok() {
@@ -72,7 +72,7 @@ LL | if x.is_ok() || y.is_ok() {
7272
LL | y.unwrap(); // will panic
7373
| ^^^^^^^^^^
7474

75-
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
75+
error: you checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`
7676
--> $DIR/complex_conditionals.rs:28:9
7777
|
7878
LL | if x.is_ok() || y.is_ok() {
@@ -81,15 +81,15 @@ LL | if x.is_ok() || y.is_ok() {
8181
LL | y.unwrap_err(); // unnecessary
8282
| ^^^^^^^^^^^^^^
8383

84-
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
84+
error: you checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`
8585
--> $DIR/complex_conditionals.rs:32:9
8686
|
8787
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
8888
| --------- the check is happening here
8989
LL | x.unwrap(); // unnecessary
9090
| ^^^^^^^^^^
9191

92-
error: This call to `unwrap_err()` will always panic.
92+
error: this call to `unwrap_err()` will always panic
9393
--> $DIR/complex_conditionals.rs:33:9
9494
|
9595
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
@@ -98,7 +98,7 @@ LL | x.unwrap(); // unnecessary
9898
LL | x.unwrap_err(); // will panic
9999
| ^^^^^^^^^^^^^^
100100

101-
error: This call to `unwrap()` will always panic.
101+
error: this call to `unwrap()` will always panic
102102
--> $DIR/complex_conditionals.rs:34:9
103103
|
104104
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
@@ -107,7 +107,7 @@ LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
107107
LL | y.unwrap(); // will panic
108108
| ^^^^^^^^^^
109109

110-
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
110+
error: you checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`
111111
--> $DIR/complex_conditionals.rs:35:9
112112
|
113113
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
@@ -116,7 +116,7 @@ LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
116116
LL | y.unwrap_err(); // unnecessary
117117
| ^^^^^^^^^^^^^^
118118

119-
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
119+
error: you checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`
120120
--> $DIR/complex_conditionals.rs:36:9
121121
|
122122
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
@@ -125,7 +125,7 @@ LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
125125
LL | z.unwrap(); // unnecessary
126126
| ^^^^^^^^^^
127127

128-
error: This call to `unwrap_err()` will always panic.
128+
error: this call to `unwrap_err()` will always panic
129129
--> $DIR/complex_conditionals.rs:37:9
130130
|
131131
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
@@ -134,7 +134,7 @@ LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
134134
LL | z.unwrap_err(); // will panic
135135
| ^^^^^^^^^^^^^^
136136

137-
error: This call to `unwrap()` will always panic.
137+
error: this call to `unwrap()` will always panic
138138
--> $DIR/complex_conditionals.rs:45:9
139139
|
140140
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
@@ -143,7 +143,7 @@ LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
143143
LL | x.unwrap(); // will panic
144144
| ^^^^^^^^^^
145145

146-
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
146+
error: you checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`
147147
--> $DIR/complex_conditionals.rs:46:9
148148
|
149149
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
@@ -152,7 +152,7 @@ LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
152152
LL | x.unwrap_err(); // unnecessary
153153
| ^^^^^^^^^^^^^^
154154

155-
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
155+
error: you checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`
156156
--> $DIR/complex_conditionals.rs:47:9
157157
|
158158
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
@@ -161,7 +161,7 @@ LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
161161
LL | y.unwrap(); // unnecessary
162162
| ^^^^^^^^^^
163163

164-
error: This call to `unwrap_err()` will always panic.
164+
error: this call to `unwrap_err()` will always panic
165165
--> $DIR/complex_conditionals.rs:48:9
166166
|
167167
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
@@ -170,7 +170,7 @@ LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
170170
LL | y.unwrap_err(); // will panic
171171
| ^^^^^^^^^^^^^^
172172

173-
error: This call to `unwrap()` will always panic.
173+
error: this call to `unwrap()` will always panic
174174
--> $DIR/complex_conditionals.rs:49:9
175175
|
176176
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
@@ -179,7 +179,7 @@ LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
179179
LL | z.unwrap(); // will panic
180180
| ^^^^^^^^^^
181181

182-
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
182+
error: you checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`
183183
--> $DIR/complex_conditionals.rs:50:9
184184
|
185185
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {

tests/ui/checked_unwrap/complex_conditionals_nested.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
1+
error: you checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`
22
--> $DIR/complex_conditionals_nested.rs:8:13
33
|
44
LL | if x.is_some() {
@@ -12,7 +12,7 @@ note: the lint level is defined here
1212
LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1414

15-
error: This call to `unwrap()` will always panic.
15+
error: this call to `unwrap()` will always panic
1616
--> $DIR/complex_conditionals_nested.rs:10:13
1717
|
1818
LL | if x.is_some() {

tests/ui/checked_unwrap/simple_conditionals.stderr

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
1+
error: you checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`
22
--> $DIR/simple_conditionals.rs:39:9
33
|
44
LL | if x.is_some() {
@@ -12,7 +12,7 @@ note: the lint level is defined here
1212
LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1414

15-
error: This call to `unwrap()` will always panic.
15+
error: this call to `unwrap()` will always panic
1616
--> $DIR/simple_conditionals.rs:41:9
1717
|
1818
LL | if x.is_some() {
@@ -27,15 +27,15 @@ note: the lint level is defined here
2727
LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
2828
| ^^^^^^^^^^^^^^^^^^^^^^^^
2929

30-
error: This call to `unwrap()` will always panic.
30+
error: this call to `unwrap()` will always panic
3131
--> $DIR/simple_conditionals.rs:44:9
3232
|
3333
LL | if x.is_none() {
3434
| ----------- because of this check
3535
LL | x.unwrap(); // will panic
3636
| ^^^^^^^^^^
3737

38-
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
38+
error: you checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`
3939
--> $DIR/simple_conditionals.rs:46:9
4040
|
4141
LL | if x.is_none() {
@@ -44,7 +44,7 @@ LL | if x.is_none() {
4444
LL | x.unwrap(); // unnecessary
4545
| ^^^^^^^^^^
4646

47-
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
47+
error: you checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`
4848
--> $DIR/simple_conditionals.rs:7:13
4949
|
5050
LL | if $a.is_some() {
@@ -57,15 +57,15 @@ LL | m!(x);
5757
|
5858
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
5959

60-
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
60+
error: you checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`
6161
--> $DIR/simple_conditionals.rs:54:9
6262
|
6363
LL | if x.is_ok() {
6464
| --------- the check is happening here
6565
LL | x.unwrap(); // unnecessary
6666
| ^^^^^^^^^^
6767

68-
error: This call to `unwrap_err()` will always panic.
68+
error: this call to `unwrap_err()` will always panic
6969
--> $DIR/simple_conditionals.rs:55:9
7070
|
7171
LL | if x.is_ok() {
@@ -74,7 +74,7 @@ LL | x.unwrap(); // unnecessary
7474
LL | x.unwrap_err(); // will panic
7575
| ^^^^^^^^^^^^^^
7676

77-
error: This call to `unwrap()` will always panic.
77+
error: this call to `unwrap()` will always panic
7878
--> $DIR/simple_conditionals.rs:57:9
7979
|
8080
LL | if x.is_ok() {
@@ -83,7 +83,7 @@ LL | if x.is_ok() {
8383
LL | x.unwrap(); // will panic
8484
| ^^^^^^^^^^
8585

86-
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
86+
error: you checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`
8787
--> $DIR/simple_conditionals.rs:58:9
8888
|
8989
LL | if x.is_ok() {
@@ -92,15 +92,15 @@ LL | if x.is_ok() {
9292
LL | x.unwrap_err(); // unnecessary
9393
| ^^^^^^^^^^^^^^
9494

95-
error: This call to `unwrap()` will always panic.
95+
error: this call to `unwrap()` will always panic
9696
--> $DIR/simple_conditionals.rs:61:9
9797
|
9898
LL | if x.is_err() {
9999
| ---------- because of this check
100100
LL | x.unwrap(); // will panic
101101
| ^^^^^^^^^^
102102

103-
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
103+
error: you checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`
104104
--> $DIR/simple_conditionals.rs:62:9
105105
|
106106
LL | if x.is_err() {
@@ -109,7 +109,7 @@ LL | x.unwrap(); // will panic
109109
LL | x.unwrap_err(); // unnecessary
110110
| ^^^^^^^^^^^^^^
111111

112-
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
112+
error: you checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`
113113
--> $DIR/simple_conditionals.rs:64:9
114114
|
115115
LL | if x.is_err() {
@@ -118,7 +118,7 @@ LL | if x.is_err() {
118118
LL | x.unwrap(); // unnecessary
119119
| ^^^^^^^^^^
120120

121-
error: This call to `unwrap_err()` will always panic.
121+
error: this call to `unwrap_err()` will always panic
122122
--> $DIR/simple_conditionals.rs:65:9
123123
|
124124
LL | if x.is_err() {

0 commit comments

Comments
 (0)