Stream: t-lang

Topic: Discussion on early-return from failed match?


BatmanAoD (Kyle Strand) (May 22 2020 at 15:19, on Zulip):

@nikomatsakis mentioned that there had been some discussion about adding a language feature to simplify code like this that combines control flow with destructuring:

fn fo() {
    let x = match bar {
        Some(v) => v,
        None => ... return
    };
}

Neither of us could find an open RFC on the topic, though. Does anyone remember such a discussion and know where it might be found?

Hanna Kruppe (May 22 2020 at 16:06, on Zulip):

not an open RFC, but: https://github.com/rust-lang/rfcs/pull/1303

Josh Triplett (May 22 2020 at 17:07, on Zulip):

@BatmanAoD (Kyle Strand) We are currently considering reopening that discussion.

Josh Triplett (May 22 2020 at 17:08, on Zulip):

There's renewed interest among the lang team in a let...else construct.

BatmanAoD (Kyle Strand) (May 22 2020 at 17:29, on Zulip):

Great! I had some thoughts on the subject yesterday, but want to read through what's already been proposed/discussed.

BatmanAoD (Kyle Strand) (May 22 2020 at 19:15, on Zulip):

Wow, that was long. I've added my two cents, though I'm not sure the end of that thread is really the best place for it. https://github.com/rust-lang/rfcs/pull/1303#issuecomment-632866111

nikomatsakis (May 22 2020 at 19:16, on Zulip):

lol

nikomatsakis (May 22 2020 at 19:17, on Zulip):

you see why I brought this up as a place where

nikomatsakis (May 22 2020 at 19:17, on Zulip):

I would prefer for that iteration to be taking place in a project group

BatmanAoD (Kyle Strand) (May 22 2020 at 19:17, on Zulip):

indeed!

nikomatsakis (May 22 2020 at 19:17, on Zulip):

and hopefully with the first aim of "discovering the space of solutions"

nikomatsakis (May 22 2020 at 19:17, on Zulip):

to some extent that's already been done

nikomatsakis (May 22 2020 at 19:17, on Zulip):

so maybe it's "documenting" now

BatmanAoD (Kyle Strand) (May 22 2020 at 19:17, on Zulip):

I believe my suggestion is actually novel, at least within that thread!

nikomatsakis (May 22 2020 at 19:17, on Zulip):

but I think it's an interesting case also of:

BatmanAoD (Kyle Strand) (May 22 2020 at 19:17, on Zulip):

(Which is not to say that's necessarily a good thing)

Josh Triplett (May 22 2020 at 20:09, on Zulip):

It's certainly a novel solution. I'm not sure if it'd be preferable to let pattern = expr else {}, though.

Josh Triplett (May 22 2020 at 20:10, on Zulip):

That would work for any pattern match, not just Option or Result.

BatmanAoD (Kyle Strand) (May 22 2020 at 20:50, on Zulip):

I guess I didn't make this explicit in my post, but with both ?{...} and expect, let pattern = expr else {...} would be expressed as let x = expr expect pattern ? {...}.

Josh Triplett (May 23 2020 at 06:28, on Zulip):

Yeah, that seemed clear from your post.

Josh Triplett (May 23 2020 at 06:29, on Zulip):

At that point, though, it's not far off from just writing let x = if let pattern = expr { x } else { return }.

BatmanAoD (Kyle Strand) (May 23 2020 at 19:15, on Zulip):

The advantage I see is that expect and ?{} could be implemented, stabilized, and used independently of each other. Though someone pointed out on the thread that ?{} is already legal syntax.

scottmcm (Jun 01 2020 at 19:59, on Zulip):

@BatmanAoD (Kyle Strand) There's also been discussion of it on IRLO in the form of let x = v ☃ return;, along with things like let x = v ☃ 0;, such as https://internals.rust-lang.org/t/something-for-coalescing-aka-generalized-improved-or-else/9295?u=scottmcm

Last update: Jun 05 2020 at 22:30UTC