Skip to content

Commit c5caa45

Browse files
committed
[doc] Document rustc type privacy bug
See #1292 Makes progress towards #671
1 parent 73b15e5 commit c5caa45

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/lib.rs

+34
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,40 @@ use {FromZeros as FromZeroes, IntoBytes as AsBytes, Ref as LayoutVerified};
446446
///
447447
/// This derive cannot currently be applied to unsized structs without an
448448
/// 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
449483
#[cfg(any(feature = "derive", test))]
450484
#[cfg_attr(doc_cfg, doc(cfg(feature = "derive")))]
451485
pub use zerocopy_derive::KnownLayout;

0 commit comments

Comments
 (0)