rust-lang / rust-lang/rust-analyzer

Only suggest trait method completions when all (method) bounds are satisfied.

Open
#20,562 1 comment 0 reactions 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

Consider the following:

struct Color;
trait HasProperty<P> {}
trait Style {
    fn color(self)
    where
        Self: Sized + HasProperty<Color>,
    {
    }
}

impl<T> Style for T {}
struct WithoutColor;

I'd expect that WithoutColor.| doesn't show any color() as it doesn't fullfill the method trait bounds, but it does, and after completion cargo check fails (i.e. shows an error).

I haven't seen these kind of issues with super-trait-bounds on traits, something like Style: HasProperty<Color> (i.e. works as expected).

(This is a trimmed down example of an actual case in Xilem, in case you're interested, you can try the examples, there's a Style trait that does something similar).

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

Start with the minimal Rust example in the issue and reproduce completion for WithoutColor.|, then compare the offered methods with the result of cargo check. Investigate rust-analyzer's method-completion handling for method trait bounds and use the linked Xilem examples as a broader reproduction; done means color() is omitted when its bounds are unsatisfied without changing valid completions.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.