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

serde::json macro invocation failed to parse #6876

Closed
extremegf opened this issue Dec 14, 2020 · 6 comments
Closed

serde::json macro invocation failed to parse #6876

extremegf opened this issue Dec 14, 2020 · 6 comments
Labels
A-macro macro expansion S-actionable Someone could pick this issue up and work on it right now

Comments

@extremegf
Copy link
Contributor

extremegf commented Dec 14, 2020

This is a new problem, as the snippets that now fail in my codebase used to be handled without issue.

I did some bisecting. This worked fine on v0.2.400 and fails on v0.2.408. It also fails on v0.2.416, albeit with a smaller red highlight.

Steps to reproduce:

lib.rs

use serde_json::json;

fn foo() {
    json!({ "a": "b" });
}

Cargo.toml

[dependencies]
serde = "1.0"
serde_json = "1"

Observe that the json! call is highlighted red with "failed to parse macro invocation".

@lnicola lnicola added the A-macro macro expansion label Dec 14, 2020
@flodiebold flodiebold changed the title Possible regression in macro parser serde::json macro invocation failed to parse Dec 14, 2020
@flodiebold flodiebold added the S-actionable Someone could pick this issue up and work on it right now label Dec 14, 2020
@flodiebold
Copy link
Member

It probably failed to expand before those versions; we just didn't have the diagnostic yet. You can disable the error for now by adding "macro-error" to the rust-analyzer.diagnostics.disabled setting.

@flodiebold
Copy link
Member

This was also reported as a comment in #6704, but it might not be the same issue.

@lnicola
Copy link
Member

lnicola commented Dec 14, 2020

Reproducer:

macro_rules! json_internal {
    ({ $tt:tt }) => {
        let _ = 42;
    };
}

fn main() {
    json_internal!({ "a" });
}

@flodiebold
Copy link
Member

flodiebold commented Dec 14, 2020

Hmm that looks like the same expanding-to-statements problem as #6811 then. Which actually #6704 is probably as well.

@lnicola
Copy link
Member

lnicola commented Dec 14, 2020

That's right. Closing as duplicate of #6811.

@lnicola lnicola closed this as completed Dec 14, 2020
@extremegf
Copy link
Contributor Author

It probably failed to expand before those versions; we just didn't have the diagnostic yet. You can disable the error for now by adding "macro-error" to the rust-analyzer.diagnostics.disabled setting.

Thank you. That's a useful workaround!

I'm impressed at how quickly this was analyzed by the RA team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macro macro expansion S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

No branches or pull requests

3 participants