Skip to content

Should prefer associated items over a possible import with the same name #18554

@kpreid

Description

@kpreid

rust-analyzer version: 0.3.2188-standalone (ba56d9b 2024-11-17)
rustc version: rustc 1.82.0 (f6e511eec 2024-10-15)
editor or extension: VSCode; version of the RA extension is v0.3.2188

(I also tested with nightly / pre-release versions; the behavior was the same.)

code snippet to reproduce:

fn main() {
    let x = f32::INF
}

Put the cursor at the end of the line and press ^Space for completions. The first two suggestions will both complete to f32::INFINITY, but the first one on the list is one which will insert use core::f32; too.

Image

Since those constants are sort-of-deprecated, I don’t think RA should be preferring them, and in the general case, I would think that given any two identical local paths, it makes sense to rank completing the associated item over importing something new.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions