Skip to content

Conversation

@hvitved
Copy link
Contributor

@hvitved hvitved commented Dec 12, 2025

Trait methods with default implementations have their types specialized when performing method resolution, that is, when matching the type of a receiver against the type of the self parameter. This PR does the same when inferring types of calls, for example in

let x : i32 = 0;
let y : usize = 1;
let z = x.max(y);

the target of x.max(y) is https://doc.rust-lang.org/std/cmp/trait.Ord.html#method.max, and before this PR the type of the other parameter would remain Self, which meant that z would have both types i32 and usize. After this PR, the type of other is specialized to i32, which means z will only have type i32.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Dec 12, 2025
@hvitved hvitved force-pushed the rust/type-inference-matching-specialization branch from 3776f1f to 846ae48 Compare December 12, 2025 18:48
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Dec 15, 2025
@hvitved hvitved force-pushed the rust/type-inference-matching-specialization branch from 846ae48 to 14344e7 Compare December 15, 2025 08:05
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.

1 participant