Skip to content

serde 1.0.211 breaks with = "" inside of macros #2844

@DaniPopes

Description

@DaniPopes

I tried this code:

macro_rules! declare_in_macro {
    ($with:literal) => {
        #[derive(serde::Serialize)]
        pub struct S {
            #[serde(with = $with)]
            f: i32,
        }
    };
}
declare_in_macro!("display");

mod display {
    pub fn serialize<S: serde::ser::Serializer>(_: &i32, _: S) -> Result<S::Ok, S::Error> {
        unimplemented!()
    }
}

with feature "derive":

  • serde 1.0.210 compiles
  • serde 1.0.211 fails with:
    error[E0424]: expected value, found module `self`
      --> src/lib.rs:10:19
       |
    3  |         #[derive(serde::Serialize)]
       |                  ---------------- this function has a `self` parameter, but a macro invocation can only access identifiers it receives from parameters
    ...
    10 | declare_in_macro!("display");
       |                   ^^^^^^^^^ `self` value is a keyword only available in methods with a `self` parameter
    
    error[E0425]: cannot find value `__s` in this scope
      --> src/lib.rs:10:19
       |
    10 | declare_in_macro!("display");
       |                   ^^^^^^^^^ not found in this scope

Also reported at #2558 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions