Skip to content

Extract module with use bindings adds qualifier to usages #23258

Description

@edl-mar

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-assistsC-bugCategory: bugE-easyE-has-instructionsIssue has some instructions and pointers to code to get started

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions