google/zerocopy

`KnownLayout` violates private-in-public rules in some cases

joshlf opened this issue · 2 comments

In some cases, #[derive(KnownLayout)] generates code like this:

trait KnownLayout {
    type PointerMetadata;
}

mod foo {
    use super::*;
    
    pub struct Foo {
        bar: Bar,
    }
    
    impl KnownLayout for Foo {
        type PointerMetadata = <Bar as KnownLayout>::PointerMetadata;
    }
    
    struct Bar;
    
    impl KnownLayout for Bar {
        type PointerMetadata = ();
    }
}

This causes a private-in-public error:

error[E0446]: private type `Bar` in public interface
  --> src/lib.rs:13:9
   |
13 |         type PointerMetadata = <Bar as KnownLayout>::PointerMetadata;
   |         ^^^^^^^^^^^^^^^^^^^^ can't leak private type
...
16 |     struct Bar;
   |     ---------- `Bar` declared as private

This is probably a rustc bug.

This is a compiler bug, and is tracked by rust-lang/rust#45713