Skip to content

Commit

Permalink
dbs-utils: Fix clippy issues caused by rust 1.68.2
Browse files Browse the repository at this point in the history
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
rust-lang/rust#82523.

Fixes: openanolis#273

Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
  • Loading branch information
justxuewei committed Apr 24, 2023
1 parent 9727ed4 commit 7da8349
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 5 additions & 3 deletions crates/dbs-utils/src/net/net_gen/if_tun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,10 @@ fn bindgen_test_layout_ethhdr() {
1usize,
concat!("Alignment of ", stringify!(ethhdr))
);
let ethhdr_test = ethhdr::default();
let p_ethhdr_test = &ethhdr_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: ",
Expand All @@ -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: ",
Expand All @@ -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: ",
Expand Down
1 change: 0 additions & 1 deletion crates/dbs-utils/src/net/net_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down

0 comments on commit 7da8349

Please sign in to comment.