Skip to content

Commit b7d9355

Browse files
committed
Fix unnecessary transmute warnings
1 parent 1448bc5 commit b7d9355

2 files changed

Lines changed: 4 additions & 9 deletions

File tree

vm/src/asm.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::fmt;
22
use std::convert::{TryFrom};
33
use std::collections::HashMap;
44
use std::collections::HashSet;
5-
use std::mem::transmute;
65
use crate::vm::{Op};
76
use crate::program::*;
87

@@ -843,8 +842,7 @@ impl Assembler
843842
// 32-bit floating-point value
844843
"f32" => {
845844
let val: f32 = input.parse_float()?;
846-
let val_u32: u32 = unsafe { transmute(val) };
847-
self.mem().push_u32(val_u32);
845+
self.mem().push_u32(val.to_bits());
848846
}
849847

850848
// Command to read an arbitrary number of bytes
@@ -1003,9 +1001,8 @@ impl Assembler
10031001
// Push a 32-bit floating-point value
10041002
"push_f32" => {
10051003
let val: f32 = input.parse_float()?;
1006-
let val_u32: u32 = unsafe { transmute(val) };
10071004
self.code.push_op(Op::push_u32);
1008-
self.code.push_u32(val_u32);
1005+
self.code.push_u32(val.to_bits());
10091006
}
10101007

10111008
// Variable-size push

vm/src/vm.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,7 @@ impl Value
348348

349349
pub fn as_f32(&self) -> f32 {
350350
let Value(val) = *self;
351-
let val = val as i32;
352-
unsafe { transmute(val) }
351+
f32::from_bits(val as u32)
353352
}
354353
}
355354

@@ -409,8 +408,7 @@ impl From<i64> for Value {
409408

410409
impl From<f32> for Value {
411410
fn from(val: f32) -> Self {
412-
let val: u32 = unsafe { transmute(val) };
413-
Value(val as u64)
411+
Value(val.to_bits() as u64)
414412
}
415413
}
416414

0 commit comments

Comments
 (0)