@@ -44,10 +44,6 @@ LL | 1f32 as i32;
4444 |
4545 = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
4646 = 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- | ~~~~~~~~~~~~~~~~~~~
5147
5248error: casting `f32` to `u32` may truncate the value
5349 --> $DIR/cast.rs:25:5
@@ -56,10 +52,6 @@ LL | 1f32 as u32;
5652 | ^^^^^^^^^^^
5753 |
5854 = 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- | ~~~~~~~~~~~~~~~~~~~
6355
6456error: casting `f32` to `u32` may lose the sign of the value
6557 --> $DIR/cast.rs:25:5
@@ -76,10 +68,6 @@ LL | 1f64 as f32;
7668 | ^^^^^^^^^^^
7769 |
7870 = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
79- help: ... or use `try_from` and handle the error accordingly
80- |
81- LL | f32::try_from(1f64);
82- | ~~~~~~~~~~~~~~~~~~~
8371
8472error: casting `i32` to `i8` may truncate the value
8573 --> $DIR/cast.rs:27:5
@@ -112,10 +100,6 @@ LL | 1f64 as isize;
112100 | ^^^^^^^^^^^^^
113101 |
114102 = 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- | ~~~~~~~~~~~~~~~~~~~~~
119103
120104error: casting `f64` to `usize` may truncate the value
121105 --> $DIR/cast.rs:30:5
@@ -124,10 +108,6 @@ LL | 1f64 as usize;
124108 | ^^^^^^^^^^^^^
125109 |
126110 = 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- | ~~~~~~~~~~~~~~~~~~~~~
131111
132112error: casting `f64` to `usize` may lose the sign of the value
133113 --> $DIR/cast.rs:30:5
@@ -154,63 +134,101 @@ LL | 1f32 as u32 as u16;
154134 | ^^^^^^^^^^^
155135 |
156136 = 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- | ~~~~~~~~~~~~~~~~~~~
161137
162138error: casting `f32` to `u32` may lose the sign of the value
163139 --> $DIR/cast.rs:31:5
164140 |
165141LL | 1f32 as u32 as u16;
166142 | ^^^^^^^^^^^
167143
144+ error: casting `i32` to `i8` may truncate the value
145+ --> $DIR/cast.rs:33:22
146+ |
147+ LL | let _x: i8 = 1i32 as _;
148+ | ^^^^^^^^^
149+ |
150+ = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
151+ help: ... or use `try_from` and handle the error accordingly
152+ |
153+ LL | let _x: i8 = 1i32.try_into();
154+ | ~~~~~~~~~~~~~~~
155+
156+ error: casting `f32` to `i32` may truncate the value
157+ --> $DIR/cast.rs:34:9
158+ |
159+ LL | 1f32 as i32;
160+ | ^^^^^^^^^^^
161+ |
162+ = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
163+
164+ error: casting `f64` to `i32` may truncate the value
165+ --> $DIR/cast.rs:35:9
166+ |
167+ LL | 1f64 as i32;
168+ | ^^^^^^^^^^^
169+ |
170+ = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
171+
172+ error: casting `f32` to `u8` may truncate the value
173+ --> $DIR/cast.rs:36:9
174+ |
175+ LL | 1f32 as u8;
176+ | ^^^^^^^^^^
177+ |
178+ = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
179+
180+ error: casting `f32` to `u8` may lose the sign of the value
181+ --> $DIR/cast.rs:36:9
182+ |
183+ LL | 1f32 as u8;
184+ | ^^^^^^^^^^
185+
168186error: casting `u8` to `i8` may wrap around the value
169- --> $DIR/cast.rs:33 :5
187+ --> $DIR/cast.rs:39 :5
170188 |
171189LL | 1u8 as i8;
172190 | ^^^^^^^^^
173191 |
174192 = note: `-D clippy::cast-possible-wrap` implied by `-D warnings`
175193
176194error: casting `u16` to `i16` may wrap around the value
177- --> $DIR/cast.rs:34 :5
195+ --> $DIR/cast.rs:40 :5
178196 |
179197LL | 1u16 as i16;
180198 | ^^^^^^^^^^^
181199
182200error: casting `u32` to `i32` may wrap around the value
183- --> $DIR/cast.rs:35 :5
201+ --> $DIR/cast.rs:41 :5
184202 |
185203LL | 1u32 as i32;
186204 | ^^^^^^^^^^^
187205
188206error: casting `u64` to `i64` may wrap around the value
189- --> $DIR/cast.rs:36 :5
207+ --> $DIR/cast.rs:42 :5
190208 |
191209LL | 1u64 as i64;
192210 | ^^^^^^^^^^^
193211
194212error: casting `usize` to `isize` may wrap around the value
195- --> $DIR/cast.rs:37 :5
213+ --> $DIR/cast.rs:43 :5
196214 |
197215LL | 1usize as isize;
198216 | ^^^^^^^^^^^^^^^
199217
200218error: casting `i32` to `u32` may lose the sign of the value
201- --> $DIR/cast.rs:40 :5
219+ --> $DIR/cast.rs:46 :5
202220 |
203221LL | -1i32 as u32;
204222 | ^^^^^^^^^^^^
205223
206224error: casting `isize` to `usize` may lose the sign of the value
207- --> $DIR/cast.rs:42 :5
225+ --> $DIR/cast.rs:48 :5
208226 |
209227LL | -1isize as usize;
210228 | ^^^^^^^^^^^^^^^^
211229
212230error: casting `i64` to `i8` may truncate the value
213- --> $DIR/cast.rs:109 :5
231+ --> $DIR/cast.rs:115 :5
214232 |
215233LL | (-99999999999i64).min(1) as i8; // should be linted because signed
216234 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -222,7 +240,7 @@ LL | i8::try_from((-99999999999i64).min(1)); // should be linted because sig
222240 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
223241
224242error: casting `u64` to `u8` may truncate the value
225- --> $DIR/cast.rs:121 :5
243+ --> $DIR/cast.rs:127 :5
226244 |
227245LL | 999999u64.clamp(0, 256) as u8; // should still be linted
228246 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -234,7 +252,7 @@ LL | u8::try_from(999999u64.clamp(0, 256)); // should still be linted
234252 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
235253
236254error: casting `main::E2` to `u8` may truncate the value
237- --> $DIR/cast.rs:142 :21
255+ --> $DIR/cast.rs:148 :21
238256 |
239257LL | let _ = self as u8;
240258 | ^^^^^^^^^^
@@ -246,15 +264,15 @@ LL | let _ = u8::try_from(self);
246264 | ~~~~~~~~~~~~~~~~~~
247265
248266error: casting `main::E2::B` to `u8` will truncate the value
249- --> $DIR/cast.rs:143 :21
267+ --> $DIR/cast.rs:149 :21
250268 |
251269LL | let _ = Self::B as u8;
252270 | ^^^^^^^^^^^^^
253271 |
254272 = note: `-D clippy::cast-enum-truncation` implied by `-D warnings`
255273
256274error: casting `main::E5` to `i8` may truncate the value
257- --> $DIR/cast.rs:179 :21
275+ --> $DIR/cast.rs:185 :21
258276 |
259277LL | let _ = self as i8;
260278 | ^^^^^^^^^^
@@ -266,13 +284,13 @@ LL | let _ = i8::try_from(self);
266284 | ~~~~~~~~~~~~~~~~~~
267285
268286error: casting `main::E5::A` to `i8` will truncate the value
269- --> $DIR/cast.rs:180 :21
287+ --> $DIR/cast.rs:186 :21
270288 |
271289LL | let _ = Self::A as i8;
272290 | ^^^^^^^^^^^^^
273291
274292error: casting `main::E6` to `i16` may truncate the value
275- --> $DIR/cast.rs:194 :21
293+ --> $DIR/cast.rs:200 :21
276294 |
277295LL | let _ = self as i16;
278296 | ^^^^^^^^^^^
@@ -284,7 +302,7 @@ LL | let _ = i16::try_from(self);
284302 | ~~~~~~~~~~~~~~~~~~~
285303
286304error: casting `main::E7` to `usize` may truncate the value on targets with 32-bit wide pointers
287- --> $DIR/cast.rs:209 :21
305+ --> $DIR/cast.rs:215 :21
288306 |
289307LL | let _ = self as usize;
290308 | ^^^^^^^^^^^^^
@@ -296,7 +314,7 @@ LL | let _ = usize::try_from(self);
296314 | ~~~~~~~~~~~~~~~~~~~~~
297315
298316error: casting `main::E10` to `u16` may truncate the value
299- --> $DIR/cast.rs:250 :21
317+ --> $DIR/cast.rs:256 :21
300318 |
301319LL | let _ = self as u16;
302320 | ^^^^^^^^^^^
@@ -308,28 +326,28 @@ LL | let _ = u16::try_from(self);
308326 | ~~~~~~~~~~~~~~~~~~~
309327
310328error: casting `u32` to `u8` may truncate the value
311- --> $DIR/cast.rs:258 :13
329+ --> $DIR/cast.rs:264 :13
312330 |
313331LL | let c = (q >> 16) as u8;
314332 | ^^^^^^^^^^^^^^^
315333 |
316334 = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
317335help: ... or use `try_from` and handle the error accordingly
318336 |
319- LL | let c = u8::try_from(( q >> 16) );
320- | ~~~~~~~~~~~~~~~~~~~~~~~
337+ LL | let c = u8::try_from(q >> 16);
338+ | ~~~~~~~~~~~~~~~~~~~~~
321339
322340error: casting `u32` to `u8` may truncate the value
323- --> $DIR/cast.rs:261 :13
341+ --> $DIR/cast.rs:267 :13
324342 |
325343LL | let c = (q / 1000) as u8;
326344 | ^^^^^^^^^^^^^^^^
327345 |
328346 = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
329347help: ... or use `try_from` and handle the error accordingly
330348 |
331- LL | let c = u8::try_from(( q / 1000) );
332- | ~~~~~~~~~~~~~~~~~~~~~~~~
349+ LL | let c = u8::try_from(q / 1000);
350+ | ~~~~~~~~~~~~~~~~~~~~~~
333351
334- error: aborting due to 36 previous errors
352+ error: aborting due to 41 previous errors
335353
0 commit comments