Skip to content

Conversation

@hvitved
Copy link
Contributor

@hvitved hvitved commented Jan 26, 2026

The following simple program would make our type inference implementation explode:

#[derive(Default)]
struct S;

fn f() -> S {
    let x = Default::default();
    From::from(x)
}

Firstly, because of a getSuccessor vs getAssocItem bug, From::from would allow for any sub trait of From, for example the Int trait, which meant that x could be inferred to have type bool. Secondly, since many from implementations are polymorphic in their argument, we should really be checking that the return type matches the type of the calling context.

This PR makes those two adjustments, and adds the regression test.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Jan 26, 2026
@hvitved hvitved force-pushed the rust/type-inference-perf branch 2 times, most recently from 71ee1c9 to 38929dd Compare January 26, 2026 18:53
@hvitved hvitved force-pushed the rust/type-inference-perf branch from 38929dd to 50ce393 Compare January 26, 2026 19:16
@hvitved hvitved changed the title Rust: Type inference performance improvements Rust: Fix context-based type inference explosion Jan 26, 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