Skip to content

Commit

Permalink
Add regression test for issue 2844
Browse files Browse the repository at this point in the history
    error[E0424]: expected value, found module `self`
      --> test_suite/tests/regression/issue2844.rs:13:19
       |
    5  |         #[derive(Serialize, Deserialize)]
       |                  --------- this function has a `self` parameter, but a macro invocation can only access identifiers it receives from parameters
    ...
    13 | declare_in_macro!("with");
       |                   ^^^^^^ `self` value is a keyword only available in methods with a `self` parameter

    error[E0425]: cannot find value `__s` in this scope
      --> test_suite/tests/regression/issue2844.rs:13:19
       |
    13 | declare_in_macro!("with");
       |                   ^^^^^^ not found in this scope

    error[E0425]: cannot find value `__deserializer` in this scope
      --> test_suite/tests/regression/issue2844.rs:13:19
       |
    13 | declare_in_macro!("with");
       |                   ^^^^^^ not found in this scope
  • Loading branch information
dtolnay committed Oct 22, 2024
1 parent 29d4f3e commit 0058c72
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test_suite/tests/regression/issue2844.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use serde_derive::{Deserialize, Serialize};

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

declare_in_macro!("with");

mod with {
use serde::{Deserializer, Serializer};

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

pub fn deserialize<'de, D>(_: D) -> Result<i32, D::Error>
where
D: Deserializer<'de>,
{
unimplemented!()
}
}

0 comments on commit 0058c72

Please sign in to comment.