rust-lang / rust-lang/rust-analyzer

Extract module with use bindings adds qualifier to usages

Open
#23,258 5 comments 0 reactions 1 assignee View on GitHub

@jassem-manita is already working on this.

Since Sep 7, 2026.

A-assists C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

Hi,

I'm pretty new to rust - so I'm not completely sure if this is a bug or a feature request (and there is still the possibility that I'm doing something wrong).

rust-analyzer 1.98.0 (88d9e12a 2026-08-18)

I want to extract a struct into its own module using "Extract module", but when the struct is already imported via a use binding, the assist adds a redundant qualifier to usages of that struct instead of updating the existing import.

There are two files, main.rs and my_module.rs

// main.rs
use crate::my_module::{First, Second};
mod my_module;
fn main() {
    let first = First {};
    let second = Second {};
}
// my_module.rs
pub(crate) struct First {}
pub(crate) struct Second {}

Running "Extract module" on struct First results in the following code:

// main.rs
use crate::my_module::{Second, modname::First}; // <- already imported
mod my_module;
fn main() {
    let first = modname::First {}; // <- qualifier added
    let second = Second {};
}

and

// my_module.rs
mod modname {
    pub(crate) struct First {}
}
pub(crate) struct Second {}

The visibility is quickly corrected by running "Change visibility to pub(crate)".
The problem is that the usage of First is now qualified with modname::, even though the import was already updated to bring First into scope directly.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.