Skip to content

Remove support for dyn* from the compiler #143036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Jun 26, 2025

This PR removes support for dyn* (#102425), which are a currently un-RFC'd experiment that was opened a few years ago to explore a component that we thought was necessary for AFIDT (async fn in dyn trait).

It doesn't seem like we are going to need dyn* types -- even in an not-exposed-to-the-user way1 -- for us to implement AFIDT. Given that AFIDT was the original motivating purpose of dyn* types, I don't really see a compelling reason to have to maintain their implementation in the compiler.

We've learned quite a lot from dyn*, but I think at this point its current behavior leads to more questions than answers. For example, dyn* support today remains somewhat fragile; it ICEs in many cases where the current "normal" dyn Trait types rely on their unsizedness for their vtable-based implementation to be sound I wouldn't be surprised if it's unsound in other ways, though I didn't play around with it too much. See the examples below.

#![feature(dyn_star)]

trait Foo {
    fn hello(self);
}

impl Foo for usize {
    fn hello(self) {
        println!("hello, world");
    }
}

fn main() {
    let x: dyn* Foo = 1usize;
    x.hello();
}

And:

#![feature(dyn_star)]

trait Trait {
    type Out where Self: Sized;
}

fn main() {
    let x: <dyn* Trait as Trait>::Out;
}

...and probably many more problems having to do with the intersection of dyn-compatibility and Self: Sized bounds that I was too lazy to look into like:

  • GATs
  • Methods with invalid signatures
  • Associated consts

Generally, dyn* types also end up getting in the way of working with normal dyn types to an extent that IMO outweighs the benefit of experimentation.

I recognize that there are probably other, more creative usages of dyn* that are orthogonal to AFIDT. However, I think any work along those lines should first have to think through some of the more fundamental interactions between dyn* and dyn-compatibility before we think about reimplementing them in the type system.


I'm planning on removing the DynKind enum and the PointerLike built-in trait from the compiler after this PR lands.

Closes #102425.

cc @eholk @rust-lang/lang @rust-lang/types

Closes #116979.
Closes #119694.
Closes #134591.
Closes #104800.

Footnotes

  1. Compared to, e.g., generators whih are an unstable building block we use to implement stable syntax like async {}.

@rustbot
Copy link
Collaborator

rustbot commented Jun 26, 2025

r? @SparrowLii

rustbot has assigned @SparrowLii.
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

@rustbot rustbot added A-tidy Area: The tidy tool PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Jun 26, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 26, 2025

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

HIR ty lowering was modified

cc @fmease

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

There are changes to the tidy tool.

cc @jieyouxu

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

Some changes occurred to constck

cc @fee1-dead

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred in compiler/rustc_sanitizers

cc @rcvalle

The Miri subtree was changed

cc @rust-lang/miri

This PR changes a file inside tests/crashes. If a crash was fixed, please move into the corresponding ui subdir and add 'Fixes #' to the PR description to autoclose the issue upon merge.

@rust-log-analyzer

This comment has been minimized.

@matthiaskrgr
Copy link
Member

And thus, after almost 3 years, the Rust Dynasty came to an end.

I guess #134591 and #104800 can also be marked as fixed/closed then?

@cyrgani cyrgani added the F-dyn_star `#![feature(dyn_star)]` label Jun 26, 2025
@oli-obk
Copy link
Contributor

oli-obk commented Jun 26, 2025

r? @oli-obk

@bors r+

@bors
Copy link
Collaborator

bors commented Jun 26, 2025

📌 Commit 965c86a has been approved by oli-obk

It is now in the queue for this repository.

@bors bors 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 Jun 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tidy Area: The tidy tool F-dyn_star `#![feature(dyn_star)]` PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler 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
8 participants