Skip to content

Commit 8134d9e

Browse files
Add regression test for suppressing private_bounds lint in KnownLayout derive (#2791)
* Suppress `private_bounds` lint in `KnownLayout` derive This commit suppresses the `private_bounds` lint on the `__ZerocopyKnownLayoutMaybeUninit` struct generated by `#[derive(KnownLayout)]`. This lint can be falsely triggered when the derive macro is used on a public struct within a `macro_rules!` macro, where the generated code refers to private types (field indices) that are technically "more private" than the public struct, even though they are in the same module scope. Fixes #2177. * Suppress `private_bounds` lint in `KnownLayout` derive This commit suppresses the `private_bounds` lint on the `__ZerocopyKnownLayoutMaybeUninit` struct generated by `#[derive(KnownLayout)]`. This lint can be falsely triggered when the derive macro is used on a public struct within a `macro_rules!` macro, where the generated code refers to private types (field indices) that are technically "more private" than the public struct, even though they are in the same module scope. Fixes #2177. --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent e781936 commit 8134d9e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

zerocopy-derive/tests/hygiene.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,23 @@ util_assert_impl_all!(
3636
_zerocopy::FromBytes,
3737
_zerocopy::Unaligned
3838
);
39+
40+
// Regression test for #2177.
41+
//
42+
// This test ensures that `#[derive(KnownLayout)]` does not trigger the
43+
// `private_bounds` lint when used on a public struct in a macro.
44+
mod issue_2177 {
45+
#![deny(private_bounds)]
46+
// We need to access `_zerocopy` from the parent module.
47+
use super::_zerocopy;
48+
49+
macro_rules! define {
50+
($name:ident, $repr:ty) => {
51+
#[derive(_zerocopy::KnownLayout)]
52+
#[repr(C)]
53+
pub struct $name($repr);
54+
};
55+
}
56+
57+
define!(Foo, u8);
58+
}

0 commit comments

Comments
 (0)