Skip to content

"unexpected token" macro-error on derive macro

Closed

Description

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions