@@ -446,6 +446,40 @@ use {FromZeros as FromZeroes, IntoBytes as AsBytes, Ref as LayoutVerified};
446
446
///
447
447
/// This derive cannot currently be applied to unsized structs without an
448
448
/// explicit `repr` attribute.
449
+ ///
450
+ /// Some invocations of this derive run afoul of a [known bug] in Rust's type
451
+ /// privacy checker. For example, this code:
452
+ ///
453
+ /// ```compile_fail,E0446
454
+ /// use zerocopy::*;
455
+ /// # use zerocopy_derive::*;
456
+ ///
457
+ /// #[derive(KnownLayout)]
458
+ /// #[repr(C)]
459
+ /// pub struct PublicType(PrivateType);
460
+ ///
461
+ /// #[derive(KnownLayout)]
462
+ /// struct PrivateType;
463
+ /// ```
464
+ ///
465
+ /// ...results in a compilation error:
466
+ ///
467
+ /// ```text
468
+ /// error[E0446]: private type `PrivateType` in public interface
469
+ /// --> examples/bug.rs:3:10
470
+ /// |
471
+ /// 3 | #[derive(KnownLayout)]
472
+ /// | ^^^^^^^^^^^ can't leak private type
473
+ /// ...
474
+ /// 8 | struct PrivateType;
475
+ /// | ------------------- `PrivateType` declared as private
476
+ /// |
477
+ /// = note: this error originates in the derive macro `KnownLayout` (in Nightly builds, run with -Z macro-backtrace for more info)
478
+ /// ```
479
+ ///
480
+ /// To work around this bug, mark private field types as `pub` and annotate them with `#[doc(hidden)]`.
481
+ ///
482
+ /// [known bug]: https://github.com/rust-lang/rust/issues/45713
449
483
#[ cfg( any( feature = "derive" , test) ) ]
450
484
#[ cfg_attr( doc_cfg, doc( cfg( feature = "derive" ) ) ) ]
451
485
pub use zerocopy_derive:: KnownLayout ;
0 commit comments