Skip to content

Add anti-fundamental attribute - #160391

Draft
ShaddyDC wants to merge 3 commits into
rust-lang:mainfrom
ShaddyDC:anti-fundamental
Draft

Add anti-fundamental attribute#160391
ShaddyDC wants to merge 3 commits into
rust-lang:mainfrom
ShaddyDC:anti-fundamental

Conversation

@ShaddyDC

@ShaddyDC ShaddyDC commented Aug 2, 2026

Copy link
Copy Markdown

This PR introduces the internal #[rustc_anti_fundamental] trait attribute to prevent downstream crates from implementing traits on non-local #[fundamental] types (such as Pin and Box).
Using this new attribute on Deref, DerefMut, Receiver, CoerceUnsized, and DispatchFromDyn, we are able to cleanly resolve orphan rule conflicts and completely remove the internal PinDerefMutHelper workaround trait in core::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

@rustbot

rustbot commented Aug 2, 2026

Copy link
Copy Markdown
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 (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Aug 2, 2026
@rust-log-analyzer

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.
@rust-log-analyzer

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants