rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.27k stars 1.61k forks source link

Add/remove Some() or Ok() or Err() wrapper #18383

Open adamchalmers opened 2 weeks ago

adamchalmers commented 2 weeks ago

I frequently find myself refactoring code and needing to either add or remove a Some() wrapper from an expression. Similar need for Ok() and Err(). It'd be great if Rust Analyzer had an action to add or remove these wrappers.

I can approximate this somewhat with macros of key sequences in my editor, but it'd be neat if RA could do it :)

Giga-Bowser commented 2 weeks ago

@rustbot claim

lnicola commented 2 weeks ago

In some cases we offer these as diagnostic quick fixes:

let x: Option<i32>  = 42; // Wrap in Some
let x: i32 = Some(42); // no Unwrap available

let x: Result<i32, ()>  = 42; // Wrap in Ok
let x: i32 = Ok(42); // No Unwrap available

Given that, I'm not sure we need another assist.

Giga-Bowser commented 2 weeks ago

I'll look into adding an equivalent unwrap fix to that diagnostic