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

Converging let else #3650

Open
DerpMcDerp opened this issue May 31, 2024 · 1 comment
Open

Converging let else #3650

DerpMcDerp opened this issue May 31, 2024 · 1 comment

Comments

@DerpMcDerp
Copy link

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);
@workingjubilee
Copy link
Member

workingjubilee commented Jun 15, 2024

While I have occasionally wanted this sort of conciseness, I don't think it's worth special-casing single-name patterns. It's best if, as much as possible, let $pat is equivalent to all other cases of pattern matching, and thus let x should be, as much as possible, just binding the entire thing and not enable any special syntactic powers for the rest of the statement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants