rust-lang / rust-lang/rust-analyzer

Add adjust return type assist

Open
#14,616 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hey folks, what do you think about adding above-mentioned assist? It could be useful when doing some refactors. If this makes sense, I can try to do it as this will boost my dev workflow. If not, feel free to close this issue.

silly example: If I change Ok(Foo) to Ok(Bar) I have to adjust return type by myself, but I'd like to quick fix it, if possible. I browsed through already existing assists and there is add_return_type but I can't see anything which suits my case.

struct Foo;
struct Bar;
fn foo() -> Foo {
  Foo // -> change to Bar
}
struct Foo;
struct Bar;
fn foo() -> Foo {
  Bar // offer quick fix action
}

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

Start by reviewing the existing add_return_type assist and other assist implementations; the issue does not name specific files or tests. Determine how an assist could detect a returned expression whose type differs from the declared return type, then define tests for the Foo/Bar example and verify that a quick fix offers to adjust the return type.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
developer-experience, 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.