@@ -41,14 +41,22 @@ fn main() {
41
41
1u32 as i32 ;
42
42
1u64 as i64 ;
43
43
1usize as isize ;
44
- 1usize as i8 ; // should not wrap, usize is never 8 bits
45
- 1usize as i16 ; // wraps on 16 bit ptr size
46
- 1usize as i32 ; // wraps on 32 bit ptr size
47
- 1usize as i64 ; // wraps on 64 bit ptr size
48
- 1u8 as isize ; // should not wrap, isize is never 8 bits
49
- 1u16 as isize ; // wraps on 16 bit ptr size
50
- 1u32 as isize ; // wraps on 32 bit ptr size
51
- 1u64 as isize ; // wraps on 64 bit ptr size
44
+ // should not wrap, usize is never 8 bits
45
+ 1usize as i8 ;
46
+ // wraps on 16 bit ptr size
47
+ 1usize as i16 ;
48
+ // wraps on 32 bit ptr size
49
+ 1usize as i32 ;
50
+ // wraps on 64 bit ptr size
51
+ 1usize as i64 ;
52
+ // should not wrap, isize is never 8 bits
53
+ 1u8 as isize ;
54
+ // wraps on 16 bit ptr size
55
+ 1u16 as isize ;
56
+ // wraps on 32 bit ptr size
57
+ 1u32 as isize ;
58
+ // wraps on 64 bit ptr size
59
+ 1u64 as isize ;
52
60
// Test clippy::cast_sign_loss
53
61
1i32 as u32 ;
54
62
-1i32 as u32 ;
@@ -120,7 +128,8 @@ fn main() {
120
128
let _ = s as i32 ;
121
129
122
130
// Test for signed min
123
- ( -99999999999i64 ) . min ( 1 ) as i8 ; // should be linted because signed
131
+ // should be linted because signed
132
+ ( -99999999999i64 ) . min ( 1 ) as i8 ;
124
133
125
134
// Test for various operations that remove enough bits for the result to fit
126
135
( 999999u64 & 1 ) as u8 ;
@@ -132,7 +141,8 @@ fn main() {
132
141
x. min ( 1 )
133
142
} ) as u8 ;
134
143
999999u64 . clamp ( 0 , 255 ) as u8 ;
135
- 999999u64 . clamp ( 0 , 256 ) as u8 ; // should still be linted
144
+ // should still be linted
145
+ 999999u64 . clamp ( 0 , 256 ) as u8 ;
136
146
137
147
#[ derive( Clone , Copy ) ]
138
148
enum E1 {
@@ -142,7 +152,8 @@ fn main() {
142
152
}
143
153
impl E1 {
144
154
fn test ( self ) {
145
- let _ = self as u8 ; // Don't lint. `0..=2` fits in u8
155
+ // Don't lint. `0..=2` fits in u8
156
+ let _ = self as u8 ;
146
157
}
147
158
}
148
159
@@ -155,8 +166,10 @@ fn main() {
155
166
fn test ( self ) {
156
167
let _ = self as u8 ;
157
168
let _ = Self :: B as u8 ;
158
- let _ = self as i16 ; // Don't lint. `255..=256` fits in i16
159
- let _ = Self :: A as u8 ; // Don't lint.
169
+ // Don't lint. `255..=256` fits in i16
170
+ let _ = self as i16 ;
171
+ // Don't lint.
172
+ let _ = Self :: A as u8 ;
160
173
}
161
174
}
162
175
@@ -168,7 +181,8 @@ fn main() {
168
181
}
169
182
impl E3 {
170
183
fn test ( self ) {
171
- let _ = self as i8 ; // Don't lint. `-1..=50` fits in i8
184
+ // Don't lint. `-1..=50` fits in i8
185
+ let _ = self as i8 ;
172
186
}
173
187
}
174
188
@@ -179,7 +193,8 @@ fn main() {
179
193
}
180
194
impl E4 {
181
195
fn test ( self ) {
182
- let _ = self as i8 ; // Don't lint. `-128..=-127` fits in i8
196
+ // Don't lint. `-128..=-127` fits in i8
197
+ let _ = self as i8 ;
183
198
}
184
199
}
185
200
@@ -192,8 +207,10 @@ fn main() {
192
207
fn test ( self ) {
193
208
let _ = self as i8 ;
194
209
let _ = Self :: A as i8 ;
195
- let _ = self as i16 ; // Don't lint. `-129..=127` fits in i16
196
- let _ = Self :: B as u8 ; // Don't lint.
210
+ // Don't lint. `-129..=127` fits in i16
211
+ let _ = self as i16 ;
212
+ // Don't lint.
213
+ let _ = Self :: B as u8 ;
197
214
}
198
215
}
199
216
@@ -206,9 +223,12 @@ fn main() {
206
223
impl E6 {
207
224
fn test ( self ) {
208
225
let _ = self as i16 ;
209
- let _ = Self :: A as u16 ; // Don't lint. `2^16-1` fits in u16
210
- let _ = self as u32 ; // Don't lint. `2^16-1..=2^16` fits in u32
211
- let _ = Self :: A as u16 ; // Don't lint.
226
+ // Don't lint. `2^16-1` fits in u16
227
+ let _ = Self :: A as u16 ;
228
+ // Don't lint. `2^16-1..=2^16` fits in u32
229
+ let _ = self as u32 ;
230
+ // Don't lint.
231
+ let _ = Self :: A as u16 ;
212
232
}
213
233
}
214
234
@@ -221,8 +241,10 @@ fn main() {
221
241
impl E7 {
222
242
fn test ( self ) {
223
243
let _ = self as usize ;
224
- let _ = Self :: A as usize ; // Don't lint.
225
- let _ = self as u64 ; // Don't lint. `2^32-1..=2^32` fits in u64
244
+ // Don't lint.
245
+ let _ = Self :: A as usize ;
246
+ // Don't lint. `2^32-1..=2^32` fits in u64
247
+ let _ = self as u64 ;
226
248
}
227
249
}
228
250
@@ -236,7 +258,8 @@ fn main() {
236
258
}
237
259
impl E8 {
238
260
fn test ( self ) {
239
- let _ = self as i128 ; // Don't lint. `-(2^127)..=2^127-1` fits it i128
261
+ // Don't lint. `-(2^127)..=2^127-1` fits it i128
262
+ let _ = self as i128 ;
240
263
}
241
264
}
242
265
@@ -248,8 +271,10 @@ fn main() {
248
271
}
249
272
impl E9 {
250
273
fn test ( self ) {
251
- let _ = Self :: A as u8 ; // Don't lint.
252
- let _ = self as u128 ; // Don't lint. `0..=2^128-1` fits in u128
274
+ // Don't lint.
275
+ let _ = Self :: A as u8 ;
276
+ // Don't lint. `0..=2^128-1` fits in u128
277
+ let _ = self as u128 ;
253
278
}
254
279
}
255
280
@@ -262,8 +287,10 @@ fn main() {
262
287
impl E10 {
263
288
fn test ( self ) {
264
289
let _ = self as u16 ;
265
- let _ = Self :: B as u32 ; // Don't lint.
266
- let _ = self as u64 ; // Don't lint.
290
+ // Don't lint.
291
+ let _ = Self :: B as u32 ;
292
+ // Don't lint.
293
+ let _ = self as u64 ;
267
294
}
268
295
}
269
296
}
0 commit comments