-
-
Notifications
You must be signed in to change notification settings - Fork 788
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2847 from dtolnay/newtypewith
Hygiene for macro-generated newtype struct deserialization with `with` attr
- Loading branch information
Showing
2 changed files
with
31 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#![allow(clippy::trivially_copy_pass_by_ref)] | ||
|
||
use serde_derive::Deserialize; | ||
|
||
macro_rules! declare_in_macro { | ||
($with:literal) => { | ||
#[derive(Deserialize)] | ||
pub struct S( | ||
#[serde(with = $with)] | ||
#[allow(dead_code)] | ||
i32, | ||
); | ||
}; | ||
} | ||
|
||
declare_in_macro!("with"); | ||
|
||
mod with { | ||
use serde::Deserializer; | ||
|
||
pub fn deserialize<'de, D>(_: D) -> Result<i32, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
unimplemented!() | ||
} | ||
} |