- Notifications
You must be signed in to change notification settings - Fork1.7k
Rust: Implement type inference for trait objects/dyn
types#20084
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
59e3ac7
to8de4313
CompareUh oh!
There was an error while loading.Please reload this page.
8de4313
to55c3674
Compare55c3674
to219e26e
Comparepaldepind commentedJul 18, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Note: The first DCA run showed an increase in type inference inconsistencies. I've fixed those and started a second DCA run. EDIT: The second DCA shows that the type inference inconsistencies are now fixed. The number of type inference inconsistencies now only decreases. |
Uh oh!
There was an error while loading.Please reload this page.
This PR implements support for trait objects on the form
dyn Trait
.The implementation works as follows:
dyn Trait
appears somewhere as a declared type then we create aDynTraitType
that consists of the traitTrait
.dyn Trait
has a type parameter for every type parameter ofTrait
. There is a 1-to-1 correspondence but they're not equal.dyn Trait
type is made to implementTrait
as if there was animpl<A, B, ...> Trait<A, B, ...> for dyn Trait<A, B, ..>
block in the source.Currently the PR doesn't account for theauto traits that one can specify with a
+
, for instancedyn Clone + Send + Sync
. I don't know if we have a need to consider those, but if we do it should be possible by building on top of the work in this PR.DCA shows a 0.33% point increase in resolved call targets and no change in analysis time.