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