Skip to content

Type inference: Improve constraint matching - #22759

Open
hvitved wants to merge 2 commits into
github:mainfrom
hvitved:rust/type-inference-more-bound-resolution
Open

hvitved wants to merge 2 commits into
github:mainfrom
hvitved:rust/type-inference-more-bound-resolution

Conversation

@hvitved

@hvitved hvitved commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

When working on type inference for Unified, I realized that there was a (corner) case that the shared inference library did not support:

mod contextual_bound {
    #[derive(Default)]
    struct S<T>(T);

    struct MyThingB<B>(B);

    trait MyTrait<T> {}

    impl<T> MyTrait<[T; 1]> for MyThingB<T> {}

    fn bar<T1, T2: MyTrait<T1>>(x: T1, y: Option<T2>) {}

    fn test_bar() {
        let x = S(0);
        let z = MyThingB(Default::default()); // unable to infer the type of `z`
        bar([x], Some(z));
    }
}

DCA is uneventful.

@github-actions github-actions Bot added the Rust Pull requests that update Rust code label Oct 6, 2026
@hvitved
hvitved requested a balanced review from Copilot October 6, 2026 18:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused matching change has regression coverage, and the remaining corrections are documentation-only.

Review effort: Balanced
Findings: 2 Low severity

Open (2)
What changed in this PR

Improves shared type inference when trait constraints contain nested type parameters.

Changes:

  • Adds constraint matching for nested implementation-side type paths.
  • Adds Rust regression cases for direct and array-wrapped trait arguments.
  • Updates generated test expectations.
File Description
shared/​typeinference/​codeql/​typeinference/​internal/​TypeInference.qll Extends constraint matching and documents examples.
rust/​ql/​test/​library-tests/​type-inference/​type-inference.expected Records updated inference results.
rust/​ql/​test/​library-tests/​type-inference/​main.rs Adds contextual trait-bound regression cases.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread shared/typeinference/codeql/typeinference/internal/TypeInference.qll Outdated
Comment thread shared/typeinference/codeql/typeinference/internal/TypeInference.qll Outdated
@hvitved
hvitved force-pushed the rust/type-inference-more-bound-resolution branch from cd3d056 to 10f6b3b Compare October 6, 2026 18:23
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Oct 7, 2026
@hvitved
hvitved marked this pull request as ready for review October 7, 2026 07:15
@hvitved
hvitved requested review from a team as code owners October 7, 2026 07:15
@hvitved
hvitved requested a review from paldepind October 7, 2026 07:15

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants