Skip to content

Commit 23c03e4

Browse files
Move transmute_float_to_int test cases into separate file
`transmute.stderr` file line count exceeded due to the new test cases so moving the new test cases into a separate file.
1 parent c77fc06 commit 23c03e4

File tree

4 files changed

+61
-57
lines changed

4 files changed

+61
-57
lines changed

tests/ui/transmute.rs

-10
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,6 @@ fn int_to_float() {
126126
let _: f32 = unsafe { std::mem::transmute(0_i32) };
127127
}
128128

129-
#[warn(clippy::transmute_float_to_int)]
130-
fn float_to_int() {
131-
let _: u32 = unsafe { std::mem::transmute(1f32) };
132-
let _: i32 = unsafe { std::mem::transmute(1f32) };
133-
let _: u64 = unsafe { std::mem::transmute(1f64) };
134-
let _: i64 = unsafe { std::mem::transmute(1f64) };
135-
let _: u64 = unsafe { std::mem::transmute(1.0) };
136-
let _: u64 = unsafe { std::mem::transmute(-1.0) };
137-
}
138-
139129
fn bytes_to_str(b: &[u8], mb: &mut [u8]) {
140130
let _: &str = unsafe { std::mem::transmute(b) };
141131
let _: &mut str = unsafe { std::mem::transmute(mb) };

tests/ui/transmute.stderr

+9-47
Original file line numberDiff line numberDiff line change
@@ -190,95 +190,57 @@ error: transmute from a `i32` to a `f32`
190190
LL | let _: f32 = unsafe { std::mem::transmute(0_i32) };
191191
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_i32 as u32)`
192192

193-
error: transmute from a `f32` to a `u32`
194-
--> $DIR/transmute.rs:131:27
195-
|
196-
LL | let _: u32 = unsafe { std::mem::transmute(1f32) };
197-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f32.to_bits()`
198-
|
199-
= note: `-D clippy::transmute-float-to-int` implied by `-D warnings`
200-
201-
error: transmute from a `f32` to a `i32`
202-
--> $DIR/transmute.rs:132:27
203-
|
204-
LL | let _: i32 = unsafe { std::mem::transmute(1f32) };
205-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f32.to_bits() as i32`
206-
207-
error: transmute from a `f64` to a `u64`
208-
--> $DIR/transmute.rs:133:27
209-
|
210-
LL | let _: u64 = unsafe { std::mem::transmute(1f64) };
211-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f64.to_bits()`
212-
213-
error: transmute from a `f64` to a `i64`
214-
--> $DIR/transmute.rs:134:27
215-
|
216-
LL | let _: i64 = unsafe { std::mem::transmute(1f64) };
217-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f64.to_bits() as i64`
218-
219-
error: transmute from a `f64` to a `u64`
220-
--> $DIR/transmute.rs:135:27
221-
|
222-
LL | let _: u64 = unsafe { std::mem::transmute(1.0) };
223-
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1.0f64.to_bits()`
224-
225-
error: transmute from a `f64` to a `u64`
226-
--> $DIR/transmute.rs:136:27
227-
|
228-
LL | let _: u64 = unsafe { std::mem::transmute(-1.0) };
229-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-1.0f64).to_bits()`
230-
231193
error: transmute from a `&[u8]` to a `&str`
232-
--> $DIR/transmute.rs:140:28
194+
--> $DIR/transmute.rs:130:28
233195
|
234196
LL | let _: &str = unsafe { std::mem::transmute(b) };
235197
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8(b).unwrap()`
236198
|
237199
= note: `-D clippy::transmute-bytes-to-str` implied by `-D warnings`
238200

239201
error: transmute from a `&mut [u8]` to a `&mut str`
240-
--> $DIR/transmute.rs:141:32
202+
--> $DIR/transmute.rs:131:32
241203
|
242204
LL | let _: &mut str = unsafe { std::mem::transmute(mb) };
243205
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8_mut(mb).unwrap()`
244206

245207
error: transmute from a pointer to a pointer
246-
--> $DIR/transmute.rs:173:29
208+
--> $DIR/transmute.rs:163:29
247209
|
248210
LL | let _: *const f32 = std::mem::transmute(ptr);
249211
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr as *const f32`
250212
|
251213
= note: `-D clippy::transmute-ptr-to-ptr` implied by `-D warnings`
252214

253215
error: transmute from a pointer to a pointer
254-
--> $DIR/transmute.rs:174:27
216+
--> $DIR/transmute.rs:164:27
255217
|
256218
LL | let _: *mut f32 = std::mem::transmute(mut_ptr);
257219
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `mut_ptr as *mut f32`
258220

259221
error: transmute from a reference to a reference
260-
--> $DIR/transmute.rs:176:23
222+
--> $DIR/transmute.rs:166:23
261223
|
262224
LL | let _: &f32 = std::mem::transmute(&1u32);
263225
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&1u32 as *const u32 as *const f32)`
264226

265227
error: transmute from a reference to a reference
266-
--> $DIR/transmute.rs:177:23
228+
--> $DIR/transmute.rs:167:23
267229
|
268230
LL | let _: &f64 = std::mem::transmute(&1f32);
269231
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&1f32 as *const f32 as *const f64)`
270232

271233
error: transmute from a reference to a reference
272-
--> $DIR/transmute.rs:180:27
234+
--> $DIR/transmute.rs:170:27
273235
|
274236
LL | let _: &mut f32 = std::mem::transmute(&mut 1u32);
275237
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *(&mut 1u32 as *mut u32 as *mut f32)`
276238

277239
error: transmute from a reference to a reference
278-
--> $DIR/transmute.rs:181:37
240+
--> $DIR/transmute.rs:171:37
279241
|
280242
LL | let _: &GenericParam<f32> = std::mem::transmute(&GenericParam { t: 1u32 });
281243
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&GenericParam { t: 1u32 } as *const GenericParam<u32> as *const GenericParam<f32>)`
282244

283-
error: aborting due to 44 previous errors
245+
error: aborting due to 38 previous errors
284246

tests/ui/transmute_float_to_int.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#[warn(clippy::transmute_float_to_int)]
2+
3+
fn float_to_int() {
4+
let _: u32 = unsafe { std::mem::transmute(1f32) };
5+
let _: i32 = unsafe { std::mem::transmute(1f32) };
6+
let _: u64 = unsafe { std::mem::transmute(1f64) };
7+
let _: i64 = unsafe { std::mem::transmute(1f64) };
8+
let _: u64 = unsafe { std::mem::transmute(1.0) };
9+
let _: u64 = unsafe { std::mem::transmute(-1.0) };
10+
}
11+
12+
fn main() {}
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
error: transmute from a `f32` to a `u32`
2+
--> $DIR/transmute_float_to_int.rs:4:27
3+
|
4+
LL | let _: u32 = unsafe { std::mem::transmute(1f32) };
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f32.to_bits()`
6+
|
7+
= note: `-D clippy::transmute-float-to-int` implied by `-D warnings`
8+
9+
error: transmute from a `f32` to a `i32`
10+
--> $DIR/transmute_float_to_int.rs:5:27
11+
|
12+
LL | let _: i32 = unsafe { std::mem::transmute(1f32) };
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f32.to_bits() as i32`
14+
15+
error: transmute from a `f64` to a `u64`
16+
--> $DIR/transmute_float_to_int.rs:6:27
17+
|
18+
LL | let _: u64 = unsafe { std::mem::transmute(1f64) };
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f64.to_bits()`
20+
21+
error: transmute from a `f64` to a `i64`
22+
--> $DIR/transmute_float_to_int.rs:7:27
23+
|
24+
LL | let _: i64 = unsafe { std::mem::transmute(1f64) };
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f64.to_bits() as i64`
26+
27+
error: transmute from a `f64` to a `u64`
28+
--> $DIR/transmute_float_to_int.rs:8:27
29+
|
30+
LL | let _: u64 = unsafe { std::mem::transmute(1.0) };
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1.0f64.to_bits()`
32+
33+
error: transmute from a `f64` to a `u64`
34+
--> $DIR/transmute_float_to_int.rs:9:27
35+
|
36+
LL | let _: u64 = unsafe { std::mem::transmute(-1.0) };
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-1.0f64).to_bits()`
38+
39+
error: aborting due to 6 previous errors
40+

0 commit comments

Comments
 (0)