Skip to content

Commit 3242afc

Browse files
committed
fix: avoid integer casts in function pointer example
1 parent 93907ab commit 3242afc

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

src/coding-guidelines/types-and-traits/gui_QbvIknd9qNF6.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,11 @@ Do not directly or indirectly compare function pointers
360360
361361
fn get_a() -> (u8, u8, u8, u8) {
362362
let mut a = MyMaybeUninit { init: (0, 0, 0, 0) };
363-
let addr1 = write_first as usize;
364-
let addr2 = write_second as usize;
363+
let addr1 = write_first as *const ();
364+
let addr2 = write_second as *const ();
365365
if addr1 == addr2 {
366366
unsafe {
367-
let ptr = addr1 as *const ();
368-
let f: fn(&mut MyMaybeUninit) = core::mem::transmute(ptr);
367+
let f: fn(&mut MyMaybeUninit) = core::mem::transmute(addr1);
369368
f(&mut a);
370369
}
371370
}

0 commit comments

Comments
 (0)