rfcs icon indicating copy to clipboard operation
rfcs copied to clipboard

Converging let else

Open DerpMcDerp opened this issue 8 months ago • 1 comments

Rust has:

let PATTERN: TYPE = EXPRESSION else DIVERGING_BLOCK;

but it should allow:

let PATTERN: TYPE = EXPRESSION else CONVERGING_BLOCK;

if PATTERN contains a single named variable. e.g.

let Foo(_, Some(Point2d(x, x))) | Bar(x) = foo() else {
	3
};
do_something(x);

=>

let x = match foo() {
	Foo(_, Some(Point2d(x, x))) | Bar(x) => x,
	_ => 3,
};
do_something(x);

DerpMcDerp avatar May 31 '24 21:05 DerpMcDerp