Skip to content

Commit c47d442

Browse files
justxueweistudychao
authored andcommitted
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 rust-lang/rust#82523. Fixes: openanolis#273 Signed-off-by: Xuewei Niu <[email protected]>
1 parent 7ce416f commit c47d442

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

crates/dbs-utils/src/net/net_gen/if_tun.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,10 @@ fn bindgen_test_layout_ethhdr() {
347347
1usize,
348348
concat!("Alignment of ", stringify!(ethhdr))
349349
);
350+
let ethhdr_test = ethhdr::default();
351+
let p_ethhdr_test = &ethhdr_test as *const ethhdr as usize;
350352
assert_eq!(
351-
unsafe { &(*(0 as *const ethhdr)).h_dest as *const _ as usize },
353+
std::ptr::addr_of!(ethhdr_test.h_dest) as usize - p_ethhdr_test,
352354
0usize,
353355
concat!(
354356
"Alignment of field: ",
@@ -358,7 +360,7 @@ fn bindgen_test_layout_ethhdr() {
358360
)
359361
);
360362
assert_eq!(
361-
unsafe { &(*(0 as *const ethhdr)).h_source as *const _ as usize },
363+
std::ptr::addr_of!(ethhdr_test.h_source) as usize - p_ethhdr_test,
362364
6usize,
363365
concat!(
364366
"Alignment of field: ",
@@ -368,7 +370,7 @@ fn bindgen_test_layout_ethhdr() {
368370
)
369371
);
370372
assert_eq!(
371-
unsafe { &(*(0 as *const ethhdr)).h_proto as *const _ as usize },
373+
std::ptr::addr_of!(ethhdr_test.h_proto) as usize - p_ethhdr_test,
372374
12usize,
373375
concat!(
374376
"Alignment of field: ",

crates/dbs-utils/src/net/net_gen/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#![allow(non_upper_case_globals)]
77
#![allow(non_camel_case_types)]
88
#![allow(non_snake_case)]
9-
#![allow(unaligned_references)]
109
#![allow(missing_docs)]
1110
#![allow(deref_nullptr)]
1211

0 commit comments

Comments
 (0)