google / google/zerocopy

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

Open
#1,292 2 comments 0 reactions 1 assignee Claimed by @jswrenn View on GitHub
blocked-on-rust bug
Dominant language
Rust
Stars
2.6k
Forks
179
Avg merge
1d 19h
Merged PRs (30d)
29

Description

In some cases, `#[derive(KnownLayout)]` generates [code like this](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=6eab52187622f8ff35e0f641aea6eb47):

```rust
trait KnownLayout {
type PointerMetadata;
}

mod foo {
use super::*;

pub struct Foo {
bar: Bar,
}

impl KnownLayout for Foo {
type PointerMetadata = ::PointerMetadata;
}

struct Bar;

impl KnownLayout for Bar {
type PointerMetadata = ();
}
}
```

This causes a private-in-public error:

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

This is probably a rustc bug.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.