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

Implement macro expansion in IfExpr, IfExprConseqElse, IfExprConseqIf, IfExprConseqIfLet. #1170

Merged
merged 1 commit into from
Apr 26, 2022

Conversation

antego
Copy link
Contributor

@antego antego commented Apr 26, 2022

Addresses #1141. Following up on #1161.

This change adds support for the macros inside the if condition expressions.

Things to note:

  1. Judging by my research, the IfExprConseqIfLet isn't used. The parser treats the syntax let var = if ... as a let expression followed by if expression:
    Screen Shot 2022-04-26 at 9 47 29 am
  2. I didn't add the macro expansion to the IfLetExpr... family of expressions because I wasn't able to write a test case reproducing the missing macro expansion. I've tried the following code
fn main() -> i32 {
    let mut res = 0;

    enum E {
        X(u8),
        Y(u8),
        Z(u8),
    }
    let v = E::Y(12);
    if let E::Y(n) = v {
        res = 1;
    }

    0
}

which caused the compiler error

FAIL: rust/compile/macro43.rs (internal compiler error: in append_reference_for_def, at rust/resolve/rust-name-resolver.h:227)

Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff :DD Thank you for working on this!

@CohenArthur
Copy link
Member

@antego I'd say open issues for your two notes: The first one is something that we can maybe discuss about removing (or it may be caused by a parser bug), and the second one needs to be fixed eventually. It would be really helpful :)

bors r+

@bors
Copy link
Contributor

bors bot commented Apr 26, 2022

Build succeeded:

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

Successfully merging this pull request may close these issues.

3 participants