@@ -135,52 +135,82 @@ error: casting `f64` to `usize` may lose the sign of the value
135
135
LL | 1f64 as usize;
136
136
| ^^^^^^^^^^^^^
137
137
138
+ error: casting `u32` to `u16` may truncate the value
139
+ --> $DIR/cast.rs:31:5
140
+ |
141
+ LL | 1f32 as u32 as u16;
142
+ | ^^^^^^^^^^^^^^^^^^
143
+ |
144
+ = help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
145
+ help: ... or use `try_from` and handle the error accordingly
146
+ |
147
+ LL | u16::try_from(1f32 as u32);
148
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~
149
+
150
+ error: casting `f32` to `u32` may truncate the value
151
+ --> $DIR/cast.rs:31:5
152
+ |
153
+ LL | 1f32 as u32 as u16;
154
+ | ^^^^^^^^^^^
155
+ |
156
+ = help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
157
+ help: ... or use `try_from` and handle the error accordingly
158
+ |
159
+ LL | u32::try_from(1f32) as u16;
160
+ | ~~~~~~~~~~~~~~~~~~~
161
+
162
+ error: casting `f32` to `u32` may lose the sign of the value
163
+ --> $DIR/cast.rs:31:5
164
+ |
165
+ LL | 1f32 as u32 as u16;
166
+ | ^^^^^^^^^^^
167
+
138
168
error: casting `u8` to `i8` may wrap around the value
139
- --> $DIR/cast.rs:32 :5
169
+ --> $DIR/cast.rs:33 :5
140
170
|
141
171
LL | 1u8 as i8;
142
172
| ^^^^^^^^^
143
173
|
144
174
= note: `-D clippy::cast-possible-wrap` implied by `-D warnings`
145
175
146
176
error: casting `u16` to `i16` may wrap around the value
147
- --> $DIR/cast.rs:33 :5
177
+ --> $DIR/cast.rs:34 :5
148
178
|
149
179
LL | 1u16 as i16;
150
180
| ^^^^^^^^^^^
151
181
152
182
error: casting `u32` to `i32` may wrap around the value
153
- --> $DIR/cast.rs:34 :5
183
+ --> $DIR/cast.rs:35 :5
154
184
|
155
185
LL | 1u32 as i32;
156
186
| ^^^^^^^^^^^
157
187
158
188
error: casting `u64` to `i64` may wrap around the value
159
- --> $DIR/cast.rs:35 :5
189
+ --> $DIR/cast.rs:36 :5
160
190
|
161
191
LL | 1u64 as i64;
162
192
| ^^^^^^^^^^^
163
193
164
194
error: casting `usize` to `isize` may wrap around the value
165
- --> $DIR/cast.rs:36 :5
195
+ --> $DIR/cast.rs:37 :5
166
196
|
167
197
LL | 1usize as isize;
168
198
| ^^^^^^^^^^^^^^^
169
199
170
200
error: casting `i32` to `u32` may lose the sign of the value
171
- --> $DIR/cast.rs:39 :5
201
+ --> $DIR/cast.rs:40 :5
172
202
|
173
203
LL | -1i32 as u32;
174
204
| ^^^^^^^^^^^^
175
205
176
206
error: casting `isize` to `usize` may lose the sign of the value
177
- --> $DIR/cast.rs:41 :5
207
+ --> $DIR/cast.rs:42 :5
178
208
|
179
209
LL | -1isize as usize;
180
210
| ^^^^^^^^^^^^^^^^
181
211
182
212
error: casting `i64` to `i8` may truncate the value
183
- --> $DIR/cast.rs:108 :5
213
+ --> $DIR/cast.rs:109 :5
184
214
|
185
215
LL | (-99999999999i64).min(1) as i8; // should be linted because signed
186
216
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -192,7 +222,7 @@ LL | i8::try_from((-99999999999i64).min(1)); // should be linted because sig
192
222
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
193
223
194
224
error: casting `u64` to `u8` may truncate the value
195
- --> $DIR/cast.rs:120 :5
225
+ --> $DIR/cast.rs:121 :5
196
226
|
197
227
LL | 999999u64.clamp(0, 256) as u8; // should still be linted
198
228
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -204,7 +234,7 @@ LL | u8::try_from(999999u64.clamp(0, 256)); // should still be linted
204
234
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
205
235
206
236
error: casting `main::E2` to `u8` may truncate the value
207
- --> $DIR/cast.rs:141 :21
237
+ --> $DIR/cast.rs:142 :21
208
238
|
209
239
LL | let _ = self as u8;
210
240
| ^^^^^^^^^^
@@ -216,15 +246,15 @@ LL | let _ = u8::try_from(self);
216
246
| ~~~~~~~~~~~~~~~~~~
217
247
218
248
error: casting `main::E2::B` to `u8` will truncate the value
219
- --> $DIR/cast.rs:142 :21
249
+ --> $DIR/cast.rs:143 :21
220
250
|
221
251
LL | let _ = Self::B as u8;
222
252
| ^^^^^^^^^^^^^
223
253
|
224
254
= note: `-D clippy::cast-enum-truncation` implied by `-D warnings`
225
255
226
256
error: casting `main::E5` to `i8` may truncate the value
227
- --> $DIR/cast.rs:178 :21
257
+ --> $DIR/cast.rs:179 :21
228
258
|
229
259
LL | let _ = self as i8;
230
260
| ^^^^^^^^^^
@@ -236,13 +266,13 @@ LL | let _ = i8::try_from(self);
236
266
| ~~~~~~~~~~~~~~~~~~
237
267
238
268
error: casting `main::E5::A` to `i8` will truncate the value
239
- --> $DIR/cast.rs:179 :21
269
+ --> $DIR/cast.rs:180 :21
240
270
|
241
271
LL | let _ = Self::A as i8;
242
272
| ^^^^^^^^^^^^^
243
273
244
274
error: casting `main::E6` to `i16` may truncate the value
245
- --> $DIR/cast.rs:193 :21
275
+ --> $DIR/cast.rs:194 :21
246
276
|
247
277
LL | let _ = self as i16;
248
278
| ^^^^^^^^^^^
@@ -254,7 +284,7 @@ LL | let _ = i16::try_from(self);
254
284
| ~~~~~~~~~~~~~~~~~~~
255
285
256
286
error: casting `main::E7` to `usize` may truncate the value on targets with 32-bit wide pointers
257
- --> $DIR/cast.rs:208 :21
287
+ --> $DIR/cast.rs:209 :21
258
288
|
259
289
LL | let _ = self as usize;
260
290
| ^^^^^^^^^^^^^
@@ -266,7 +296,7 @@ LL | let _ = usize::try_from(self);
266
296
| ~~~~~~~~~~~~~~~~~~~~~
267
297
268
298
error: casting `main::E10` to `u16` may truncate the value
269
- --> $DIR/cast.rs:249 :21
299
+ --> $DIR/cast.rs:250 :21
270
300
|
271
301
LL | let _ = self as u16;
272
302
| ^^^^^^^^^^^
@@ -278,7 +308,7 @@ LL | let _ = u16::try_from(self);
278
308
| ~~~~~~~~~~~~~~~~~~~
279
309
280
310
error: casting `u32` to `u8` may truncate the value
281
- --> $DIR/cast.rs:257 :13
311
+ --> $DIR/cast.rs:258 :13
282
312
|
283
313
LL | let c = (q >> 16) as u8;
284
314
| ^^^^^^^^^^^^^^^
@@ -290,7 +320,7 @@ LL | let c = u8::try_from((q >> 16));
290
320
| ~~~~~~~~~~~~~~~~~~~~~~~
291
321
292
322
error: casting `u32` to `u8` may truncate the value
293
- --> $DIR/cast.rs:260 :13
323
+ --> $DIR/cast.rs:261 :13
294
324
|
295
325
LL | let c = (q / 1000) as u8;
296
326
| ^^^^^^^^^^^^^^^^
@@ -301,5 +331,5 @@ help: ... or use `try_from` and handle the error accordingly
301
331
LL | let c = u8::try_from((q / 1000));
302
332
| ~~~~~~~~~~~~~~~~~~~~~~~~
303
333
304
- error: aborting due to 33 previous errors
334
+ error: aborting due to 36 previous errors
305
335
0 commit comments