rust-lang / rust-lang/rust-analyzer

Rename operation does not rename examples in docstrings

Open
#9,573 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

E-unknown S-unactionable
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

Given cargo new --lib rename with contents:

/// Prints "Hello, world!".
///
/// # Example
/// ```rust
/// use rename::hello;
/// hello();
/// ```
pub fn hello() {
    println!("Hello, world!");
}

and using the rename operation (F2 in VSCode) on the hello() function, you end up with

/// Prints "Hello, world!".
///
/// # Example
/// ```rust
/// use rename::hello;
/// hello();
/// ```
pub fn hello_world() {
    println!("Hello, world!");
}

which results in cargo test breaking:

---- src/lib.rs - hello_world (line 4) stdout ----
error[E0432]: unresolved import `rename::hello`
 --> src/lib.rs:5:5
  |
4 | use rename::hello;
  |     ^^^^^^^^^^^^^ no `hello` in the root

error: aborting due to previous error

Considering rust-analyzer manages to provide syntax highlighting within the docstring example blocks, it would be nice if the rename operation affected the docstrings as well.

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.

Research direction

Reproduce the issue with the shown cargo new --lib rename example and the VSCode F2 rename operation, then run cargo test to confirm the doctest failure. Trace how rename handles symbols in Rust docstring example blocks; done means the renamed function and its references in the example stay consistent and cargo test passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.