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

Macro error: expected Expr #19168

Open
colinmarc opened this issue Feb 17, 2025 · 3 comments
Open

Macro error: expected Expr #19168

colinmarc opened this issue Feb 17, 2025 · 3 comments
Labels
A-macro macro expansion C-bug Category: bug

Comments

@colinmarc
Copy link

rust-analyzer version: rust-analyzer 1.84.1 (e71f9a9 2025-01-27)

rustc version: rustc 1.84.1 (e71f9a9a9 2025-01-27)

editor or extension: zed or nvim

Image

I'm getting an LSP error on a macro that compiles fine. The issue is reproducible on commit ba3f8bce2749329d2b02922d7637e8546c5eb81b of https://github.com/colinmarc/magic-mirror.

Here is the macro invocation that rust-analyzer doesn't like:

https://github.com/colinmarc/magic-mirror/blob/ba3f8bce2749329d2b02922d7637e8546c5eb81b/mm-server/src/encoder/h264.rs#L22-L28

And here is where the macro lives:

https://github.com/colinmarc/magic-mirror/blob/ba3f8bce2749329d2b02922d7637e8546c5eb81b/mm-server/src/vulkan/chain.rs#L28

Please ignore how insane the macro is 😓 Building the project is also a bit of a hassle, sorry about that. It requires linux and cmake nasm protoc libxkbcommon-dev. Detailed build instructions here: https://colinmarc.github.io/magic-mirror/setup/server/#building-mmserver-from-source

@colinmarc colinmarc added the C-bug Category: bug label Feb 17, 2025
@lnicola lnicola added A-proc-macro proc macro A-macro macro expansion and removed A-proc-macro proc macro labels Feb 17, 2025
@ChayimFriedman2
Copy link
Contributor

Minimized reproduction:

macro_rules! a {
    ($t:tt) => {};
}

macro_rules! b {
    ($t:ty) => {
        a!($t);
    };
}

b!(&'static str);

None groups strike again...

@colinmarc
Copy link
Author

Thanks so much for boiling it down, I could not have gotten there.

Does that mean the issue is in __replace_expr? Do you have a suggested workaround for the time being?

@ChayimFriedman2
Copy link
Contributor

ChayimFriedman2 commented Feb 17, 2025

You can wrap it in parentheses:

                    Self::new(__replace_expr!(($HeadStruct) Default::default()), $(__replace_expr!(($Struct) Default::default()),)*)

colinmarc added a commit to colinmarc/magic-mirror that referenced this issue Feb 20, 2025
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
Projects
None yet
Development

No branches or pull requests

3 participants