Rust: Implement type inference for trait objects/dyn
types
#20084
+527
−198
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 the auto 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.