rust-lang / rust-lang/rust-analyzer

Replace field access with getter/setter

Open
#10,954 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-assists C-feature
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

I have a struct with a field that has been public but would now like to change it to be accessed via a getter. There's an assist to generate but could there be a way to also replace accesses to the field with the getter?

I guess it could be hard/impossible to know if the getter/getter_mut/setter should be used. But in my specific case the field is only ever read and I only wish to generate a read only getter.

Could this be implemented and/or is there a way to do this currently using some sort of find/replace?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files or tests; start by locating the existing assist that generates getters and tracing the related field-access handling. Define the supported read-only case and verify it with focused assist tests; done means matching field reads are safely converted without changing mutable or ambiguous accesses.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.