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

"unexpected token" macro-error on derive macro #17968

Closed
GREsau opened this issue Aug 26, 2024 · 9 comments · Fixed by #17972
Closed

"unexpected token" macro-error on derive macro #17968

GREsau opened this issue Aug 26, 2024 · 9 comments · Fixed by #17972
Assignees
Labels
A-proc-macro proc macro C-bug Category: bug

Comments

@GREsau
Copy link

GREsau commented Aug 26, 2024

rust-analyzer version: 0.3.2086-standalone (7106cd3be 2024-08-25)

rustc version: rustc 1.80.1 (3f5fd8dd4 2024-08-06)

editor or extension: VSCode, rust-analyzer v0.3.2086 (error does not occur with v0.3.2078)

relevant settings: n/a

repository link (if public, optional): n/a

code snippet to reproduce:
cargo add schemars (reproducible both with stable v0.8.21 and prerelease v1.0.0-alpha.11)

#[derive(schemars::JsonSchema)]
pub struct X;

fn main() {
    println!("{:?}", schemars::schema_for!(X))
}

image

The code compiles and runs fine. When running cargo expand and using schemars v1.0.0-alpha.11, the derive expands to:

const _: () = {
    #[automatically_derived]
    #[allow(unused_braces)]
    impl schemars::JsonSchema for X {
        fn schema_name() -> schemars::_alloc::borrow::Cow<'static, str> {
            schemars::_alloc::borrow::Cow::Borrowed("X")
        }
        fn schema_id() -> schemars::_alloc::borrow::Cow<'static, str> {
            schemars::_alloc::borrow::Cow::Borrowed("rust_test::X")
        }
        fn json_schema(generator: &mut schemars::SchemaGenerator) -> schemars::Schema {
            generator.subschema_for::<()>()
        }
    }
};

...which rust-analyzer has no problems with.

@GREsau GREsau added the C-bug Category: bug label Aug 26, 2024
@lnicola lnicola added A-macro macro expansion A-proc-macro proc macro and removed A-macro macro expansion labels Aug 26, 2024
@rever96
Copy link

rever96 commented Aug 26, 2024

I got the same problem.
Go back to v0.3.2078 until they will fix the problem

@SenojLuap
Copy link

Not sure if it's the same issue, but I get a similar looking error while using rocket's get macro
image

@ChayimFriedman2
Copy link
Contributor

ChayimFriedman2 commented Aug 26, 2024

@rustbot claim

@kerminek
Copy link

Not sure if it's the same issue, but I get a similar looking error while using rocket's get macro image

Same
Zrzut ekranu 2024-08-27 o 00 57 25

@ChayimFriedman2
Copy link
Contributor

@kerminek @SenojLuap The problem is module_path!() not expanding correctly. If rocket's #[get] uses it, it is likely the same problem indeed (you can check by r-a "Expand macro recursively"), do not use cargo-expand because it will expand module_path!() too.

@Spycemyster
Copy link

Not sure if it's the same issue, but I get a similar looking error while using rocket's get macro image

Switching to rust-analyzer 0.3.2078 fixes it for now (credit to @rever96)

@lnicola
Copy link
Member

lnicola commented Aug 27, 2024

v0.3.2089 should have a fix for this.

@GREsau
Copy link
Author

GREsau commented Aug 27, 2024

Thanks, I can confirm this is now resolved after updating the extension to v0.3.2089 🙂

@SenojLuap
Copy link

Same. Thanks!

lnicola pushed a commit to lnicola/rust that referenced this issue Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-proc-macro proc macro C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants