rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.31k stars 1.62k forks source link

"Go To References" for `PartialOrd` functions should find comparison operators #18540

Open JarredAllen opened 1 day ago

JarredAllen commented 1 day ago

If I have code like this:

pub struct Foo { .. }

impl PartialOrd for Foo { .. }

// also `Eq` and `PartialEq` are implemented consistently with `PartialOrd`

fn compare_foos(foo1: Foo, foo2: Foo) -> bool {
    foo1 <= foo2
}

Running "go to definition" on the <= will go to the definition of the le method in the impl PartialOrd for Foo (including to the default implementation in the PartialOrd trait if not explicitly overridden in the impl block), but running "go to references" can't go back the other way.

It'd be great if I could "go to references" on the le function to find all places where <= is used to compare 2 Foos. It'd be even greater if, for a type that only implements the partial_cmp function and leaves the default implementations alone, "go to references" could find all the </<=/>/>= comparison operators (not sure if this second part is feasible, since it does technically go through a different method).

ChayimFriedman2 commented 1 day ago

Ah yes I noticed that a while ago. Do note however that this is going to be pretty much the slowest thing we ever provide (find all references is based on textual search then refinement using semantics info - because calculating semantic info is expensive. Searching for operators is going to find a lot of matches).