rust-lang / rust-lang/rust-analyzer
Discussion: Extract into function behavior w.r.t. first assignment of a variable
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
Currently when extracting some code that includes a variable assignment into a function, rust-analyzer tries taking a mutable reference to that variable regardless of whether that variable was previously initialized. Use cases for having declaration separate from initialization are On-Stack Dynamic Dispatch and conditional initialization of values of "guard" types (e.g. sentry::init's return type).
In both cases if the assignment is the last statement of the code to be extracted, RA could instead make the new function return the value that is to be assigned to that variable, but there is of course no general solution here with the current language which is why I started the issue title with Discussion:. I'm curious how others think a situation like this should be handled.
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
No source file, test, or entry point is identified in the issue. Start by examining rust-analyzer's extract-into-function behavior and the examples linked in the discussion, then determine the intended behavior for assignments whose variables were or were not previously initialized. Done requires an agreed design and corresponding implementation scope.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100