Skip to content

Layout test should pass clippy borrow_as_ptr lint #2205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2192,7 +2192,7 @@ impl CodeGenerator for CompInfo {
quote! {
assert_eq!(
unsafe {
&(*(::#prefix::ptr::null::<#canonical_ident>())).#field_name as *const _ as usize
::#prefix::ptr::addr_of!((*(::#prefix::ptr::null::<#canonical_ident>())).#field_name) as usize
},
#field_offset,
concat!("Offset of field: ", stringify!(#canonical_ident), "::", stringify!(#field_name))
Expand Down
74 changes: 48 additions & 26 deletions tests/expectations/tests/16-byte-alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1>(
)))
.dport as *const _ as usize
::std::ptr::addr_of!(
(*(::std::ptr::null::<
rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1,
>()))
.dport
) as usize
},
0usize,
concat!(
Expand All @@ -58,9 +61,12 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1>(
)))
.sport as *const _ as usize
::std::ptr::addr_of!(
(*(::std::ptr::null::<
rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1,
>()))
.sport
) as usize
},
2usize,
concat!(
Expand All @@ -85,8 +91,10 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<rte_ipv4_tuple__bindgen_ty_1>())).sctp_tag
as *const _ as usize
::std::ptr::addr_of!(
(*(::std::ptr::null::<rte_ipv4_tuple__bindgen_ty_1>()))
.sctp_tag
) as usize
},
0usize,
concat!(
Expand Down Expand Up @@ -120,8 +128,9 @@ fn bindgen_test_layout_rte_ipv4_tuple() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<rte_ipv4_tuple>())).src_addr as *const _
as usize
::std::ptr::addr_of!(
(*(::std::ptr::null::<rte_ipv4_tuple>())).src_addr
) as usize
},
0usize,
concat!(
Expand All @@ -133,8 +142,9 @@ fn bindgen_test_layout_rte_ipv4_tuple() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<rte_ipv4_tuple>())).dst_addr as *const _
as usize
::std::ptr::addr_of!(
(*(::std::ptr::null::<rte_ipv4_tuple>())).dst_addr
) as usize
},
4usize,
concat!(
Expand Down Expand Up @@ -193,9 +203,12 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1>(
)))
.dport as *const _ as usize
::std::ptr::addr_of!(
(*(::std::ptr::null::<
rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1,
>()))
.dport
) as usize
},
0usize,
concat!(
Expand All @@ -207,9 +220,12 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1>(
)))
.sport as *const _ as usize
::std::ptr::addr_of!(
(*(::std::ptr::null::<
rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1,
>()))
.sport
) as usize
},
2usize,
concat!(
Expand All @@ -234,8 +250,10 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<rte_ipv6_tuple__bindgen_ty_1>())).sctp_tag
as *const _ as usize
::std::ptr::addr_of!(
(*(::std::ptr::null::<rte_ipv6_tuple__bindgen_ty_1>()))
.sctp_tag
) as usize
},
0usize,
concat!(
Expand Down Expand Up @@ -269,8 +287,9 @@ fn bindgen_test_layout_rte_ipv6_tuple() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<rte_ipv6_tuple>())).src_addr as *const _
as usize
::std::ptr::addr_of!(
(*(::std::ptr::null::<rte_ipv6_tuple>())).src_addr
) as usize
},
0usize,
concat!(
Expand All @@ -282,8 +301,9 @@ fn bindgen_test_layout_rte_ipv6_tuple() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<rte_ipv6_tuple>())).dst_addr as *const _
as usize
::std::ptr::addr_of!(
(*(::std::ptr::null::<rte_ipv6_tuple>())).dst_addr
) as usize
},
16usize,
concat!(
Expand Down Expand Up @@ -324,7 +344,8 @@ fn bindgen_test_layout_rte_thash_tuple() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<rte_thash_tuple>())).v4 as *const _ as usize
::std::ptr::addr_of!((*(::std::ptr::null::<rte_thash_tuple>())).v4)
as usize
},
0usize,
concat!(
Expand All @@ -336,7 +357,8 @@ fn bindgen_test_layout_rte_thash_tuple() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<rte_thash_tuple>())).v6 as *const _ as usize
::std::ptr::addr_of!((*(::std::ptr::null::<rte_thash_tuple>())).v6)
as usize
},
0usize,
concat!(
Expand Down
74 changes: 48 additions & 26 deletions tests/expectations/tests/16-byte-alignment_1_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1>(
)))
.dport as *const _ as usize
::std::ptr::addr_of!(
(*(::std::ptr::null::<
rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1,
>()))
.dport
) as usize
},
0usize,
concat!(
Expand All @@ -103,9 +106,12 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1>(
)))
.sport as *const _ as usize
::std::ptr::addr_of!(
(*(::std::ptr::null::<
rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1,
>()))
.sport
) as usize
},
2usize,
concat!(
Expand Down Expand Up @@ -135,8 +141,10 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<rte_ipv4_tuple__bindgen_ty_1>())).sctp_tag
as *const _ as usize
::std::ptr::addr_of!(
(*(::std::ptr::null::<rte_ipv4_tuple__bindgen_ty_1>()))
.sctp_tag
) as usize
},
0usize,
concat!(
Expand Down Expand Up @@ -166,8 +174,9 @@ fn bindgen_test_layout_rte_ipv4_tuple() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<rte_ipv4_tuple>())).src_addr as *const _
as usize
::std::ptr::addr_of!(
(*(::std::ptr::null::<rte_ipv4_tuple>())).src_addr
) as usize
},
0usize,
concat!(
Expand All @@ -179,8 +188,9 @@ fn bindgen_test_layout_rte_ipv4_tuple() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<rte_ipv4_tuple>())).dst_addr as *const _
as usize
::std::ptr::addr_of!(
(*(::std::ptr::null::<rte_ipv4_tuple>())).dst_addr
) as usize
},
4usize,
concat!(
Expand Down Expand Up @@ -237,9 +247,12 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1>(
)))
.dport as *const _ as usize
::std::ptr::addr_of!(
(*(::std::ptr::null::<
rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1,
>()))
.dport
) as usize
},
0usize,
concat!(
Expand All @@ -251,9 +264,12 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1>(
)))
.sport as *const _ as usize
::std::ptr::addr_of!(
(*(::std::ptr::null::<
rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1,
>()))
.sport
) as usize
},
2usize,
concat!(
Expand Down Expand Up @@ -283,8 +299,10 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<rte_ipv6_tuple__bindgen_ty_1>())).sctp_tag
as *const _ as usize
::std::ptr::addr_of!(
(*(::std::ptr::null::<rte_ipv6_tuple__bindgen_ty_1>()))
.sctp_tag
) as usize
},
0usize,
concat!(
Expand Down Expand Up @@ -314,8 +332,9 @@ fn bindgen_test_layout_rte_ipv6_tuple() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<rte_ipv6_tuple>())).src_addr as *const _
as usize
::std::ptr::addr_of!(
(*(::std::ptr::null::<rte_ipv6_tuple>())).src_addr
) as usize
},
0usize,
concat!(
Expand All @@ -327,8 +346,9 @@ fn bindgen_test_layout_rte_ipv6_tuple() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<rte_ipv6_tuple>())).dst_addr as *const _
as usize
::std::ptr::addr_of!(
(*(::std::ptr::null::<rte_ipv6_tuple>())).dst_addr
) as usize
},
16usize,
concat!(
Expand Down Expand Up @@ -360,7 +380,8 @@ fn bindgen_test_layout_rte_thash_tuple() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<rte_thash_tuple>())).v4 as *const _ as usize
::std::ptr::addr_of!((*(::std::ptr::null::<rte_thash_tuple>())).v4)
as usize
},
0usize,
concat!(
Expand All @@ -372,7 +393,8 @@ fn bindgen_test_layout_rte_thash_tuple() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<rte_thash_tuple>())).v6 as *const _ as usize
::std::ptr::addr_of!((*(::std::ptr::null::<rte_thash_tuple>())).v6)
as usize
},
0usize,
concat!(
Expand Down
Loading