Merge pull request #1201 from alexcrichton/proc-macro2-v3
Update to syn/quote/proc-macro2 new apis
This commit is contained in:
commit
21698f264a
@ -23,10 +23,10 @@ name = "serde_derive"
|
||||
proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
proc-macro2 = "0.2"
|
||||
quote = "0.4"
|
||||
proc-macro2 = "0.3"
|
||||
quote = "0.5"
|
||||
serde_derive_internals = { version = "=0.22.2", default-features = false, path = "../serde_derive_internals" }
|
||||
syn = { version = "0.12", features = ["visit"] }
|
||||
syn = { version = "0.13", features = ["visit"] }
|
||||
|
||||
[dev-dependencies]
|
||||
serde = { version = "1.0", path = "../serde" }
|
||||
|
@ -14,7 +14,7 @@ use syn::punctuated::Punctuated;
|
||||
use internals::ast::{Data, Container};
|
||||
use internals::attr;
|
||||
|
||||
use proc_macro2::{Span, Term};
|
||||
use proc_macro2::Span;
|
||||
|
||||
// Remove the default from every type parameter because in the generated impls
|
||||
// they look like associated types: "error: associated type bindings are not
|
||||
@ -192,6 +192,7 @@ where
|
||||
// the bound e.g. Serialize
|
||||
bounds: vec![
|
||||
syn::TypeParamBound::Trait(syn::TraitBound {
|
||||
paren_token: None,
|
||||
modifier: syn::TraitBoundModifier::None,
|
||||
lifetimes: None,
|
||||
path: bound.clone(),
|
||||
@ -239,6 +240,7 @@ pub fn with_self_bound(
|
||||
// the bound e.g. Default
|
||||
bounds: vec![
|
||||
syn::TypeParamBound::Trait(syn::TraitBound {
|
||||
paren_token: None,
|
||||
modifier: syn::TraitBoundModifier::None,
|
||||
lifetimes: None,
|
||||
path: bound.clone(),
|
||||
@ -249,7 +251,7 @@ pub fn with_self_bound(
|
||||
}
|
||||
|
||||
pub fn with_lifetime_bound(generics: &syn::Generics, lifetime: &str) -> syn::Generics {
|
||||
let bound = syn::Lifetime::new(Term::intern(lifetime), Span::call_site());
|
||||
let bound = syn::Lifetime::new(lifetime, Span::call_site());
|
||||
let def = syn::LifetimeDef {
|
||||
attrs: Vec::new(),
|
||||
lifetime: bound,
|
||||
|
@ -10,7 +10,7 @@ use syn::{self, Ident, Index, Member};
|
||||
use syn::punctuated::Punctuated;
|
||||
use syn::spanned::Spanned;
|
||||
use quote::{ToTokens, Tokens};
|
||||
use proc_macro2::{Literal, Span, Term};
|
||||
use proc_macro2::{Literal, Span};
|
||||
|
||||
use bound;
|
||||
use fragment::{Expr, Fragment, Match, Stmts};
|
||||
@ -181,8 +181,8 @@ enum BorrowedLifetimes {
|
||||
impl BorrowedLifetimes {
|
||||
fn de_lifetime(&self) -> syn::Lifetime {
|
||||
match *self {
|
||||
BorrowedLifetimes::Borrowed(_) => syn::Lifetime::new(Term::intern("'de"), Span::call_site()),
|
||||
BorrowedLifetimes::Static => syn::Lifetime::new(Term::intern("'static"), Span::call_site()),
|
||||
BorrowedLifetimes::Borrowed(_) => syn::Lifetime::new("'de", Span::call_site()),
|
||||
BorrowedLifetimes::Static => syn::Lifetime::new("'static", Span::call_site()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -190,7 +190,7 @@ impl BorrowedLifetimes {
|
||||
match *self {
|
||||
BorrowedLifetimes::Borrowed(ref bounds) => Some(syn::LifetimeDef {
|
||||
attrs: Vec::new(),
|
||||
lifetime: syn::Lifetime::new(Term::intern("'de"), Span::call_site()),
|
||||
lifetime: syn::Lifetime::new("'de", Span::call_site()),
|
||||
colon_token: None,
|
||||
bounds: bounds.iter().cloned().collect(),
|
||||
}),
|
||||
@ -549,7 +549,7 @@ fn deserialize_seq(
|
||||
let visit = match field.attrs.deserialize_with() {
|
||||
None => {
|
||||
let field_ty = &field.ty;
|
||||
let span = Span::call_site().located_at(field.original.span());
|
||||
let span = field.original.span();
|
||||
let func = quote_spanned!(span=> _serde::de::SeqAccess::next_element::<#field_ty>);
|
||||
quote!(try!(#func(&mut __seq)))
|
||||
}
|
||||
@ -2193,7 +2193,7 @@ fn deserialize_map(
|
||||
let visit = match field.attrs.deserialize_with() {
|
||||
None => {
|
||||
let field_ty = &field.ty;
|
||||
let span = Span::call_site().located_at(field.original.span());
|
||||
let span = field.original.span();
|
||||
let func = quote_spanned!(span=> _serde::de::MapAccess::next_value::<#field_ty>);
|
||||
quote! {
|
||||
try!(#func(&mut __map))
|
||||
@ -2638,7 +2638,7 @@ fn expr_is_missing(field: &Field, cattrs: &attr::Container) -> Fragment {
|
||||
let name = field.attrs.name().deserialize_name();
|
||||
match field.attrs.deserialize_with() {
|
||||
None => {
|
||||
let span = Span::call_site().located_at(field.original.span());
|
||||
let span = field.original.span();
|
||||
let func = quote_spanned!(span=> _serde::private::de::missing_field);
|
||||
quote_expr! {
|
||||
try!(#func(#name))
|
||||
@ -2721,7 +2721,7 @@ impl<'a> ToTokens for DeTypeGenerics<'a> {
|
||||
if self.0.borrowed.de_lifetime_def().is_some() {
|
||||
let def = syn::LifetimeDef {
|
||||
attrs: Vec::new(),
|
||||
lifetime: syn::Lifetime::new(Term::intern("'de"), Span::call_site()),
|
||||
lifetime: syn::Lifetime::new("'de", Span::call_site()),
|
||||
colon_token: None,
|
||||
bounds: Punctuated::new(),
|
||||
};
|
||||
@ -2747,7 +2747,7 @@ impl<'a> ToTokens for InPlaceTypeGenerics<'a> {
|
||||
if self.0.borrowed.de_lifetime_def().is_some() {
|
||||
let def = syn::LifetimeDef {
|
||||
attrs: Vec::new(),
|
||||
lifetime: syn::Lifetime::new(Term::intern("'de"), Span::call_site()),
|
||||
lifetime: syn::Lifetime::new("'de", Span::call_site()),
|
||||
colon_token: None,
|
||||
bounds: Punctuated::new(),
|
||||
};
|
||||
@ -2772,7 +2772,7 @@ impl<'a> DeTypeGenerics<'a> {
|
||||
fn place_lifetime() -> syn::LifetimeDef {
|
||||
syn::LifetimeDef {
|
||||
attrs: Vec::new(),
|
||||
lifetime: syn::Lifetime::new(Term::intern("'place"), Span::call_site()),
|
||||
lifetime: syn::Lifetime::new("'place", Span::call_site()),
|
||||
colon_token: None,
|
||||
bounds: Punctuated::new(),
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ fn serialize_newtype_struct(
|
||||
field_expr = wrap_serialize_field_with(params, field.ty, path, &field_expr);
|
||||
}
|
||||
|
||||
let span = Span::call_site().located_at(field.original.span());
|
||||
let span = field.original.span();
|
||||
let func = quote_spanned!(span=> _serde::Serializer::serialize_newtype_struct);
|
||||
quote_expr! {
|
||||
#func(__serializer, #type_name, #field_expr)
|
||||
@ -880,7 +880,7 @@ fn serialize_tuple_struct_visitor(
|
||||
field_expr = wrap_serialize_field_with(params, field.ty, path, &field_expr);
|
||||
}
|
||||
|
||||
let span = Span::call_site().located_at(field.original.span());
|
||||
let span = field.original.span();
|
||||
let func = tuple_trait.serialize_element(span);
|
||||
let ser = quote! {
|
||||
try!(#func(&mut __serde_state, #field_expr));
|
||||
@ -923,7 +923,7 @@ fn serialize_struct_visitor(
|
||||
field_expr = wrap_serialize_field_with(params, field.ty, path, &field_expr);
|
||||
}
|
||||
|
||||
let span = Span::call_site().located_at(field.original.span());
|
||||
let span = field.original.span();
|
||||
let ser = if field.attrs.flatten() {
|
||||
quote! {
|
||||
try!(_serde::Serialize::serialize(&#field_expr, _serde::private::ser::FlatMapSerializer(&mut __serde_state)));
|
||||
|
@ -12,8 +12,8 @@ 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"] }
|
||||
proc-macro2 = "0.3"
|
||||
syn = { version = "0.13", default-features = false, features = ["derive", "parsing", "clone-impls"] }
|
||||
|
||||
[badges]
|
||||
travis-ci = { repository = "serde-rs/serde" }
|
||||
|
@ -15,7 +15,7 @@ use syn::punctuated::Punctuated;
|
||||
use syn::synom::{Synom, ParseError};
|
||||
use std::collections::BTreeSet;
|
||||
use std::str::FromStr;
|
||||
use proc_macro2::{Span, TokenStream, TokenNode, TokenTree};
|
||||
use proc_macro2::{Span, TokenStream, TokenTree, Group};
|
||||
|
||||
// This module handles parsing of `#[serde(...)]` attributes. The entrypoints
|
||||
// are `attr::Container::from_ast`, `attr::Variant::from_ast`, and
|
||||
@ -1160,7 +1160,7 @@ fn parse_lit_into_where(
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
|
||||
let where_string = syn::LitStr::new(&format!("where {}", string.value()), string.span);
|
||||
let where_string = syn::LitStr::new(&format!("where {}", string.value()), string.span());
|
||||
|
||||
parse_lit_str::<syn::WhereClause>(&where_string)
|
||||
.map(|wh| wh.predicates.into_iter().collect())
|
||||
@ -1410,21 +1410,17 @@ where
|
||||
|
||||
fn spanned_tokens(s: &syn::LitStr) -> Result<TokenStream, ParseError> {
|
||||
let stream = try!(syn::parse_str(&s.value()));
|
||||
Ok(respan_token_stream(stream, s.span))
|
||||
Ok(respan_token_stream(stream, s.span()))
|
||||
}
|
||||
|
||||
fn respan_token_stream(stream: TokenStream, span: Span) -> TokenStream {
|
||||
stream.into_iter().map(|token| respan_token_tree(token, span)).collect()
|
||||
}
|
||||
|
||||
fn respan_token_tree(token: TokenTree, span: Span) -> TokenTree {
|
||||
TokenTree {
|
||||
span: span,
|
||||
kind: match token.kind {
|
||||
TokenNode::Group(delimiter, nested) => {
|
||||
TokenNode::Group(delimiter, respan_token_stream(nested, span))
|
||||
}
|
||||
other => other,
|
||||
},
|
||||
fn respan_token_tree(mut token: TokenTree, span: Span) -> TokenTree {
|
||||
if let TokenTree::Group(ref mut g) = token {
|
||||
*g = Group::new(g.delimiter(), respan_token_stream(g.stream().clone(), span));
|
||||
}
|
||||
token.set_span(span);
|
||||
token
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ unstable = ["serde/unstable", "compiletest_rs"]
|
||||
|
||||
[dev-dependencies]
|
||||
fnv = "1.0"
|
||||
proc-macro2 = "0.2"
|
||||
proc-macro2 = "0.3"
|
||||
rustc-serialize = "0.3.16"
|
||||
serde = { path = "../serde", features = ["rc"] }
|
||||
serde_derive = { path = "../serde_derive", features = ["deserialize_in_place"] }
|
||||
|
Loading…
x
Reference in New Issue
Block a user