Skip to content

Inlining a method with an early return does not handle early return correctly. #19377

@VonTum

Description

@VonTum

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions