Add anti-fundamental attribute - #160391
Draft
ShaddyDC wants to merge 3 commits into
Draft
Conversation
Collaborator
|
Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @dingxiangfei2009 (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
This comment has been minimized.
This comment has been minimized.
This adds a new compiler attribute that prevents non-local #[fundamental] types from receiving implementations of the marked trait. This is the infrastructure for fixing soundness problems with DerefMut and DispatchFromDyn on fundamental wrappers like Box and Pin. The attribute is parsed, cross-crate encoded, stored in TraitDef, and checked during the orphan check in coherence.
Mark Deref, DerefMut, DispatchFromDyn, CoerceUnsized, and Receiver with #[rustc_anti_fundamental] to prevent downstream crates from implementing these traits on #[fundamental] types like Box and Pin.
ShaddyDC
force-pushed
the
anti-fundamental
branch
from
August 2, 2026 16:51
96b570b to
eec2923
Compare
This comment has been minimized.
This comment has been minimized.
With DerefMut now marked #[rustc_anti_fundamental], the PinHelper/ PinDerefMutHelper indirection is no longer needed to prevent downstream crates from implementing DerefMut on Pin. Replace it with a direct DerefMut impl for Pin and remove the helper module, its diagnostic item, and the special-casing in trait suggestion rendering.
ShaddyDC
force-pushed
the
anti-fundamental
branch
from
August 2, 2026 18:19
eec2923 to
8bc0866
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces the internal
#[rustc_anti_fundamental]trait attribute to prevent downstream crates from implementing traits on non-local#[fundamental]types (such asPinandBox).Using this new attribute on
Deref,DerefMut,Receiver,CoerceUnsized, andDispatchFromDyn, we are able to cleanly resolve orphan rule conflicts and completely remove the internalPinDerefMutHelperworkaround trait incore::pin.See also #85099
This description is WIP, and I will expand on it later, but I wanted to create this PR as a starting point for further discussion with some people I was working on this.
r? @dingxiangfei2009