Don't need aster to construct syn::Ident

This commit is contained in:
David Tolnay 2017-01-12 21:15:13 -08:00
parent b0d20afdfb
commit 3951ef91c0
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 17 additions and 17 deletions

View File

@ -1,4 +1,4 @@
use syn::{self, aster};
use syn::{self, aster, Ident};
use quote::Tokens;
use bound;
@ -28,7 +28,7 @@ pub fn expand_derive_deserialize(item: &syn::MacroInput) -> Result<Tokens, Strin
let where_clause = &impl_generics.where_clause;
let dummy_const = aster::id(format!("_IMPL_DESERIALIZE_FOR_{}", item.ident));
let dummy_const = Ident::new(format!("_IMPL_DESERIALIZE_FOR_{}", item.ident));
Ok(quote! {
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
@ -312,7 +312,7 @@ fn deserialize_seq(
let let_values: Vec<_> = fields.iter()
.enumerate()
.map(|(i, field)| {
let name = aster::id(format!("__field{}", i));
let name = Ident::new(format!("__field{}", i));
if field.attrs.skip_deserializing() {
let default = expr_is_missing(&field.attrs);
quote! {
@ -354,14 +354,14 @@ fn deserialize_seq(
.enumerate()
.map(|(i, field)| {
let ident = field.ident.clone().expect("struct contains unnamed fields");
let value = aster::id(format!("__field{}", i));
let value = Ident::new(format!("__field{}", i));
quote!(#ident: #value)
});
quote! {
#type_path { #(#args),* }
}
} else {
let args = (0..fields.len()).map(|i| aster::id(format!("__field{}", i)));
let args = (0..fields.len()).map(|i| Ident::new(format!("__field{}", i)));
quote! {
#type_path ( #(#args),* )
}
@ -512,7 +512,7 @@ fn deserialize_item_enum(
// Match arms to extract a variant from a string
let mut variant_arms = vec![];
for (i, variant) in variants.iter().filter(|variant| !variant.attrs.skip_deserializing()).enumerate() {
let variant_name = aster::id(format!("__field{}", i));
let variant_name = Ident::new(format!("__field{}", i));
let variant_name = quote!(__Field::#variant_name);
let block = deserialize_variant(
@ -649,7 +649,7 @@ fn deserialize_field_visitor(
) -> Tokens {
// Create the field names for the fields.
let field_idents: &Vec<_> = &(0 .. field_names.len())
.map(|i| aster::id(format!("__field{}", i)))
.map(|i| Ident::new(format!("__field{}", i)))
.collect();
let ignore_variant = if is_variant || item_attrs.deny_unknown_fields() {
@ -764,7 +764,7 @@ fn deserialize_map(
let fields_names = fields.iter()
.enumerate()
.map(|(i, field)|
(field, aster::id(format!("__field{}", i))))
(field, Ident::new(format!("__field{}", i))))
.collect::<Vec<_>>();
// Declare each field that will be deserialized.

View File

@ -1,4 +1,4 @@
use syn::{self, aster};
use syn::{self, aster, Ident};
use quote::Tokens;
use bound;
@ -22,7 +22,7 @@ pub fn expand_derive_serialize(item: &syn::MacroInput) -> Result<Tokens, String>
let where_clause = &impl_generics.where_clause;
let dummy_const = aster::id(format!("_IMPL_SERIALIZE_FOR_{}", item.ident));
let dummy_const = Ident::new(format!("_IMPL_SERIALIZE_FOR_{}", item.ident));
Ok(quote! {
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
@ -159,7 +159,7 @@ fn serialize_tuple_struct(
fields,
impl_generics,
false,
aster::id("serialize_tuple_struct_elt"),
Ident::new("serialize_tuple_struct_elt"),
);
let type_name = item_attrs.name().serialize_name();
@ -184,7 +184,7 @@ fn serialize_struct(
fields,
impl_generics,
false,
aster::id("serialize_struct_elt"),
Ident::new("serialize_struct_elt"),
);
let type_name = item_attrs.name().serialize_name();
@ -299,7 +299,7 @@ fn serialize_variant(
},
Style::Tuple => {
let field_names = (0 .. variant.fields.len())
.map(|i| aster::id(format!("__field{}", i)));
.map(|i| Ident::new(format!("__field{}", i)));
let block = serialize_tuple_variant(
type_name,
@ -373,7 +373,7 @@ fn serialize_tuple_variant(
fields,
generics,
true,
aster::id("serialize_tuple_variant_elt"),
Ident::new("serialize_tuple_variant_elt"),
);
let len = serialize_stmts.len();
@ -403,7 +403,7 @@ fn serialize_struct_variant(
fields,
generics,
true,
aster::id("serialize_struct_variant_elt"),
Ident::new("serialize_struct_variant_elt"),
);
let item_name = item_attrs.name().serialize_name();
@ -448,10 +448,10 @@ fn serialize_tuple_struct_visitor(
.enumerate()
.map(|(i, field)| {
let mut field_expr = if is_enum {
let id = aster::id(format!("__field{}", i));
let id = Ident::new(format!("__field{}", i));
quote!(#id)
} else {
let i = aster::id(i);
let i = Ident::new(i);
quote!(&self.#i)
};