rust-lang / rust-lang/portable-simd
`PrivateMethods`' items aren't private, they are accessible via `MaskElement`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.1k
- Forks
- 108
- Avg merge
- 22h 53m
- Merged PRs (30d)
- 3
Description
A surprising new SemVer breakage case was discovered earlier this week, affecting sealed traits' associated items (consts, types, functions with or without receivers — everything) being accessible to subtraits. This is non-obvious and usually isn't intended by the authors of such code, which can lead to accidental breakage.
portable-simd has such an at-risk pattern here
mod private_methods {
pub impl(super) trait PrivateMethods {
fn valid<const N: usize>(values: Simd<Self, N>) -> bool
where
Self: SimdElement;
fn eq(self, other: Self) -> bool;
fn to_usize(self) -> usize;
fn max_unsigned() -> u64;
type Unsigned: SimdElement;
const TRUE: Self;
const FALSE: Self;
}
}
Despite the name PrivateMethods, all of those items and methods are accessible downstream (including in downstream crates) via any pub subtrait of PrivateMethods, such as the adjacent MaskElement:
pub impl(self) unsafe trait MaskElement:
SimdElement<Mask = Self> + SimdCast + PrivateMethods {}
Stabilizing MaskElement could lead to accidentally stabilizing all those PrivateMethods items too, which seems undesirable.
This is a sibling issue of https://github.com/rust-lang/rust/issues/158654 which flags an analogous concern in the Rust standard library itself.
Hat tip to @jhpratt for looping me in to look at the SemVer breakage and suggesting that we scan portable-simd for this pattern. I used AI tools for the scan, but wrote this issue fully by hand otherwise.
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
Start in crates/core_simd/src/masks.rs, reading the private_methods::PrivateMethods trait and the adjacent public MaskElement trait. Check how each associated item is exposed through the subtrait and verify the intended visibility behavior, including from a downstream crate if possible. Done means the PrivateMethods items are no longer unintentionally accessible through MaskElement.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100