rust-lang / rust-lang/rust-analyzer
"Go To References" for `PartialOrd` functions should find comparison operators
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
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).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing rust-analyzer's go-to-definition and go-to-references handling for PartialOrd methods and comparison operators. Check how le references are resolved, then determine whether operator uses can be included, including default implementations based on partial_cmp. Done means references from le find relevant <= uses, with the broader comparison operators covered where feasible.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100