@@ -40,26 +40,15 @@ error: casting `f32` to `i32` may truncate the value
40
40
--> $DIR/cast.rs:24:5
41
41
|
42
42
LL | 1f32 as i32;
43
- | ^^^^^^^^^^^
43
+ | ^^^^^^^^^^^ help: avoid silent truncation by using: `i32::try_from(1f32).unwrap()`
44
44
|
45
- = help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
46
45
= note: `-D clippy::cast-possible-truncation` implied by `-D warnings`
47
- help: ... or use `try_from` and handle the error accordingly
48
- |
49
- LL | i32::try_from(1f32);
50
- | ~~~~~~~~~~~~~~~~~~~
51
46
52
47
error: casting `f32` to `u32` may truncate the value
53
48
--> $DIR/cast.rs:25:5
54
49
|
55
50
LL | 1f32 as u32;
56
- | ^^^^^^^^^^^
57
- |
58
- = help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
59
- help: ... or use `try_from` and handle the error accordingly
60
- |
61
- LL | u32::try_from(1f32);
62
- | ~~~~~~~~~~~~~~~~~~~
51
+ | ^^^^^^^^^^^ help: avoid silent truncation by using: `u32::try_from(1f32).unwrap()`
63
52
64
53
error: casting `f32` to `u32` may lose the sign of the value
65
54
--> $DIR/cast.rs:25:5
@@ -73,61 +62,31 @@ error: casting `f64` to `f32` may truncate the value
73
62
--> $DIR/cast.rs:26:5
74
63
|
75
64
LL | 1f64 as f32;
76
- | ^^^^^^^^^^^
77
- |
78
- = help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
79
- help: ... or use `try_from` and handle the error accordingly
80
- |
81
- LL | f32::try_from(1f64);
82
- | ~~~~~~~~~~~~~~~~~~~
65
+ | ^^^^^^^^^^^ help: avoid silent truncation by using: `f32::try_from(1f64).unwrap()`
83
66
84
67
error: casting `i32` to `i8` may truncate the value
85
68
--> $DIR/cast.rs:27:5
86
69
|
87
70
LL | 1i32 as i8;
88
- | ^^^^^^^^^^
89
- |
90
- = help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
91
- help: ... or use `try_from` and handle the error accordingly
92
- |
93
- LL | i8::try_from(1i32);
94
- | ~~~~~~~~~~~~~~~~~~
71
+ | ^^^^^^^^^^ help: avoid silent truncation by using: `i8::try_from(1i32).unwrap()`
95
72
96
73
error: casting `i32` to `u8` may truncate the value
97
74
--> $DIR/cast.rs:28:5
98
75
|
99
76
LL | 1i32 as u8;
100
- | ^^^^^^^^^^
101
- |
102
- = help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
103
- help: ... or use `try_from` and handle the error accordingly
104
- |
105
- LL | u8::try_from(1i32);
106
- | ~~~~~~~~~~~~~~~~~~
77
+ | ^^^^^^^^^^ help: avoid silent truncation by using: `u8::try_from(1i32).unwrap()`
107
78
108
79
error: casting `f64` to `isize` may truncate the value
109
80
--> $DIR/cast.rs:29:5
110
81
|
111
82
LL | 1f64 as isize;
112
- | ^^^^^^^^^^^^^
113
- |
114
- = help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
115
- help: ... or use `try_from` and handle the error accordingly
116
- |
117
- LL | isize::try_from(1f64);
118
- | ~~~~~~~~~~~~~~~~~~~~~
83
+ | ^^^^^^^^^^^^^ help: avoid silent truncation by using: `isize::try_from(1f64).unwrap()`
119
84
120
85
error: casting `f64` to `usize` may truncate the value
121
86
--> $DIR/cast.rs:30:5
122
87
|
123
88
LL | 1f64 as usize;
124
- | ^^^^^^^^^^^^^
125
- |
126
- = help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
127
- help: ... or use `try_from` and handle the error accordingly
128
- |
129
- LL | usize::try_from(1f64);
130
- | ~~~~~~~~~~~~~~~~~~~~~
89
+ | ^^^^^^^^^^^^^ help: avoid silent truncation by using: `usize::try_from(1f64).unwrap()`
131
90
132
91
error: casting `f64` to `usize` may lose the sign of the value
133
92
--> $DIR/cast.rs:30:5
@@ -183,37 +142,19 @@ error: casting `i64` to `i8` may truncate the value
183
142
--> $DIR/cast.rs:108:5
184
143
|
185
144
LL | (-99999999999i64).min(1) as i8; // should be linted because signed
186
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
187
- |
188
- = help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
189
- help: ... or use `try_from` and handle the error accordingly
190
- |
191
- LL | i8::try_from((-99999999999i64).min(1)); // should be linted because signed
192
- | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
145
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: avoid silent truncation by using: `i8::try_from((-99999999999i64).min(1)).unwrap()`
193
146
194
147
error: casting `u64` to `u8` may truncate the value
195
148
--> $DIR/cast.rs:120:5
196
149
|
197
150
LL | 999999u64.clamp(0, 256) as u8; // should still be linted
198
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
199
- |
200
- = help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
201
- help: ... or use `try_from` and handle the error accordingly
202
- |
203
- LL | u8::try_from(999999u64.clamp(0, 256)); // should still be linted
204
- | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
151
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: avoid silent truncation by using: `u8::try_from(999999u64.clamp(0, 256)).unwrap()`
205
152
206
153
error: casting `main::E2` to `u8` may truncate the value
207
154
--> $DIR/cast.rs:141:21
208
155
|
209
156
LL | let _ = self as u8;
210
- | ^^^^^^^^^^
211
- |
212
- = help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
213
- help: ... or use `try_from` and handle the error accordingly
214
- |
215
- LL | let _ = u8::try_from(self);
216
- | ~~~~~~~~~~~~~~~~~~
157
+ | ^^^^^^^^^^ help: avoid silent truncation by using: `u8::try_from(self).unwrap()`
217
158
218
159
error: casting `main::E2::B` to `u8` will truncate the value
219
160
--> $DIR/cast.rs:142:21
@@ -227,13 +168,7 @@ error: casting `main::E5` to `i8` may truncate the value
227
168
--> $DIR/cast.rs:178:21
228
169
|
229
170
LL | let _ = self as i8;
230
- | ^^^^^^^^^^
231
- |
232
- = help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
233
- help: ... or use `try_from` and handle the error accordingly
234
- |
235
- LL | let _ = i8::try_from(self);
236
- | ~~~~~~~~~~~~~~~~~~
171
+ | ^^^^^^^^^^ help: avoid silent truncation by using: `i8::try_from(self).unwrap()`
237
172
238
173
error: casting `main::E5::A` to `i8` will truncate the value
239
174
--> $DIR/cast.rs:179:21
@@ -245,61 +180,31 @@ error: casting `main::E6` to `i16` may truncate the value
245
180
--> $DIR/cast.rs:193:21
246
181
|
247
182
LL | let _ = self as i16;
248
- | ^^^^^^^^^^^
249
- |
250
- = help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
251
- help: ... or use `try_from` and handle the error accordingly
252
- |
253
- LL | let _ = i16::try_from(self);
254
- | ~~~~~~~~~~~~~~~~~~~
183
+ | ^^^^^^^^^^^ help: avoid silent truncation by using: `i16::try_from(self).unwrap()`
255
184
256
185
error: casting `main::E7` to `usize` may truncate the value on targets with 32-bit wide pointers
257
186
--> $DIR/cast.rs:208:21
258
187
|
259
188
LL | let _ = self as usize;
260
- | ^^^^^^^^^^^^^
261
- |
262
- = help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
263
- help: ... or use `try_from` and handle the error accordingly
264
- |
265
- LL | let _ = usize::try_from(self);
266
- | ~~~~~~~~~~~~~~~~~~~~~
189
+ | ^^^^^^^^^^^^^ help: avoid silent truncation by using: `usize::try_from(self).unwrap()`
267
190
268
191
error: casting `main::E10` to `u16` may truncate the value
269
192
--> $DIR/cast.rs:249:21
270
193
|
271
194
LL | let _ = self as u16;
272
- | ^^^^^^^^^^^
273
- |
274
- = help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
275
- help: ... or use `try_from` and handle the error accordingly
276
- |
277
- LL | let _ = u16::try_from(self);
278
- | ~~~~~~~~~~~~~~~~~~~
195
+ | ^^^^^^^^^^^ help: avoid silent truncation by using: `u16::try_from(self).unwrap()`
279
196
280
197
error: casting `u32` to `u8` may truncate the value
281
198
--> $DIR/cast.rs:257:13
282
199
|
283
200
LL | let c = (q >> 16) as u8;
284
- | ^^^^^^^^^^^^^^^
285
- |
286
- = help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
287
- help: ... or use `try_from` and handle the error accordingly
288
- |
289
- LL | let c = u8::try_from((q >> 16));
290
- | ~~~~~~~~~~~~~~~~~~~~~~~
201
+ | ^^^^^^^^^^^^^^^ help: avoid silent truncation by using: `u8::try_from((q >> 16)).unwrap()`
291
202
292
203
error: casting `u32` to `u8` may truncate the value
293
204
--> $DIR/cast.rs:260:13
294
205
|
295
206
LL | let c = (q / 1000) as u8;
296
- | ^^^^^^^^^^^^^^^^
297
- |
298
- = help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
299
- help: ... or use `try_from` and handle the error accordingly
300
- |
301
- LL | let c = u8::try_from((q / 1000));
302
- | ~~~~~~~~~~~~~~~~~~~~~~~~
207
+ | ^^^^^^^^^^^^^^^^ help: avoid silent truncation by using: `u8::try_from((q / 1000)).unwrap()`
303
208
304
209
error: aborting due to 33 previous errors
305
210
0 commit comments