Skip to content

Rust: Disambiguate types inferred from trait bounds#21464

Draft
hvitved wants to merge 5 commits intogithub:mainfrom
hvitved:rust/type-inference-trait-bound-impl-overlap
Draft

Rust: Disambiguate types inferred from trait bounds#21464
hvitved wants to merge 5 commits intogithub:mainfrom
hvitved:rust/type-inference-trait-bound-impl-overlap

Conversation

@hvitved
Copy link
Contributor

@hvitved hvitved commented Mar 12, 2026

In certain cases where a type implements the same trait but with different type arguments, we may infer overlapping types from trait bounds (see example in first commit).

In order to disambiguate, this PR takes the same approach as #21420, but lifting the idea from that PR into the shared type inference library, so it applies to both resolution of <Foo as Bar<...>> paths as well as constraints on type parameters inside functions.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Mar 12, 2026
@hvitved hvitved force-pushed the rust/type-inference-trait-bound-impl-overlap branch 2 times, most recently from 4d48515 to 902e953 Compare March 17, 2026 10:18
@hvitved hvitved force-pushed the rust/type-inference-trait-bound-impl-overlap branch from 902e953 to 1dbd888 Compare March 17, 2026 10:44
hasTypeConstraint(tt, type, constraint) and
rootTypesSatisfaction(type, constraint, abs, cond, _) and
predicate potentialInstantiationOf(Term term, TypeAbstraction abs, TypeMention cond) {
exists(Constraint constraint, Type type, Type constraintRoot |
@hvitved hvitved force-pushed the rust/type-inference-trait-bound-impl-overlap branch from 1dbd888 to 7a5a89a Compare March 17, 2026 14:01
@hvitved hvitved force-pushed the rust/type-inference-trait-bound-impl-overlap branch 4 times, most recently from 9300d8d to e14936f Compare March 18, 2026 09:26
@hvitved hvitved changed the title Rust: Only infer types from trait bounds when their implementation is unambigous Rust: Disambiguate types inferred from trait bounds Mar 18, 2026
@hvitved hvitved force-pushed the rust/type-inference-trait-bound-impl-overlap branch from 98a7ca6 to be2a49b Compare March 18, 2026 16:55
@hvitved hvitved force-pushed the rust/type-inference-trait-bound-impl-overlap branch from be2a49b to 03a444d Compare March 18, 2026 18:53
@hvitved hvitved force-pushed the rust/type-inference-trait-bound-impl-overlap branch from 03a444d to 8b7328d Compare March 18, 2026 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant