@@ -135,52 +135,82 @@ error: casting `f64` to `usize` may lose the sign of the value
135135LL | 1f64 as usize;
136136 | ^^^^^^^^^^^^^
137137
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+
138168error: casting `u8` to `i8` may wrap around the value
139- --> $DIR/cast.rs:32 :5
169+ --> $DIR/cast.rs:33 :5
140170 |
141171LL | 1u8 as i8;
142172 | ^^^^^^^^^
143173 |
144174 = note: `-D clippy::cast-possible-wrap` implied by `-D warnings`
145175
146176error: casting `u16` to `i16` may wrap around the value
147- --> $DIR/cast.rs:33 :5
177+ --> $DIR/cast.rs:34 :5
148178 |
149179LL | 1u16 as i16;
150180 | ^^^^^^^^^^^
151181
152182error: casting `u32` to `i32` may wrap around the value
153- --> $DIR/cast.rs:34 :5
183+ --> $DIR/cast.rs:35 :5
154184 |
155185LL | 1u32 as i32;
156186 | ^^^^^^^^^^^
157187
158188error: casting `u64` to `i64` may wrap around the value
159- --> $DIR/cast.rs:35 :5
189+ --> $DIR/cast.rs:36 :5
160190 |
161191LL | 1u64 as i64;
162192 | ^^^^^^^^^^^
163193
164194error: casting `usize` to `isize` may wrap around the value
165- --> $DIR/cast.rs:36 :5
195+ --> $DIR/cast.rs:37 :5
166196 |
167197LL | 1usize as isize;
168198 | ^^^^^^^^^^^^^^^
169199
170200error: casting `i32` to `u32` may lose the sign of the value
171- --> $DIR/cast.rs:39 :5
201+ --> $DIR/cast.rs:40 :5
172202 |
173203LL | -1i32 as u32;
174204 | ^^^^^^^^^^^^
175205
176206error: casting `isize` to `usize` may lose the sign of the value
177- --> $DIR/cast.rs:41 :5
207+ --> $DIR/cast.rs:42 :5
178208 |
179209LL | -1isize as usize;
180210 | ^^^^^^^^^^^^^^^^
181211
182212error: casting `i64` to `i8` may truncate the value
183- --> $DIR/cast.rs:108 :5
213+ --> $DIR/cast.rs:109 :5
184214 |
185215LL | (-99999999999i64).min(1) as i8; // should be linted because signed
186216 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -192,7 +222,7 @@ LL | i8::try_from((-99999999999i64).min(1)); // should be linted because sig
192222 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
193223
194224error: casting `u64` to `u8` may truncate the value
195- --> $DIR/cast.rs:120 :5
225+ --> $DIR/cast.rs:121 :5
196226 |
197227LL | 999999u64.clamp(0, 256) as u8; // should still be linted
198228 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -204,7 +234,7 @@ LL | u8::try_from(999999u64.clamp(0, 256)); // should still be linted
204234 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
205235
206236error: casting `main::E2` to `u8` may truncate the value
207- --> $DIR/cast.rs:141 :21
237+ --> $DIR/cast.rs:142 :21
208238 |
209239LL | let _ = self as u8;
210240 | ^^^^^^^^^^
@@ -216,15 +246,15 @@ LL | let _ = u8::try_from(self);
216246 | ~~~~~~~~~~~~~~~~~~
217247
218248error: casting `main::E2::B` to `u8` will truncate the value
219- --> $DIR/cast.rs:142 :21
249+ --> $DIR/cast.rs:143 :21
220250 |
221251LL | let _ = Self::B as u8;
222252 | ^^^^^^^^^^^^^
223253 |
224254 = note: `-D clippy::cast-enum-truncation` implied by `-D warnings`
225255
226256error: casting `main::E5` to `i8` may truncate the value
227- --> $DIR/cast.rs:178 :21
257+ --> $DIR/cast.rs:179 :21
228258 |
229259LL | let _ = self as i8;
230260 | ^^^^^^^^^^
@@ -236,13 +266,13 @@ LL | let _ = i8::try_from(self);
236266 | ~~~~~~~~~~~~~~~~~~
237267
238268error: casting `main::E5::A` to `i8` will truncate the value
239- --> $DIR/cast.rs:179 :21
269+ --> $DIR/cast.rs:180 :21
240270 |
241271LL | let _ = Self::A as i8;
242272 | ^^^^^^^^^^^^^
243273
244274error: casting `main::E6` to `i16` may truncate the value
245- --> $DIR/cast.rs:193 :21
275+ --> $DIR/cast.rs:194 :21
246276 |
247277LL | let _ = self as i16;
248278 | ^^^^^^^^^^^
@@ -254,7 +284,7 @@ LL | let _ = i16::try_from(self);
254284 | ~~~~~~~~~~~~~~~~~~~
255285
256286error: 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
258288 |
259289LL | let _ = self as usize;
260290 | ^^^^^^^^^^^^^
@@ -266,7 +296,7 @@ LL | let _ = usize::try_from(self);
266296 | ~~~~~~~~~~~~~~~~~~~~~
267297
268298error: casting `main::E10` to `u16` may truncate the value
269- --> $DIR/cast.rs:249 :21
299+ --> $DIR/cast.rs:250 :21
270300 |
271301LL | let _ = self as u16;
272302 | ^^^^^^^^^^^
@@ -278,7 +308,7 @@ LL | let _ = u16::try_from(self);
278308 | ~~~~~~~~~~~~~~~~~~~
279309
280310error: casting `u32` to `u8` may truncate the value
281- --> $DIR/cast.rs:257 :13
311+ --> $DIR/cast.rs:258 :13
282312 |
283313LL | let c = (q >> 16) as u8;
284314 | ^^^^^^^^^^^^^^^
@@ -290,7 +320,7 @@ LL | let c = u8::try_from((q >> 16));
290320 | ~~~~~~~~~~~~~~~~~~~~~~~
291321
292322error: casting `u32` to `u8` may truncate the value
293- --> $DIR/cast.rs:260 :13
323+ --> $DIR/cast.rs:261 :13
294324 |
295325LL | let c = (q / 1000) as u8;
296326 | ^^^^^^^^^^^^^^^^
@@ -301,5 +331,5 @@ help: ... or use `try_from` and handle the error accordingly
301331LL | let c = u8::try_from((q / 1000));
302332 | ~~~~~~~~~~~~~~~~~~~~~~~~
303333
304- error: aborting due to 33 previous errors
334+ error: aborting due to 36 previous errors
305335
0 commit comments