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

Allow #[auto_enum] to be directly used on if expressions #86

Closed
taiki-e opened this issue Jan 29, 2020 · 5 comments · Fixed by #89
Closed

Allow #[auto_enum] to be directly used on if expressions #86

taiki-e opened this issue Jan 29, 2020 · 5 comments · Fixed by #89
Labels
A-auto_enum Area: #[auto_enum] C-enhancement Category: A new feature or an improvement for an existing one

Comments

@taiki-e
Copy link
Owner

taiki-e commented Jan 29, 2020

Once rust-lang/rust#68618 is resolved, we can support this.

@taiki-e taiki-e added C-enhancement Category: A new feature or an improvement for an existing one S-blocked Status: Blocked on something else labels Jan 29, 2020
@Aaron1011
Copy link

This is no longer blocked.

@Boscop
Copy link

Boscop commented Apr 12, 2020

I've been using auto_enums on let x = if .. exprs and it's working. Or do you mean if exprs without let?

Btw, any idea why rustc complains about "unnecessary braces around function argument" after I updated my nightly? rust-lang/rust#71080

@taiki-e
Copy link
Owner Author

taiki-e commented Apr 13, 2020

@Boscop

Or do you mean if exprs without let?

Yes, basically I want to annotate if expressions without depending on let.

Practically the same as the current one, it would be nice to support the following styles:

#[auto_enum]
fn a() {
    let res = {
        // This is the same as using #[auto_enum] on `let`, 
        // but maybe easier to read depending on the length of the block.
        #[auto_enum]
        if x {
            // ...
        } else {
            // ...
        }
    };
}

#[auto_enum]
fn b() -> Option<impl Foo> {
    // Equivalent to `#[auto_enum] let res = if ...` and `Some(res)`
    Some(#[auto_enum] if x { y } else { x })
}

And, these are already available on match expressions, so we can provide more consistent support.

@taiki-e
Copy link
Owner Author

taiki-e commented Apr 13, 2020

Btw, any idea why rustc complains about "unnecessary braces around function argument" after I updated my nightly? rust-lang/rust#71080

Thanks for reporting it, I will look into it.

@taiki-e
Copy link
Owner Author

taiki-e commented Apr 14, 2020

And, these are already available on match expressions, so we can provide more consistent support.

Oh..., this comment is not correct. The second example does not work without unstable features even if I replace if with a match (#90, if I have unstable features enabled, both will work.)
Also, the first example actually seems to be already supported. (#89)

@bors bors bot closed this as completed in 30f02d6 Apr 14, 2020
@bors bors bot closed this as completed in #89 Apr 14, 2020
@taiki-e taiki-e added the A-auto_enum Area: #[auto_enum] label Apr 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-auto_enum Area: #[auto_enum] C-enhancement Category: A new feature or an improvement for an existing one
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants