Skip to content

unresolved reference for trait associated type #14393

@jhgg

Description

@jhgg

I'm not sure the best title for this issue, so feel free to rename:

Consider the following code:

trait Foo {
    type Bar;
    fn baz() -> Self::Bar;
}

enum BarEnum {
    Qux { x: u32 },
    Tup(),
    Reg,
}

impl BarEnum {
    fn method() -> Self {
        Self::Tup()
    }
}

impl Foo for String {
    type Bar = BarEnum;

    fn baz() -> Self::Bar {
        Self::Bar::Qux { x: 1 };
        //    ^^^  ^^^   ^
        //   unresolved

        Self::Bar::Tup();
        //    ^^^
        //    unresolved

        Self::Bar::Reg;
        //    ^^^
        //    unresolved

        Self::Bar::method()
        //    ^^^
        //    unresolved
    }
}

When referring to BarEnum as Self::Bar, rust-analyzer seems to be unable to resolve. Here is a screenshot with a red semantic token.

image

This breaks autocomplete, and also stuff like rename symbol, for example renaming BarEnum::Qux, does not cause Self::Bar::Qux to be renamed. Additionally renaming type Bar also does not rename where its unresilved.

Self::Bar only becomes unresolved after you type :: after it:

Code_-_Insiders_7kJhB66akj

rust-analyzer version: rust-analyzer version: 0.4.1445-standalone

rustc version: rustc 1.66.1 (90743e729 2023-01-10)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-hirhir and hir-def relatedA-nameresname, path and module resolutionA-tytype system / type inference / traits / method resolutionC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions