Skip to content

Conversation

@jhpratt
Copy link
Member

@jhpratt jhpratt commented Jan 21, 2026

Successful merges:

r? @ghost

Create a similar rollup

bjorn3 and others added 14 commits November 23, 2025 10:33
…tible_trait], which makes the marked trait dyn-incompatible.

Removes the attribute from `MetaSized` and `PointeeSized`, with a special case in the trait solvers for `MetaSized`.

`dyn MetaSized` is a perfectly cromulent type, and seems to only have had #[rustc_do_not_implement_via_object] so the builtin object
candidate does not overlap with the builtin MetaSized impl that all `dyn` types get.
Resolves this with a special case by checking `is_sizedness_trait` where the trait solvers previously checked `implement_via_object`.

`dyn PointeeSized` alone is rejected for other reasons (since `dyn PointeeSized` is considered to have no principal trait because `PointeeSized`
is removed at an earlier stage of the compiler), but `(dyn PointeeSized + Send)` is valid and equivalent to `dyn Send`.

Add suggestions from code review

Update compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs and tests

Co-authored-by: lcnr <rust@lcnr.de>
The dep names needed here are statically available from `rustc_middle`.
Replace `#[rustc_do_not_implement_via_object]` with `#[rustc_dyn_incompatible_trait]`

Background: `#[rustc_do_not_implement_via_object]` on a trait currently still allows `dyn Trait` to exist (if the trait is otherwise dyn-compatible), it just means that `dyn Trait` does not automatically implement `Trait` via the normal object candidate. For some traits, this means that `dyn Trait` does not implement `Trait` at all (e.g. `Unsize` and `Tuple`). For some traits, this means that `dyn Trait` implements `Trait`, but with different associated types (e.g. `Pointee`, `DiscriminantKind`). Both of these cases can can cause issues with codegen , as seen in rust-lang#148089 (and rust-lang#148089 (comment) ), because codegen assumes that if `dyn Trait` does not implement `Trait` (including if `dyn Trait<Assoc = T>` does not implement `Trait` with `Assoc == T`), then `dyn Trait` cannot be constructed, so vtable accesses on `dyn Trait` are unreachable, but this is not the case if `dyn Trait` has multiple supertraits: one which is `#[rustc_do_not_implement_via_object]`, and one which we are doing the vtable access to call a method from.

This PR replaces `#[rustc_do_not_implement_via_object]` with `#[rustc_dyn_incompatible_trait]`, which makes the marked trait dyn-incompatible, making `dyn Trait` not well-formed, instead of it being well-formed but not implementing `Trait`. This resolves rust-lang#148089 by making it not compile.

May fix rust-lang#148615

The traits that are currently marked `#[rustc_do_not_implement_via_object]` are: `Sized`, `MetaSized`, `PointeeSized`, `TransmuteFrom`, `Unsize`, `BikeshedGuaranteedNoDrop`, `DiscriminantKind`, `Destruct`, `Tuple`, `FnPtr`, `Pointee`. Of these:
* `Sized` and `FnPtr` are already not dyn-compatible (`FnPtr: Copy`, which implies `Sized`)
* `MetaSized`
    * Removed `#[rustc_do_not_implement_via_object]`. Still dyn-compatible after this change. (Has a special-case in the trait solvers to ignore the object candidate for `dyn MetaSized`, since it `dyn MetaSized: MetSized` comes from the sized candidate that all `dyn Trait` get.)
* `PointeeSized`
    * Removed `#[rustc_do_not_implement_via_object]`. It doesn't seem to have been doing anything anyway ([playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=a395626c8bef791b87a2d371777b7841)), since `PointeeSized` is removed before trait solving(?).
* `Pointee`, `DiscriminantKind`, `Unsize`, and `Tuple` being dyn-compatible without having `dyn Trait: Trait` (with same assoc tys) can be observed to cause codegen issues (rust-lang#148089) so should be made dyn-incompatible
* `Destruct`, `TransmuteFrom`, and `BikeshedGuaranteedNoDrop` I'm not sure if would be useful as object types, but they can be relaxed to being dyn-compatible later if it is determined they should be.

-----

<details> <summary> resolved </summary>

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.
    3. 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)?
    4. Resolved: the trait solvers special-case `dyn MetaSized` to ignore the object candidate in preference to the sizedness candidate (technically the check is for any `is_sizedness_trait`, but only `MetaSized` gets this far (`Sized` is inherently dyn-incompatible, and `dyn PointeeSized` is ill-formed for other reasons)
4. 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.
    2. Resolved: can be improved later

  <details> <summary>diagnostic example</summary>

```rs
#![feature(ptr_metadata)]

trait C: std::ptr::Pointee {}

fn main() {
    let y: &dyn C;
}
```

```rs
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`.
  ```

  </details> </details>

  Still investigating "3. `compiler/rustc_hir/src/attrs/encode_cross_crate.rs`: Should `DynIncompatibleTrait` attribute be encoded cross crate?"
Move LTO to OngoingCodegen::join

This will make it easier to in the future move all this code to link_binary.

Follow up to rust-lang#147810
Part of rust-lang/compiler-team#908
Simplify lookup of `DepKind` names in duplicate dep node check

This PR simplifies parts of the query system, by removing the `make_dep_kind_name_array!` macro, and removing much of the associated plumbing added by 68fd771.

Instead, we now create a `DEP_KIND_NAMES` constant in `define_dep_nodes!`, and look up names in that instead.
Roll bootstrap reviewers for `src/tools/build-manifest`

I honestly don't know who's supposed to be maintaining this tool, but maybe bootstrap? 🤷

r? @Kobzol (maybe)
@rust-bors rust-bors bot added the rollup A PR which is a rollup label Jan 21, 2026
@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-meta Area: Issues & PRs about the rust-lang/rust repository itself A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) 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 Jan 21, 2026
@jhpratt
Copy link
Member Author

jhpratt commented Jan 21, 2026

@bors r+ rollup=never p=4

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 21, 2026

📌 Commit e723e0d has been approved by jhpratt

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 21, 2026
@rust-bors

This comment has been minimized.

@rust-bors rust-bors bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 21, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 21, 2026

☀️ Test successful - CI
Approved by: jhpratt
Duration: 3h 20m 1s
Pushing 838db25 to main...

@rust-bors rust-bors bot merged commit 838db25 into rust-lang:main Jan 21, 2026
12 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Jan 21, 2026
@rust-timer
Copy link
Collaborator

📌 Perf builds for each rolled up PR:

PR# Message Perf Build Sha
#148637 Replace #[rustc_do_not_implement_via_object] with `#[rust… 8236a96062fd8a861237af7cd06917d2fe19d96b (link)
#149209 Move LTO to OngoingCodegen::join 668708791d42df730da4ff67e63c63468f6e9401 (link)
#151402 Simplify lookup of DepKind names in duplicate dep node ch… 7b448f23f6cce06e3ad2a1024d7fc7f227133921 (link)
#151437 Roll bootstrap reviewers for src/tools/build-manifest fa2f2f41be45c86c26790ebad667c3dd5d5f430d (link)

previous master: 88ad3d44ca

In the case of a perf regression, run the following command for each PR you suspect might be the cause: @rust-timer build $SHA

@jhpratt jhpratt deleted the rollup-wfHDCMS branch January 21, 2026 11:11
@github-actions
Copy link
Contributor

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 88ad3d4 (parent) -> 838db25 (this PR)

Test differences

Show 102 test diffs

Stage 1

  • [ui] tests/ui/dyn-compatibility/metasized.rs: [missing] -> pass (J0)
  • [ui] tests/ui/dyn-compatibility/pointeesized.rs: [missing] -> pass (J0)
  • [ui] tests/ui/dyn-compatibility/sized-3.rs: [missing] -> pass (J0)
  • [ui] tests/ui/traits/ice-with-dyn-pointee.rs: pass -> [missing] (J0)

Stage 2

  • [ui] tests/ui/dyn-compatibility/metasized.rs: [missing] -> pass (J1)
  • [ui] tests/ui/dyn-compatibility/pointeesized.rs: [missing] -> pass (J1)
  • [ui] tests/ui/dyn-compatibility/sized-3.rs: [missing] -> pass (J1)
  • [ui] tests/ui/traits/ice-with-dyn-pointee.rs: pass -> [missing] (J1)

Additionally, 94 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 838db2538201a845a3694c99d9114a1acebd6e28 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-sparcv9-solaris: 5490.7s -> 6983.7s (+27.2%)
  2. dist-aarch64-apple: 8305.0s -> 10212.0s (+23.0%)
  3. dist-aarch64-msvc: 5485.1s -> 6221.9s (+13.4%)
  4. i686-msvc-2: 7343.6s -> 8171.2s (+11.3%)
  5. x86_64-gnu-debug: 6681.8s -> 7322.6s (+9.6%)
  6. tidy: 163.9s -> 149.0s (-9.1%)
  7. x86_64-gnu-llvm-20: 4468.7s -> 4828.0s (+8.0%)
  8. dist-loongarch64-linux: 5245.9s -> 5655.6s (+7.8%)
  9. dist-armv7-linux: 4808.4s -> 5171.1s (+7.5%)
  10. dist-various-1: 4128.5s -> 3833.3s (-7.2%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (838db25): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.1% [0.0%, 0.2%] 2
Improvements ✅
(primary)
-0.3% [-0.3%, -0.2%] 11
Improvements ✅
(secondary)
-0.5% [-1.0%, -0.2%] 22
All ❌✅ (primary) -0.3% [-0.3%, -0.2%] 11

Max RSS (memory usage)

Results (primary -8.2%, secondary -3.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.9% [0.9%, 0.9%] 1
Regressions ❌
(secondary)
3.3% [1.6%, 5.4%] 4
Improvements ✅
(primary)
-8.9% [-17.4%, -2.3%] 12
Improvements ✅
(secondary)
-4.7% [-15.1%, -0.7%] 26
All ❌✅ (primary) -8.2% [-17.4%, 0.9%] 13

Cycles

Results (primary -1.1%, secondary 1.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.9% [2.2%, 5.8%] 6
Improvements ✅
(primary)
-1.1% [-1.1%, -1.1%] 1
Improvements ✅
(secondary)
-3.1% [-4.2%, -2.2%] 4
All ❌✅ (primary) -1.1% [-1.1%, -1.1%] 1

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 472.964s -> 472.653s (-0.07%)
Artifact size: 383.27 MiB -> 383.22 MiB (-0.01%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-meta Area: Issues & PRs about the rust-lang/rust repository itself A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) merged-by-bors This PR was explicitly merged by bors. rollup A PR which is a rollup 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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants