Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
adamchalmers opened this issue Oct 23, 2024 · 3 comments · May be fixed by #18458
Open

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

adamchalmers opened this issue Oct 23, 2024 · 3 comments · May be fixed by #18458
Assignees
Labels
A-assists C-feature Category: feature request

Comments

@adamchalmers
Copy link

adamchalmers commented Oct 23, 2024

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 :)

@adamchalmers adamchalmers added the C-feature Category: feature request label Oct 23, 2024
@Giga-Bowser
Copy link
Contributor

@rustbot claim

@lnicola
Copy link
Member

lnicola commented Oct 23, 2024

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
Copy link
Contributor

Giga-Bowser commented Oct 23, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-assists C-feature Category: feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants