Skip to content

KnownLayout violates private-in-public rules in some cases #1292

@joshlf

Description

@joshlf

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.

Metadata

Metadata

Assignees

Labels

blocked-on-rustBlocked on a Rust feature landing or stabilizingbugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions