Skip to content

Auto Import structure breaks with "rust-analyzer.imports.prefix": "plain" #17320

Open
@homchom

Description

@homchom

I do not believe this is a regression, but it is exacerbated by #17277.


rust-analyzer version: 0.3.1975-standalone (71a816a 2024-05-26)

rustc version: 1.78.0 (9b00956e5 2024-04-29)

editor or extension: VSCode

relevant settings: rust-analyzer.imports.prefix

to reproduce:

  1. Create a new project with serde (including feature derive) as a dependency; any external crate would work, but I chose serde for this report.
  2. Create the following src directory
├── lib.rs
├── foo.rs

and the following files.

// lib.rs
use serde::Serialize;

mod foo;

#[derive(Serialize)]
struct Example;

impl Example {
    fn a() {
    }
}
// foo.rs
pub fn b() {
}

It is important that the module is named foo, so it is alphabetically before serde.
3. Through UI or JSON, change the setting rust-analyzer.imports.prefix to self.
4. In the body of Example::a(), type b and use auto-import. Observe that self::foo::b is correctly imported in a group below serde::Serialize. Remove the function call and import, so it once again resembles Step 2.
5. Change rust-analyzer.imports.prefix to plain (the default).
6. In the body of Example::a(), type b and use auto-import. Observe that foo::c is incorrectly imported. It should be below serde::Serialize, as it is a current module import, but it is instead above serde::Serialize in the same group, as if it was an external crate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions