Skip to content

Rust: Support blanket implementations #20133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

paldepind
Copy link
Contributor

@paldepind paldepind commented Jul 28, 2025

This PR implements method resolution for blanket implementations that satisfies the criteria that the type parameter for which the implementation targets has a trait bound.

For instance, this impl block

impl<R: AsyncRead> AsyncReadExt for R {}

should be handled as there is a trait bound AsyncRead on the type parameter R.

On the other hand, this impl block

impl<T, U> Into<U> for T where U: From<T> {

is not handled since there is not trait bound for T.

At a high level, the implementation works as follows:

  1. For a method call foo.bar check if there's a blanket implementation that has the method bar.
  2. For a trait bound on the blanket implementation's type parameter, check if foo satisfies the trait bound.
  3. Given the above, resolve foo.bar to the method from the blanket implementation.

Todo

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Jul 28, 2025
@paldepind paldepind force-pushed the rust/type-inference-blanket-impl branch from 983257d to 2e98c24 Compare August 2, 2025 13:10
@paldepind paldepind force-pushed the rust/type-inference-blanket-impl branch from 2e98c24 to f130198 Compare August 3, 2025 08:37
(
f = impl.(ImplItemNode).getAssocItem(name)
or
// If the the trait has a method with a default implementation, then that

Check warning

Code scanning / CodeQL

Comment has repeated word Warning

The comment repeats the.
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