Skip to content
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

rust-analyzer fails to resolve/auto-complete constants of associated types. #18935

Open
MasterTemple opened this issue Jan 14, 2025 · 0 comments
Labels
A-completion autocompletion C-bug Category: bug

Comments

@MasterTemple
Copy link

rust-analyzer fails to resolve/auto-complete constants of associated types.

What was I doing?

I wanted to have multiple associated constants on a type (implemented by a proc macro), but I wanted them grouped/nested together under another associated type.

Basically I wanted something like MyType::CONSTS::MY_CONST (instead of adding them directly on the type like MyType::CONST_1, MyType::CONST_2, MyType::CONST_3, and so on).

What was my issue?

I can do <MyType as MyConstTrait>::CONSTS::MY_CONST and my code will compile and run properly, but none of the constants are suggested.

The only auto-complete suggestions are into, try_into, from, and try_from.

See below for full (minimal) implementation.

rust-analyzer version: 0.4.2262-standalone

rustc version: rustc 1.84.0-nightly (b91a3a056 2024-11-07)

editor or extension: I have the same issue using rust-analyzer on both VSCode and Neovim

relevant settings: N/A

repository link (if public, optional): (eg. rust-analyzer)

code snippet to reproduce:

pub struct Person {
    age: i32,
    name: String,
    alive: bool,
}

trait FieldPaths {
    type T;
}

impl FieldPaths for Person {
    type T = PersonPaths;
}

pub struct PersonPaths;

impl PersonPaths {
    pub const AGE: &'static str = "age";
    pub const NAME: &'static str = "name";
    pub const ALIVE: &'static str = "alive";
}

fn main() {
    // I get no intelli-sense to complete AGE, but it does compile
    let age = <Person as FieldPaths>::T::AGE;
    println!("{age}");

    // Still no intelli-sense to complete AGE, but still compiles
    type PATH = <Person as FieldPaths>::T;
    let age = PATH::AGE;
    println!("{age}");
}
@MasterTemple MasterTemple added the C-bug Category: bug label Jan 14, 2025
@lnicola lnicola added the A-completion autocompletion label Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion autocompletion C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants