Skip to content

Conversation

@zachs18
Copy link
Contributor

@zachs18 zachs18 commented Nov 7, 2025

May fix #148615

This affects three groups of traits:

  1. MetaSized
    1. Removed #[rustc_do_not_implement_via_object]. Still dyn-compatible after this change. See question 1 below
  2. PointeeSized
    1. Removed #[rustc_do_not_implement_via_object]. It doesn't seem to have been doing anything anyway (playground), since PointeeSized is removed before trait solving(?).
  3. All the other traits which are currently #[rustc_do_not_implement_via_object] (including Pointee, Tuple, Destruct, etc)
    1. These traits now have #[rustc_dyn_incompatible_trait] and are now dyn-incompatible.

Questions before merge:

  1. dyn MetaSized: MetaSized having both SizedCandidate and ObjectCandidate
    1. I'm not sure if the checks in compiler/rustc_trait_selection/src/traits/project.rs and compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs were "load-bearing" for MetaSized (which is the only trait that was previously #[rustc_do_not_implement_via_object] that is still dyn-compatible after this change). Is it fine to just remove them? Removing them (as I did in the second commit) doesn't change any UI test results.
    2. IIUC, dyn MetaSized could get its MetaSized implementation in two ways: the object candidate (the normal dyn Trait: Trait) that was supressed by #[rustc_do_not_implement_via_object], and the SizedCandidate (that all dyn Trait get for dyn Trait: MetaSized). Given that MetaSized has no associated types or methods, is it fine that these both exist now? Or is it better to only have the SizedCandidate and leave these checks in (i.e. drop the second commit, and remove the FIXMEs)?
  2. Diagnostics improvements?
    1. The diagnostics are kinda bad. If you have a trait Foo: Pointee {}, you now get a note that reads like Foo "opted out of dyn-compatbility", when really Pointee did that.
diagnostic example
#![feature(ptr_metadata)] trait C: std::ptr::Pointee {} fn main() { let y: &dyn C; }
error[E0038]: the trait `C` is not dyn compatible --> c.rs:6:17 | 6 | let y: &dyn C; | ^ `C` is not dyn compatible | note: for a trait to be dyn compatible it needs to allow building a vtable for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility> --> /home/zachary/opt_mount/zachary/Programming/rust-compiler-2/library/core/src/ptr/metadata.rs:57:1 | 57 | #[rustc_dyn_incompatible_trait] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...because it opted out of dyn-compatbility | ::: c.rs:3:7 | 3 | trait C: std::ptr::Pointee {} | - this trait is not dyn compatible... error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0038`.
@rustbot
Copy link
Collaborator

rustbot commented Nov 7, 2025

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

This PR changes rustc_public

cc @oli-obk, @celinval, @ouz-a

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Nov 7, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 7, 2025

r? @nnethercote

rustbot has assigned @nnethercote.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@nnethercote
Copy link
Contributor

I know it says "DO NOT MERGE YET". Is it ready for review? If not, can you convert it to a draft PR?

Also, you might as well squash the tidy commits, there's no need for them to be separate.

…tible_trait], which makes the marked trait dyn-incompatible. Removes the attribute from `MetaSized` and `PointeeSized`. `dyn MetaSized` is a perfectly cromulent type, and seems to only have had #[rustc_do_not_implement_via_object] so the builtin object candidate would not overlap with the builtin MetaSized impl that all `dyn` types get. Resolves this by checking `is_sizedness_trait` where the trait solvers previously checked `implement_via_object`. (is this necessary?) `dyn PointeeSized` alone is rejected for other reasons (since `dyn PointeeSized` is considered to have no trait because `PointeeSized` is removed at an earlier stage of the compiler), but `(dyn PointeeSized + Send)` is valid and equivalent to `dyn Send`.
@zachs18 zachs18 force-pushed the rustc_dyn_incompatible branch from 5344d24 to 95686b6 Compare November 8, 2025 01:38
@rustbot
Copy link
Collaborator

rustbot commented Nov 8, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@zachs18 zachs18 changed the title [DO NOT MERGE YET] Replace #[rustc_do_not_implement_via_object] with #[rustc_dyn_incompatible_trait] Replace #[rustc_do_not_implement_via_object] with #[rustc_dyn_incompatible_trait] Nov 8, 2025
@zachs18
Copy link
Contributor Author

zachs18 commented Nov 8, 2025

I know it says "DO NOT MERGE YET". Is it ready for review?

Yes, it is ready for review. I added that because I have questions in the PR description that should be addressed (and the commits amended based on the answers) before merging.

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-review Status: Awaiting review from the assignee but also interested parties. 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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

4 participants