@@ -40,15 +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
45
= note: `-D clippy::cast-possible-truncation` implied by `-D warnings`
46
46
47
47
error: casting `f32` to `u32` may truncate the value
48
48
--> $DIR/cast.rs:25:5
49
49
|
50
50
LL | 1f32 as u32;
51
- | ^^^^^^^^^^^
51
+ | ^^^^^^^^^^^ help: avoid silent truncation by using: `u32::try_from(1f32).unwrap()`
52
52
53
53
error: casting `f32` to `u32` may lose the sign of the value
54
54
--> $DIR/cast.rs:25:5
@@ -62,31 +62,31 @@ error: casting `f64` to `f32` may truncate the value
62
62
--> $DIR/cast.rs:26:5
63
63
|
64
64
LL | 1f64 as f32;
65
- | ^^^^^^^^^^^
65
+ | ^^^^^^^^^^^ help: avoid silent truncation by using: `f32::try_from(1f64).unwrap()`
66
66
67
67
error: casting `i32` to `i8` may truncate the value
68
68
--> $DIR/cast.rs:27:5
69
69
|
70
70
LL | 1i32 as i8;
71
- | ^^^^^^^^^^
71
+ | ^^^^^^^^^^ help: avoid silent truncation by using: `i8::try_from(1i32).unwrap()`
72
72
73
73
error: casting `i32` to `u8` may truncate the value
74
74
--> $DIR/cast.rs:28:5
75
75
|
76
76
LL | 1i32 as u8;
77
- | ^^^^^^^^^^
77
+ | ^^^^^^^^^^ help: avoid silent truncation by using: `u8::try_from(1i32).unwrap()`
78
78
79
79
error: casting `f64` to `isize` may truncate the value
80
80
--> $DIR/cast.rs:29:5
81
81
|
82
82
LL | 1f64 as isize;
83
- | ^^^^^^^^^^^^^
83
+ | ^^^^^^^^^^^^^ help: avoid silent truncation by using: `isize::try_from(1f64).unwrap()`
84
84
85
85
error: casting `f64` to `usize` may truncate the value
86
86
--> $DIR/cast.rs:30:5
87
87
|
88
88
LL | 1f64 as usize;
89
- | ^^^^^^^^^^^^^
89
+ | ^^^^^^^^^^^^^ help: avoid silent truncation by using: `usize::try_from(1f64).unwrap()`
90
90
91
91
error: casting `f64` to `usize` may lose the sign of the value
92
92
--> $DIR/cast.rs:30:5
@@ -142,19 +142,19 @@ error: casting `i64` to `i8` may truncate the value
142
142
--> $DIR/cast.rs:108:5
143
143
|
144
144
LL | (-99999999999i64).min(1) as i8; // should be linted because signed
145
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
145
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: avoid silent truncation by using: `i8::try_from((-99999999999i64).min(1)).unwrap()`
146
146
147
147
error: casting `u64` to `u8` may truncate the value
148
148
--> $DIR/cast.rs:120:5
149
149
|
150
150
LL | 999999u64.clamp(0, 256) as u8; // should still be linted
151
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
151
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: avoid silent truncation by using: `u8::try_from(999999u64.clamp(0, 256)).unwrap()`
152
152
153
153
error: casting `main::E2` to `u8` may truncate the value
154
154
--> $DIR/cast.rs:141:21
155
155
|
156
156
LL | let _ = self as u8;
157
- | ^^^^^^^^^^
157
+ | ^^^^^^^^^^ help: avoid silent truncation by using: `u8::try_from(self).unwrap()`
158
158
159
159
error: casting `main::E2::B` to `u8` will truncate the value
160
160
--> $DIR/cast.rs:142:21
@@ -168,7 +168,7 @@ error: casting `main::E5` to `i8` may truncate the value
168
168
--> $DIR/cast.rs:178:21
169
169
|
170
170
LL | let _ = self as i8;
171
- | ^^^^^^^^^^
171
+ | ^^^^^^^^^^ help: avoid silent truncation by using: `i8::try_from(self).unwrap()`
172
172
173
173
error: casting `main::E5::A` to `i8` will truncate the value
174
174
--> $DIR/cast.rs:179:21
@@ -180,31 +180,31 @@ error: casting `main::E6` to `i16` may truncate the value
180
180
--> $DIR/cast.rs:193:21
181
181
|
182
182
LL | let _ = self as i16;
183
- | ^^^^^^^^^^^
183
+ | ^^^^^^^^^^^ help: avoid silent truncation by using: `i16::try_from(self).unwrap()`
184
184
185
185
error: casting `main::E7` to `usize` may truncate the value on targets with 32-bit wide pointers
186
186
--> $DIR/cast.rs:208:21
187
187
|
188
188
LL | let _ = self as usize;
189
- | ^^^^^^^^^^^^^
189
+ | ^^^^^^^^^^^^^ help: avoid silent truncation by using: `usize::try_from(self).unwrap()`
190
190
191
191
error: casting `main::E10` to `u16` may truncate the value
192
192
--> $DIR/cast.rs:249:21
193
193
|
194
194
LL | let _ = self as u16;
195
- | ^^^^^^^^^^^
195
+ | ^^^^^^^^^^^ help: avoid silent truncation by using: `u16::try_from(self).unwrap()`
196
196
197
197
error: casting `u32` to `u8` may truncate the value
198
198
--> $DIR/cast.rs:257:13
199
199
|
200
200
LL | let c = (q >> 16) as u8;
201
- | ^^^^^^^^^^^^^^^
201
+ | ^^^^^^^^^^^^^^^ help: avoid silent truncation by using: `u8::try_from((q >> 16)).unwrap()`
202
202
203
203
error: casting `u32` to `u8` may truncate the value
204
204
--> $DIR/cast.rs:260:13
205
205
|
206
206
LL | let c = (q / 1000) as u8;
207
- | ^^^^^^^^^^^^^^^^
207
+ | ^^^^^^^^^^^^^^^^ help: avoid silent truncation by using: `u8::try_from((q / 1000)).unwrap()`
208
208
209
209
error: aborting due to 33 previous errors
210
210
0 commit comments