From 7da834977fcf69b5e8b642226433e67ca15dac32 Mon Sep 17 00:00:00 2001 From: Xuewei Niu Date: Mon, 24 Apr 2023 13:58:11 +0800 Subject: [PATCH] dbs-utils: Fix clippy issues caused by rust 1.68.2 Obtaining reference of unaligned fields is being phased out. Therefore, `&struct.field` is replaced with `std::ptr::addr_of!(struct.field)` to avoid those warning issues. For more details, please refer to https://github.com/rust-lang/rust/issues/82523. Fixes: #273 Signed-off-by: Xuewei Niu --- crates/dbs-utils/src/net/net_gen/if_tun.rs | 8 +++++--- crates/dbs-utils/src/net/net_gen/mod.rs | 1 - 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/dbs-utils/src/net/net_gen/if_tun.rs b/crates/dbs-utils/src/net/net_gen/if_tun.rs index 9d10f9ca..45cf21a4 100644 --- a/crates/dbs-utils/src/net/net_gen/if_tun.rs +++ b/crates/dbs-utils/src/net/net_gen/if_tun.rs @@ -347,8 +347,10 @@ fn bindgen_test_layout_ethhdr() { 1usize, concat!("Alignment of ", stringify!(ethhdr)) ); + let ethhdr_test = ethhdr::default(); + let p_ethhdr_test = ðhdr_test as *const ethhdr as usize; assert_eq!( - unsafe { &(*(0 as *const ethhdr)).h_dest as *const _ as usize }, + std::ptr::addr_of!(ethhdr_test.h_dest) as usize - p_ethhdr_test, 0usize, concat!( "Alignment of field: ", @@ -358,7 +360,7 @@ fn bindgen_test_layout_ethhdr() { ) ); assert_eq!( - unsafe { &(*(0 as *const ethhdr)).h_source as *const _ as usize }, + std::ptr::addr_of!(ethhdr_test.h_source) as usize - p_ethhdr_test, 6usize, concat!( "Alignment of field: ", @@ -368,7 +370,7 @@ fn bindgen_test_layout_ethhdr() { ) ); assert_eq!( - unsafe { &(*(0 as *const ethhdr)).h_proto as *const _ as usize }, + std::ptr::addr_of!(ethhdr_test.h_proto) as usize - p_ethhdr_test, 12usize, concat!( "Alignment of field: ", diff --git a/crates/dbs-utils/src/net/net_gen/mod.rs b/crates/dbs-utils/src/net/net_gen/mod.rs index 7db148d5..69bea8b7 100644 --- a/crates/dbs-utils/src/net/net_gen/mod.rs +++ b/crates/dbs-utils/src/net/net_gen/mod.rs @@ -6,7 +6,6 @@ #![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] #![allow(non_snake_case)] -#![allow(unaligned_references)] #![allow(missing_docs)] #![allow(deref_nullptr)]