rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
13.62k stars 1.49k forks source link

"Extract module to file" extracts module to incorrect path when source module's location is specified with #[path] #17181

Closed selenography closed 4 days ago

selenography commented 2 weeks ago

rust-analyzer version: 0.3.1940-standalone (f216be4a0 2024-04-27)

rustc version: rustc 1.79.0-nightly (0d8b3346a 2024-04-14)

editor or extension: VSCode; rust-analyzer v0.3.1940

relevant settings: None applicable

code snippet to reproduce: In src/main.rs:

#[path="parser/__mod.rs"]
mod parser;

fn main() {}

In src/parser/__mod.rs:

mod expr {};

Place the cursor on expr and invoke the "Extract module to file" assist.

Expected behavior: The line in __mod.rs becomes mod expr;, and a new empty file is created at parser/expr.rs.

Actual behavior: The line in __mod.rs becomes mod expr;, and a new empty file is created at parser/parser/expr.rs (where it will not be recognized as part of the workspace).