Skip to content

"Convert match to let-else" assist #13254

Closed
@jonas-schievink

Description

@jonas-schievink

(let-else will be stable in about 6 weeks from now (Rust 1.65); we should probably not ship this assist before then)

It would be nice to have an assist to rewrite let statements with a match like the following, to their corresponding let-else form:

let val = match opt {
    Some(it) => it,
    None => return,
};

->

let Some(val) = opt else { return };

Criteria for the assist should be:

  • let statement whose initializer is a match expression
  • match has 2 arms, the first extracts data, the second has a diverging expression

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions