rust-lang / rust-lang/rust-analyzer

Rename on an imported type should rename the import to an alias.

Open
#23,345 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I'm not sure if this is valid request, but please feel free to close it, if it is.

When I tried to rename an imported type, hoping it will rename it to an alias, but it just returned an error: "Can't rename non-local definition".
But when I searched, I found that rename will alias an import, if we are in the use tree when invoking it, so I was wondering if we could extend to any imported type or the at least non-local crate imports?

Simple example:

use std::collections::HashMap

struct Foo {
	map: HashMap$0,
}

Invoking rename on the cursor should create an alias import:

use std::collections::HashMap as StdHashMap;

struct Foo {
	map: StdHashMap$0,
}

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

No implementation files or tests are named. Start by tracing rename handling for imported types and the existing use-tree behavior that already creates aliases; done means renaming an imported type from its usage site creates the expected import alias and updates the reference without the non-local-definition error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.