`offset_of_slice` exposes whether a custom DST has a private slice field
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
The following program compiles:
#![feature(offset_of_slice)]
mod foo {
pub struct Inner {
foo: u8,
tail: [u8],
// tail: dyn core::fmt::Debug,
}
pub struct Outer {
pub dst: Inner,
}
}
fn main() {
assert_eq!(core::mem::offset_of!(foo::Outer, dst), 0);
}
It does not compile if the type of tail is changed to a dyn type. I believe neither version should compile, because tail is a private field, and therefore information about its type should not leak to places where it is not visible.
rustc version: 1.87.0-nightly (2025-03-09 3ea711f17e3946ac3f4d)
@rustbot label F-offset_of_slice C-bug
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file or test is named. Start by reproducing the provided program on the referenced nightly compiler, then trace the compiler's handling of offset_of! and privacy for custom DST fields. Done means both the private slice and private dyn-tail variants are rejected, with a regression test covering the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100