@@ -44,10 +44,6 @@ LL | 1f32 as i32;
44
44
|
45
45
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
46
46
= 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
47
52
48
error: casting `f32` to `u32` may truncate the value
53
49
--> $DIR/cast.rs:25:5
@@ -56,10 +52,6 @@ LL | 1f32 as u32;
56
52
| ^^^^^^^^^^^
57
53
|
58
54
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
59
- help: ... or use `try_from` and handle the error accordingly
60
- |
61
- LL | u32::try_from(1f32);
62
- | ~~~~~~~~~~~~~~~~~~~
63
55
64
56
error: casting `f32` to `u32` may lose the sign of the value
65
57
--> $DIR/cast.rs:25:5
@@ -112,10 +104,6 @@ LL | 1f64 as isize;
112
104
| ^^^^^^^^^^^^^
113
105
|
114
106
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
115
- help: ... or use `try_from` and handle the error accordingly
116
- |
117
- LL | isize::try_from(1f64);
118
- | ~~~~~~~~~~~~~~~~~~~~~
119
107
120
108
error: casting `f64` to `usize` may truncate the value
121
109
--> $DIR/cast.rs:30:5
@@ -124,10 +112,6 @@ LL | 1f64 as usize;
124
112
| ^^^^^^^^^^^^^
125
113
|
126
114
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
127
- help: ... or use `try_from` and handle the error accordingly
128
- |
129
- LL | usize::try_from(1f64);
130
- | ~~~~~~~~~~~~~~~~~~~~~
131
115
132
116
error: casting `f64` to `usize` may lose the sign of the value
133
117
--> $DIR/cast.rs:30:5
@@ -154,63 +138,101 @@ LL | 1f32 as u32 as u16;
154
138
| ^^^^^^^^^^^
155
139
|
156
140
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
157
- help: ... or use `try_from` and handle the error accordingly
158
- |
159
- LL | u32::try_from(1f32) as u16;
160
- | ~~~~~~~~~~~~~~~~~~~
161
141
162
142
error: casting `f32` to `u32` may lose the sign of the value
163
143
--> $DIR/cast.rs:31:5
164
144
|
165
145
LL | 1f32 as u32 as u16;
166
146
| ^^^^^^^^^^^
167
147
148
+ error: casting `i32` to `i8` may truncate the value
149
+ --> $DIR/cast.rs:33:22
150
+ |
151
+ LL | let _x: i8 = 1i32 as _;
152
+ | ^^^^^^^^^
153
+ |
154
+ = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
155
+ help: ... or use `try_from` and handle the error accordingly
156
+ |
157
+ LL | let _x: i8 = <_>::try_from(1i32);
158
+ | ~~~~~~~~~~~~~~~~~~~
159
+
160
+ error: casting `f32` to `i32` may truncate the value
161
+ --> $DIR/cast.rs:34:9
162
+ |
163
+ LL | 1f32 as i32;
164
+ | ^^^^^^^^^^^
165
+ |
166
+ = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
167
+
168
+ error: casting `f64` to `i32` may truncate the value
169
+ --> $DIR/cast.rs:35:9
170
+ |
171
+ LL | 1f64 as i32;
172
+ | ^^^^^^^^^^^
173
+ |
174
+ = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
175
+
176
+ error: casting `f32` to `u8` may truncate the value
177
+ --> $DIR/cast.rs:36:9
178
+ |
179
+ LL | 1f32 as u8;
180
+ | ^^^^^^^^^^
181
+ |
182
+ = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
183
+
184
+ error: casting `f32` to `u8` may lose the sign of the value
185
+ --> $DIR/cast.rs:36:9
186
+ |
187
+ LL | 1f32 as u8;
188
+ | ^^^^^^^^^^
189
+
168
190
error: casting `u8` to `i8` may wrap around the value
169
- --> $DIR/cast.rs:33 :5
191
+ --> $DIR/cast.rs:39 :5
170
192
|
171
193
LL | 1u8 as i8;
172
194
| ^^^^^^^^^
173
195
|
174
196
= note: `-D clippy::cast-possible-wrap` implied by `-D warnings`
175
197
176
198
error: casting `u16` to `i16` may wrap around the value
177
- --> $DIR/cast.rs:34 :5
199
+ --> $DIR/cast.rs:40 :5
178
200
|
179
201
LL | 1u16 as i16;
180
202
| ^^^^^^^^^^^
181
203
182
204
error: casting `u32` to `i32` may wrap around the value
183
- --> $DIR/cast.rs:35 :5
205
+ --> $DIR/cast.rs:41 :5
184
206
|
185
207
LL | 1u32 as i32;
186
208
| ^^^^^^^^^^^
187
209
188
210
error: casting `u64` to `i64` may wrap around the value
189
- --> $DIR/cast.rs:36 :5
211
+ --> $DIR/cast.rs:42 :5
190
212
|
191
213
LL | 1u64 as i64;
192
214
| ^^^^^^^^^^^
193
215
194
216
error: casting `usize` to `isize` may wrap around the value
195
- --> $DIR/cast.rs:37 :5
217
+ --> $DIR/cast.rs:43 :5
196
218
|
197
219
LL | 1usize as isize;
198
220
| ^^^^^^^^^^^^^^^
199
221
200
222
error: casting `i32` to `u32` may lose the sign of the value
201
- --> $DIR/cast.rs:40 :5
223
+ --> $DIR/cast.rs:46 :5
202
224
|
203
225
LL | -1i32 as u32;
204
226
| ^^^^^^^^^^^^
205
227
206
228
error: casting `isize` to `usize` may lose the sign of the value
207
- --> $DIR/cast.rs:42 :5
229
+ --> $DIR/cast.rs:48 :5
208
230
|
209
231
LL | -1isize as usize;
210
232
| ^^^^^^^^^^^^^^^^
211
233
212
234
error: casting `i64` to `i8` may truncate the value
213
- --> $DIR/cast.rs:109 :5
235
+ --> $DIR/cast.rs:115 :5
214
236
|
215
237
LL | (-99999999999i64).min(1) as i8; // should be linted because signed
216
238
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -222,7 +244,7 @@ LL | i8::try_from((-99999999999i64).min(1)); // should be linted because sig
222
244
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
223
245
224
246
error: casting `u64` to `u8` may truncate the value
225
- --> $DIR/cast.rs:121 :5
247
+ --> $DIR/cast.rs:127 :5
226
248
|
227
249
LL | 999999u64.clamp(0, 256) as u8; // should still be linted
228
250
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -234,7 +256,7 @@ LL | u8::try_from(999999u64.clamp(0, 256)); // should still be linted
234
256
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
235
257
236
258
error: casting `main::E2` to `u8` may truncate the value
237
- --> $DIR/cast.rs:142 :21
259
+ --> $DIR/cast.rs:148 :21
238
260
|
239
261
LL | let _ = self as u8;
240
262
| ^^^^^^^^^^
@@ -246,15 +268,15 @@ LL | let _ = u8::try_from(self);
246
268
| ~~~~~~~~~~~~~~~~~~
247
269
248
270
error: casting `main::E2::B` to `u8` will truncate the value
249
- --> $DIR/cast.rs:143 :21
271
+ --> $DIR/cast.rs:149 :21
250
272
|
251
273
LL | let _ = Self::B as u8;
252
274
| ^^^^^^^^^^^^^
253
275
|
254
276
= note: `-D clippy::cast-enum-truncation` implied by `-D warnings`
255
277
256
278
error: casting `main::E5` to `i8` may truncate the value
257
- --> $DIR/cast.rs:179 :21
279
+ --> $DIR/cast.rs:185 :21
258
280
|
259
281
LL | let _ = self as i8;
260
282
| ^^^^^^^^^^
@@ -266,13 +288,13 @@ LL | let _ = i8::try_from(self);
266
288
| ~~~~~~~~~~~~~~~~~~
267
289
268
290
error: casting `main::E5::A` to `i8` will truncate the value
269
- --> $DIR/cast.rs:180 :21
291
+ --> $DIR/cast.rs:186 :21
270
292
|
271
293
LL | let _ = Self::A as i8;
272
294
| ^^^^^^^^^^^^^
273
295
274
296
error: casting `main::E6` to `i16` may truncate the value
275
- --> $DIR/cast.rs:194 :21
297
+ --> $DIR/cast.rs:200 :21
276
298
|
277
299
LL | let _ = self as i16;
278
300
| ^^^^^^^^^^^
@@ -284,7 +306,7 @@ LL | let _ = i16::try_from(self);
284
306
| ~~~~~~~~~~~~~~~~~~~
285
307
286
308
error: casting `main::E7` to `usize` may truncate the value on targets with 32-bit wide pointers
287
- --> $DIR/cast.rs:209 :21
309
+ --> $DIR/cast.rs:215 :21
288
310
|
289
311
LL | let _ = self as usize;
290
312
| ^^^^^^^^^^^^^
@@ -296,7 +318,7 @@ LL | let _ = usize::try_from(self);
296
318
| ~~~~~~~~~~~~~~~~~~~~~
297
319
298
320
error: casting `main::E10` to `u16` may truncate the value
299
- --> $DIR/cast.rs:250 :21
321
+ --> $DIR/cast.rs:256 :21
300
322
|
301
323
LL | let _ = self as u16;
302
324
| ^^^^^^^^^^^
@@ -308,7 +330,7 @@ LL | let _ = u16::try_from(self);
308
330
| ~~~~~~~~~~~~~~~~~~~
309
331
310
332
error: casting `u32` to `u8` may truncate the value
311
- --> $DIR/cast.rs:258 :13
333
+ --> $DIR/cast.rs:264 :13
312
334
|
313
335
LL | let c = (q >> 16) as u8;
314
336
| ^^^^^^^^^^^^^^^
@@ -320,7 +342,7 @@ LL | let c = u8::try_from((q >> 16));
320
342
| ~~~~~~~~~~~~~~~~~~~~~~~
321
343
322
344
error: casting `u32` to `u8` may truncate the value
323
- --> $DIR/cast.rs:261 :13
345
+ --> $DIR/cast.rs:267 :13
324
346
|
325
347
LL | let c = (q / 1000) as u8;
326
348
| ^^^^^^^^^^^^^^^^
@@ -331,5 +353,5 @@ help: ... or use `try_from` and handle the error accordingly
331
353
LL | let c = u8::try_from((q / 1000));
332
354
| ~~~~~~~~~~~~~~~~~~~~~~~~
333
355
334
- error: aborting due to 36 previous errors
356
+ error: aborting due to 41 previous errors
335
357
0 commit comments