rust-lang / rust-analyzer

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

Feature request: Find all assignments / mutable borrows #10376

Open jplatte opened 2 years ago

jplatte commented 2 years ago

In addition to "find all references", it would sometimes be very useful to find all places where a certain variable or struct field is either written to directly, or mutably borrowed.

matklad commented 2 years ago

More generally, occurences should be classified into following buckets:

LSP doesn't currently have a nice way to present this in UI though. For structs, we have a horrible hack that seraching for { or ( narrows the search down to just constructors. I wonder if we can generalize that to writes somehow...

I guess for variables we can allow triggering search on the mut keyword, but that doesn't work for fields.

matklad commented 2 years ago

Some references to code:

Note that the second function shouldnt' probably exist -- instead, the relevant info shoudl just be present in ReferenceAccess (which is missnamed, let me fix that...)

matklad commented 2 years ago

cc #10426