rust-lang / rust-lang/rust-analyzer

`return` statements in inlined functions just get moved over and try to return out of the outer function + generic types are discarded

Open
#15,471 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

title,

code example

fn none<T>() -> Option<T> {
    return None;
}

pub fn main() {
    let a = none::<u32>();
}
  • inlining the none function replaces it with let a = { return None; };, which tries to return None in main
  • the generic type param T of none was first known to be u32, to preserve this information (and not end up with "type annotations needed for Option<T>") let a = None::<u32>; would work

rust-analyzer version: 0.4.1625-standalone

rustc version: rustc 1.71.1 (eb26296b5 2023-08-03)

relevant settings: none

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 reproducing the reported Rust example with rust-analyzer's function-inlining feature. Trace the inlining implementation and its existing tests, if present; done means an inlined return remains valid within the replacement expression and the known generic type is preserved without a type-inference error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
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.