rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

Trait method should not appear in the auto complete if bounds not satisfied

Open XavDesbordes opened this issue 7 months ago • 4 comments

Hi, Using rust nightly rustc 1.89.0-nightly (777d37277 2025-05-17).

I will copy paste the question I asked on the (rust forum) with a playground link.


Hi,

The issue: I would like Vscode/rust-analyzer not to show some trait functions in auto complete if the bounds are not satisfied. I mean, for the type B in the playground, ra still show get_value_from_key when it should only show get_value_from_key2 and vice versa for A when auto-complete popup is displayed.

(This is a very simplified example, the trait is much more complex than this with dozen of functions with varying constraints)

Is there a way to make that behave properly?

Thanks!

XavDesbordes avatar May 26 '25 12:05 XavDesbordes

In general, rust-analyzer attempts to display only the methods that are contextually relevant. To diagnose what's going wrong in your case, we'll need a minimal, reproducible example of the issue.

ShoyuVanilla avatar May 28 '25 07:05 ShoyuVanilla

Yes, it is in the linked playground

XavDesbordes avatar May 28 '25 12:05 XavDesbordes

Oh, I missed it. Sorry, and thanks!

ShoyuVanilla avatar May 28 '25 12:05 ShoyuVanilla

You are more than welcome :)

XavDesbordes avatar May 28 '25 13:05 XavDesbordes