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 from 7f122f8 to 4d48515 Compare March 16, 2026 10:48
@hvitved hvitved force-pushed the rust/type-inference-trait-bound-impl-overlap branch 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 from 7a5a89a to 40c61b9 Compare March 17, 2026 14:11
@hvitved hvitved force-pushed the rust/type-inference-trait-bound-impl-overlap branch from 40c61b9 to 173db82 Compare March 17, 2026 14:46
@hvitved hvitved force-pushed the rust/type-inference-trait-bound-impl-overlap branch from 173db82 to 9300d8d Compare March 17, 2026 19:21
@hvitved hvitved force-pushed the rust/type-inference-trait-bound-impl-overlap branch 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
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