rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

`Wrap return type in...` Quick Fix should not wrap types that are already wrapped

Open sbdchd opened this issue 7 months ago • 0 comments

Running Wrap return type in... Option:

fn foo(x: i64) -> i64 {
    if x > 10 {
        Some(1)
    } else {
        None
    }
}

Gives:

fn foo(x: i64) -> Option<i64> {
    if x > 10 {
        Some(Some(1))
    } else {
        Some(None)
    }
}

But it would be better if it recognized the return values are already Option<T> so they don't need to be wrapped again:

fn foo(x: i64) -> Option<i64> {
    if x > 10 {
        Some(1)
    } else {
        None
    }
}

sbdchd avatar Jun 19 '25 16:06 sbdchd