rust-lang / rust-lang/rust-analyzer

Consider present type aliases when using quick fixes

Open
#14,373 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Using libraries like ndarray you have a lot of type aliases e.g. Array2<f64> because the actual types are quite complex e.g. ArrayBase<ndarray::OwnedRepr<f64>, ndarray::Dim<[usize; 2]>>.

While in an ideal world, rust-analyzer could know to import the correct type alias if you use e.g. Add this functions return type. In reality, it would probably be unfeasible to search for those. What I imagine could be possible is to at least look at all imported type aliases and if there is one in scope that matches, use that one.

An alternative could be to add a code-action when on a type to "search for matching type alias" or something like that. I'm not familiar with how RA can access the available types, so I am not sure if this can be done, but it does sound possible to me.

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

The issue names no files or tests; start by locating the quick-fix implementation for generated return types and how imported type aliases are represented. Compare the proposed in-scope alias matching with the alternative search code action, then define one focused behavior. Done means the chosen behavior is specified and its matching cases are covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
developer-experience
Issue type
Feature
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.