Skip to content

Commit

Permalink
Clippy: transmute used without annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
mooman219 committed Nov 19, 2024
1 parent e81c191 commit 64b5213
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl Font {
if let Some(mapping) = subtable.glyph_index(codepoint) {
if let Some(mapping) = NonZeroU16::new(mapping.0) {
indices_to_load.insert(mapping.get());
char_to_glyph.insert(unsafe { mem::transmute(codepoint) }, mapping);
char_to_glyph.insert(unsafe { mem::transmute::<u32, char>(codepoint) }, mapping);
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/platform/float/get_bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn get_bitmap(a: &Vec<f32>, length: usize) -> Vec<u8> {
y = _mm_packus_epi16(_mm_packs_epi32(y, nzero), nzero);

// Store the first 4 u8s from y in output.
let pointer: &mut i32 = core::mem::transmute(output.get_unchecked_mut(i));
let pointer: &mut i32 = core::mem::transmute::<&mut u8, &mut i32>(output.get_unchecked_mut(i));
*pointer = core::mem::transmute::<__m128i, [i32; 4]>(y)[0];
// offset = (x[3], x[3], x[3], x[3])
offset = _mm_set1_ps(core::mem::transmute::<__m128, [f32; 4]>(x)[3]);
Expand Down
17 changes: 12 additions & 5 deletions src/platform/simd_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,24 @@ impl f32x4 {

#[inline(always)]
pub fn new_u32(x0: u32, x1: u32, x2: u32, x3: u32) -> Self {
unsafe { Self::new(transmute(x0), transmute(x1), transmute(x2), transmute(x3)) }
unsafe {
Self::new(
transmute::<u32, f32>(x0),
transmute::<u32, f32>(x1),
transmute::<u32, f32>(x2),
transmute::<u32, f32>(x3),
)
}
}

#[inline(always)]
pub fn sub_integer(&self, other: f32x4) -> f32x4 {
unsafe {
Self::new(
transmute(transmute::<f32, u32>(self.x0) - transmute::<f32, u32>(other.x0)),
transmute(transmute::<f32, u32>(self.x1) - transmute::<f32, u32>(other.x1)),
transmute(transmute::<f32, u32>(self.x2) - transmute::<f32, u32>(other.x2)),
transmute(transmute::<f32, u32>(self.x3) - transmute::<f32, u32>(other.x3)),
transmute::<u32, f32>(transmute::<f32, u32>(self.x0) - transmute::<f32, u32>(other.x0)),
transmute::<u32, f32>(transmute::<f32, u32>(self.x1) - transmute::<f32, u32>(other.x1)),
transmute::<u32, f32>(transmute::<f32, u32>(self.x2) - transmute::<f32, u32>(other.x2)),
transmute::<u32, f32>(transmute::<f32, u32>(self.x3) - transmute::<f32, u32>(other.x3)),
)
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/platform/simd_x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ impl f32x4 {
pub fn new_u32(x0: u32, x1: u32, x2: u32, x3: u32) -> Self {
f32x4(unsafe {
_mm_set_ps(
core::mem::transmute(x3),
core::mem::transmute(x2),
core::mem::transmute(x1),
core::mem::transmute(x0),
core::mem::transmute::<u32, f32>(x3),
core::mem::transmute::<u32, f32>(x2),
core::mem::transmute::<u32, f32>(x1),
core::mem::transmute::<u32, f32>(x0),
)
})
}
Expand All @@ -45,7 +45,7 @@ impl f32x4 {

#[inline(always)]
pub fn copied(self) -> (f32, f32, f32, f32) {
unsafe { core::mem::transmute(self.0) }
unsafe { core::mem::transmute::<__m128, (f32, f32, f32, f32)>(self.0) }
}

#[inline(always)]
Expand Down
12 changes: 6 additions & 6 deletions src/table/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ pub struct StreamSliceI32<'a>(StreamSliceU32<'a>);
impl<'a> StreamSliceI8<'a> {
#[inline]
pub fn get(&self, index: usize) -> Option<i8> {
Some(unsafe { core::mem::transmute(self.0.get(index)?) })
Some(unsafe { core::mem::transmute::<u8, i8>(self.0.get(index)?) })
}
}
impl<'a> StreamSliceI16<'a> {
#[inline]
pub fn get(&self, index: usize) -> Option<i16> {
Some(unsafe { core::mem::transmute(self.0.get(index)?) })
Some(unsafe { core::mem::transmute::<u16, i16>(self.0.get(index)?) })
}
}
impl<'a> StreamSliceI32<'a> {
#[inline]
pub fn get(&self, index: usize) -> Option<i32> {
Some(unsafe { core::mem::transmute(self.0.get(index)?) })
Some(unsafe { core::mem::transmute::<u32, i32>(self.0.get(index)?) })
}
}

Expand Down Expand Up @@ -164,17 +164,17 @@ impl<'a> Stream<'a> {

#[inline]
pub fn read_i8(&mut self) -> Option<i8> {
Some(unsafe { core::mem::transmute(self.read_u8()?) })
Some(unsafe { core::mem::transmute::<u8, i8>(self.read_u8()?) })
}

#[inline]
pub fn read_i16(&mut self) -> Option<i16> {
Some(unsafe { core::mem::transmute(self.read_u16()?) })
Some(unsafe { core::mem::transmute::<u16, i16>(self.read_u16()?) })
}

#[inline]
pub fn read_i32(&mut self) -> Option<i32> {
Some(unsafe { core::mem::transmute(self.read_u32()?) })
Some(unsafe { core::mem::transmute::<u32, i32>(self.read_u32()?) })
}

// FONT
Expand Down

0 comments on commit 64b5213

Please sign in to comment.