Skip to content

MBE doesn't bracket reference arguments #9996

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

Closed
lnicola opened this issue Aug 23, 2021 · 3 comments
Closed

MBE doesn't bracket reference arguments #9996

lnicola opened this issue Aug 23, 2021 · 3 comments
Labels
A-macro macro expansion C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now

Comments

@lnicola
Copy link
Member

lnicola commented Aug 23, 2021

CC #8961

struct Options {
    casei: Option<bool>,
}
const CASEI: Options = Options { casei: Some(true) };

macro_rules! toregex {
    ($name:ident, $options:expr) => {
        #[test]
        fn $name() {
            if let Some(casei) = $options.casei {
                foo(casei);
            }
        }
    };
}

toregex!(re_casei, &CASEI);

fn foo(_c: bool) {}

If you macro-expand toregex, it produces if let Some(casei) = &CASEI.casei, causing a compilation error and a and type mismatch. The correct expansion is if let Some(casei) = (&CASEI).casei.

@lnicola lnicola added A-macro macro expansion S-actionable Someone could pick this issue up and work on it right now labels Aug 23, 2021
@lnicola lnicola changed the title MBE doesn't bracket arguments MBE doesn't bracket reference arguments Aug 23, 2021
@flodiebold
Copy link
Member

Hmm isn't this supposed to work by introducing 'invisible' parens? But obviously something is going wrong there...

@lnicola
Copy link
Member Author

lnicola commented Aug 23, 2021

I think so, and we had some changes related to token grouping, IIRC. We should still display the brackets for convenience, though.

@lnicola
Copy link
Member Author

lnicola commented Sep 10, 2021

This was apparently fixed by #10044. For some reason, it doesn't reproduce without the #[test] attribute.

@lnicola lnicola added the C-bug Category: bug label Sep 13, 2021
@lnicola lnicola closed this as completed Dec 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macro macro expansion C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

No branches or pull requests

2 participants