rust-lang / rust-lang/rust-analyzer

[Feature Request]: Code action to suggestion types that satisfy a set of traits using Chalk

Open
#13,411 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I've come across a case where I have a generic struct that whose type parameter needs to satisfy two traits.

pub struct FileReader<R: Read + Seek> { /* private fields */ }

These are standard traits and I can find their implementors individually. Then I can see which implementors are common and use one of them.

However this made me consider if there's a way to query the IDE for possible structs/types that implement a given set of traits. This might be useful when generics have many trait conditions and/or a trait has many implementors.

I've asked this on SO and rust internals. There it was discussed that chalk, the new trait resolver, can potentially answer queries like this.

Now since rust-analyzer has integrated with chalk. Is it possible to answer queries like this? Kind of like an auto-complete code action, where the the analyzer can make recommendations.

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 reviewing rust-analyzer's Chalk integration and the code-action handling relevant to type and trait resolution; then determine whether queries for types satisfying multiple traits can be represented. Done means the analyzer can offer such recommendations with coverage for the requested behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.