Stream: general

Topic: code:goto impl BarT for . :: bar, not trait BarT::bar


zeroexcuses (May 10 2020 at 21:14, on Zulip):

Suppose we have:

trait BarT {
  fn bar(&self) ;
}

impl BarT for Dog { ... };

fn main() {
  let dog: Dog;
  dog.bar();
}

now, suppose the cursor is over the bar of dog.bar. At this point, when I try to go to reference, I get thrown to the 'BarT::bar'. However, since the compiler knows that dog: Dog, is there a way to have it jump to impl BarT for Dog::bar ?

I.e. in situations where the compiler knows the type of the lhs of the .bar, I want it to jump me to the right impl, rather than the generic trait BarT

This works for me in IntelliJ/Rust most of the time, but I can't figure out how to do this in vs code.

zeroexcuses (May 10 2020 at 21:15, on Zulip):

(I'm using latest vs code, latest rust analyzer, and rustc nightly)

Laurențiu Nicola (May 11 2020 at 06:35, on Zulip):

Not right now, but it might be possible to offer it because once you're on the trait method, you can choose "Go to Implementations" and it will highlight the Dog one. Maybe "Go to Definition" should take you to the implementation, though I'm not sure it makes sense.

zeroexcuses (May 11 2020 at 13:23, on Zulip):

I don't know if we are talking the same thing. If I put the cursor over BarT::bar, and hit ctrl-t, it will show me ALL implementations and I can choose. The downside is that if Dog, Cat, Rat, Donkey, Eagle, ... all implement the trait, then I have to manually pick the one.

Laurențiu Nicola (May 11 2020 at 13:27, on Zulip):

It's not the same thing, but since it finds the Dog implementation, it could presumably navigate there

zeroexcuses (May 11 2020 at 13:43, on Zulip):

Sure, but the problem is the mental cost of doing "what is the type of this var" so I can select the right one, whereas I'd really prefer the compiler/IDE just did this for me.

Last update: May 29 2020 at 17:30UTC