rust-lang / rust-lang/rust-analyzer
Inlining a method with an early return does not handle early return correctly.
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
rust-analyzer version: rust-analyzer version: 0.3.2319-standalone [/home/lennart/.vscode/extensions/rust-lang.rust-analyzer-0.3.2319-linux-x64/server/rust-analyzer]
rustc version: rustc 1.82.0 (f6e511eec 2024-10-15)
editor or extension: VSCode v0.3.2319
relevant settings: Base settings
repository link (if public, optional): https://github.com/pc2/sus-compiler
code snippet to reproduce:
Using the code action "Inline early_return" also inlines the return None statement unmodified, which does not match the original function's behavior
fn early_return() -> Option<()> {
return None;
}
fn use_early_return() -> Option<()> {
if early_return().is_none() {
return Some(());
}
None
}
produces
fn use_early_return() -> Option<()> {
if {
return None;
}.is_none() {
return Some(());
}
None
}
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
Start from rust-analyzer's code action named Inline early_return and reproduce the issue with the Rust snippet provided. Compare the generated code's behavior with the original function; done means early returns preserve the original behavior and the regression is covered by a test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100