Skip to content

rust-analyzer fails to resolve some of the bounds on traits with associated types #19339

Open
@klkvr

Description

@klkvr

rust-analyzer version: 0.4.2336-standalone (5e7dd31 2025-03-09)

rustc version: rustc 1.87.0-nightly (f4a216d28 2025-03-02)

editor or extension: VSCode 0.4.2336

repository link (if public, optional): https://github.com/paradigmxyz/reth

code snippet to reproduce:

trait Bar {
    type Baz;

    fn baz(&self) -> Self::Baz;
}

trait Foo {
    type Bar;

    fn bar(&self) -> Self::Bar;
}

trait FooFactory {
    type Output: Foo<Bar: Bar<Baz = u8>>;

    fn foo(&self) -> Self::Output;

    fn foo_rpit(&self) -> impl Foo<Bar: Bar<Baz = u8>>;
}

fn test1(foo: impl Foo<Bar: Bar<Baz = u8>>) {
    // baz: u8 inferred
    let baz = foo.bar().baz();
}

fn test2<T: FooFactory>(factory: T) {
    // type unknown
    let baz = factory.foo().bar().baz();
    let baz = factory.foo_rpit().bar().baz();
}

It seems that in some cases rust-analyzer is failing to resolve more complex bounds while simpler bounds involving the same types are getting resolved correctlty

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-chalkchalk related issueA-tytype system / type inference / traits / method resolutionC-bugCategory: bugS-blocked-on-new-solverwill be fixed when we will switch to the new trait solver

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions