Use call_site in 'with' attribute

This commit is contained in:
David Tolnay 2018-01-09 20:34:29 -08:00
parent b313f947dc
commit ddc4b50d4d
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
3 changed files with 9 additions and 4 deletions

View File

@ -12,6 +12,7 @@ readme = "README.md"
include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
[dependencies]
proc-macro2 = "0.2"
syn = { version = "0.12", default-features = false, features = ["derive", "parsing", "clone-impls"] }
[badges]

View File

@ -8,12 +8,14 @@
use Ctxt;
use syn;
use syn::Ident;
use syn::Meta::{List, NameValue, Word};
use syn::NestedMeta::{Literal, Meta};
use syn::punctuated::Punctuated;
use syn::synom::Synom;
use std::collections::BTreeSet;
use std::str::FromStr;
use proc_macro2::Span;
// This module handles parsing of `#[serde(...)]` attributes. The entrypoints
// are `attr::Container::from_ast`, `attr::Variant::from_ast`, and
@ -577,10 +579,10 @@ impl Variant {
Meta(NameValue(ref m)) if m.ident == "with" => {
if let Ok(path) = parse_lit_into_path(cx, m.ident.as_ref(), &m.lit) {
let mut ser_path = path.clone();
ser_path.segments.push("serialize".into());
ser_path.segments.push(Ident::new("serialize", Span::call_site()).into());
serialize_with.set(ser_path);
let mut de_path = path;
de_path.segments.push("deserialize".into());
de_path.segments.push(Ident::new("deserialize", Span::call_site()).into());
deserialize_with.set(de_path);
}
}
@ -819,10 +821,10 @@ impl Field {
Meta(NameValue(ref m)) if m.ident == "with" => {
if let Ok(path) = parse_lit_into_path(cx, m.ident.as_ref(), &m.lit) {
let mut ser_path = path.clone();
ser_path.segments.push("serialize".into());
ser_path.segments.push(Ident::new("serialize", Span::call_site()).into());
serialize_with.set(ser_path);
let mut de_path = path;
de_path.segments.push("deserialize".into());
de_path.segments.push(Ident::new("deserialize", Span::call_site()).into());
deserialize_with.set(de_path);
}
}

View File

@ -12,6 +12,8 @@
#[macro_use]
extern crate syn;
extern crate proc_macro2;
pub mod ast;
pub mod attr;