Bump to syn 0.12 and quote 0.4

epel9
Josh Stone 7 years ago
parent aa44bb22f5
commit a9e239a63f

@ -0,0 +1,240 @@
From f551ddd7f122a761363d3413c6f1c3c59df0eb4f Mon Sep 17 00:00:00 2001
From: Josh Stone <jistone@redhat.com>
Date: Fri, 9 Mar 2018 17:03:43 -0800
Subject: [PATCH] Update to syn 0.12 and quote 0.4
This is mostly just updating names -- it should behave exactly the same.
---
src/lib.rs | 119 ++++++++++++++++++++++++++++++-------------------------------
1 file changed, 59 insertions(+), 60 deletions(-)
diff --git a/src/lib.rs b/src/lib.rs
index a6c301319f96..c32652fbaf88 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -7,14 +7,15 @@ extern crate quote;
use proc_macro::TokenStream;
-fn impl_struct(name: &syn::Ident, fields: &[syn::Field]) -> quote::Tokens {
- let items: Vec<_> = fields.iter().map(|f| {
+fn impl_struct(name: &syn::Ident, fields: &syn::FieldsNamed) -> quote::Tokens {
+ let items: Vec<_> = fields.named.iter().map(|f| {
let ident = &f.ident;
let ty = &f.ty;
match ty {
- &syn::Ty::Array(_, ref constexpr) => {
- match constexpr {
- &syn::ConstExpr::Lit(syn::Lit::Int(size, _)) => {
+ &syn::Type::Array(ref array) => {
+ match array.len {
+ syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Int(ref int), ..}) => {
+ let size = int.value();
quote! {
#ident: { let mut __tmp: #ty = [0; #size as usize]; src.gread_inout_with(offset, &mut __tmp, ctx)?; __tmp }
}
@@ -44,13 +45,13 @@ fn impl_struct(name: &syn::Ident, fields: &[syn::Field]) -> quote::Tokens {
}
}
-fn impl_try_from_ctx(ast: &syn::MacroInput) -> quote::Tokens {
+fn impl_try_from_ctx(ast: &syn::DeriveInput) -> quote::Tokens {
let name = &ast.ident;
- match &ast.body {
- &syn::Body::Struct(ref data) => {
- match data {
- &syn::VariantData::Struct(ref fields) => {
- impl_struct(name, &fields)
+ match ast.data {
+ syn::Data::Struct(ref data) => {
+ match data.fields {
+ syn::Fields::Named(ref fields) => {
+ impl_struct(name, fields)
},
_ => {
panic!("Pread can only be derived for a regular struct with public fields")
@@ -63,18 +64,17 @@ fn impl_try_from_ctx(ast: &syn::MacroInput) -> quote::Tokens {
#[proc_macro_derive(Pread)]
pub fn derive_pread(input: TokenStream) -> TokenStream {
- let s = input.to_string();
- let ast = syn::parse_macro_input(&s).unwrap();
+ let ast: syn::DeriveInput = syn::parse(input).unwrap();
let gen = impl_try_from_ctx(&ast);
- gen.parse().unwrap()
+ gen.into()
}
-fn impl_try_into_ctx(name: &syn::Ident, fields: &[syn::Field]) -> quote::Tokens {
- let items: Vec<_> = fields.iter().map(|f| {
+fn impl_try_into_ctx(name: &syn::Ident, fields: &syn::FieldsNamed) -> quote::Tokens {
+ let items: Vec<_> = fields.named.iter().map(|f| {
let ident = &f.ident;
let ty = &f.ty;
match ty {
- &syn::Ty::Array(_, _) => {
+ &syn::Type::Array(_) => {
quote! {
for i in 0..self.#ident.len() {
dst.gwrite_with(self.#ident[i], offset, ctx)?;
@@ -103,13 +103,13 @@ fn impl_try_into_ctx(name: &syn::Ident, fields: &[syn::Field]) -> quote::Tokens
}
}
-fn impl_pwrite(ast: &syn::MacroInput) -> quote::Tokens {
+fn impl_pwrite(ast: &syn::DeriveInput) -> quote::Tokens {
let name = &ast.ident;
- match &ast.body {
- &syn::Body::Struct(ref data) => {
- match data {
- &syn::VariantData::Struct(ref fields) => {
- impl_try_into_ctx(name, &fields)
+ match ast.data {
+ syn::Data::Struct(ref data) => {
+ match data.fields {
+ syn::Fields::Named(ref fields) => {
+ impl_try_into_ctx(name, fields)
},
_ => {
panic!("Pwrite can only be derived for a regular struct with public fields")
@@ -122,10 +122,9 @@ fn impl_pwrite(ast: &syn::MacroInput) -> quote::Tokens {
#[proc_macro_derive(Pwrite)]
pub fn derive_pwrite(input: TokenStream) -> TokenStream {
- let s = input.to_string();
- let ast = syn::parse_macro_input(&s).unwrap();
+ let ast: syn::DeriveInput = syn::parse(input).unwrap();
let gen = impl_pwrite(&ast);
- gen.parse().unwrap()
+ gen.into()
}
fn size_with(name: &syn::Ident) -> quote::Tokens {
@@ -140,12 +139,12 @@ fn size_with(name: &syn::Ident) -> quote::Tokens {
}
}
-fn impl_size_with(ast: &syn::MacroInput) -> quote::Tokens {
+fn impl_size_with(ast: &syn::DeriveInput) -> quote::Tokens {
let name = &ast.ident;
- match &ast.body {
- &syn::Body::Struct(ref data) => {
- match data {
- &syn::VariantData::Struct(_) => {
+ match ast.data {
+ syn::Data::Struct(ref data) => {
+ match data.fields {
+ syn::Fields::Named(_) => {
size_with(name)
},
_ => {
@@ -159,20 +158,21 @@ fn impl_size_with(ast: &syn::MacroInput) -> quote::Tokens {
#[proc_macro_derive(SizeWith)]
pub fn derive_sizewith(input: TokenStream) -> TokenStream {
- let s = input.to_string();
- let ast = syn::parse_macro_input(&s).unwrap();
+ let ast: syn::DeriveInput = syn::parse(input).unwrap();
let gen = impl_size_with(&ast);
- gen.parse().unwrap()
+ gen.into()
}
-fn impl_cread_struct(name: &syn::Ident, fields: &[syn::Field]) -> quote::Tokens {
- let items: Vec<_> = fields.iter().map(|f| {
+fn impl_cread_struct(name: &syn::Ident, fields: &syn::FieldsNamed) -> quote::Tokens {
+ let items: Vec<_> = fields.named.iter().map(|f| {
let ident = &f.ident;
let ty = &f.ty;
match ty {
- &syn::Ty::Array(ref arrty, ref constexpr) => {
- match constexpr {
- &syn::ConstExpr::Lit(syn::Lit::Int(size, _)) => {
+ &syn::Type::Array(ref array) => {
+ let arrty = &array.elem;
+ match array.len {
+ syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Int(ref int), ..}) => {
+ let size = int.value();
let incr = quote! { ::scroll::export::mem::size_of::<#arrty>() };
quote! {
#ident: {
@@ -209,13 +209,13 @@ fn impl_cread_struct(name: &syn::Ident, fields: &[syn::Field]) -> quote::Tokens
}
}
-fn impl_from_ctx(ast: &syn::MacroInput) -> quote::Tokens {
+fn impl_from_ctx(ast: &syn::DeriveInput) -> quote::Tokens {
let name = &ast.ident;
- match &ast.body {
- &syn::Body::Struct(ref data) => {
- match data {
- &syn::VariantData::Struct(ref fields) => {
- impl_cread_struct(name, &fields)
+ match ast.data {
+ syn::Data::Struct(ref data) => {
+ match data.fields {
+ syn::Fields::Named(ref fields) => {
+ impl_cread_struct(name, fields)
},
_ => {
panic!("IOread can only be derived for a regular struct with public fields")
@@ -228,19 +228,19 @@ fn impl_from_ctx(ast: &syn::MacroInput) -> quote::Tokens {
#[proc_macro_derive(IOread)]
pub fn derive_ioread(input: TokenStream) -> TokenStream {
- let s = input.to_string();
- let ast = syn::parse_macro_input(&s).unwrap();
+ let ast: syn::DeriveInput = syn::parse(input).unwrap();
let gen = impl_from_ctx(&ast);
- gen.parse().unwrap()
+ gen.into()
}
-fn impl_into_ctx(name: &syn::Ident, fields: &[syn::Field]) -> quote::Tokens {
- let items: Vec<_> = fields.iter().map(|f| {
+fn impl_into_ctx(name: &syn::Ident, fields: &syn::FieldsNamed) -> quote::Tokens {
+ let items: Vec<_> = fields.named.iter().map(|f| {
let ident = &f.ident;
let ty = &f.ty;
let size = quote! { ::scroll::export::mem::size_of::<#ty>() };
match ty {
- &syn::Ty::Array(ref arrty, _) => {
+ &syn::Type::Array(ref array) => {
+ let arrty = &array.elem;
quote! {
let size = ::scroll::export::mem::size_of::<#arrty>();
for i in 0..self.#ident.len() {
@@ -270,13 +270,13 @@ fn impl_into_ctx(name: &syn::Ident, fields: &[syn::Field]) -> quote::Tokens {
}
}
-fn impl_iowrite(ast: &syn::MacroInput) -> quote::Tokens {
+fn impl_iowrite(ast: &syn::DeriveInput) -> quote::Tokens {
let name = &ast.ident;
- match &ast.body {
- &syn::Body::Struct(ref data) => {
- match data {
- &syn::VariantData::Struct(ref fields) => {
- impl_into_ctx(name, &fields)
+ match ast.data {
+ syn::Data::Struct(ref data) => {
+ match data.fields {
+ syn::Fields::Named(ref fields) => {
+ impl_into_ctx(name, fields)
},
_ => {
panic!("IOwrite can only be derived for a regular struct with public fields")
@@ -289,8 +289,7 @@ fn impl_iowrite(ast: &syn::MacroInput) -> quote::Tokens {
#[proc_macro_derive(IOwrite)]
pub fn derive_iowrite(input: TokenStream) -> TokenStream {
- let s = input.to_string();
- let ast = syn::parse_macro_input(&s).unwrap();
+ let ast: syn::DeriveInput = syn::parse(input).unwrap();
let gen = impl_iowrite(&ast);
- gen.parse().unwrap()
+ gen.into()
}
--
2.14.3

@ -7,19 +7,24 @@
Name: rust-%{crate}
Version: 0.9.1
Release: 2%{?dist}
Release: 3%{?dist}
Summary: Macros 1.1 derive implementation for Pread and Pwrite traits from scroll crate
License: MIT
URL: https://crates.io/crates/scroll_derive
Source0: https://crates.io/api/v1/crates/%{crate}/%{version}/download#/%{crate}-%{version}.crate
# Initial patched metadata
# * bump to syn 0.12 and quote 0.4
Patch0: scroll_derive-0.9.1-fix-metadata.diff
# https://github.com/m4b/scroll_derive/pull/4
Patch1: 0001-Update-to-syn-0.12-and-quote-0.4.patch
ExclusiveArch: %{rust_arches}
BuildRequires: rust-packaging
# [dependencies]
BuildRequires: (crate(quote) >= 0.3.15 with crate(quote) < 0.4.0)
BuildRequires: (crate(syn) >= 0.11.11 with crate(syn) < 0.12.0)
BuildRequires: (crate(quote) >= 0.4.0 with crate(quote) < 0.5.0)
BuildRequires: (crate(syn) >= 0.12.0 with crate(syn) < 0.13.0)
%if %{with check}
# [dev-dependencies]
BuildRequires: (crate(scroll) >= 0.9.0 with crate(scroll) < 0.10.0)
@ -60,6 +65,9 @@ which use %{crate} from crates.io.
%{cargo_registry}/%{crate}-%{version}/
%changelog
* Sat Mar 10 2018 Josh Stone <jistone@redhat.com> - 0.9.1-3
- Bump to syn 0.12 and quote 0.4
* Fri Feb 09 2018 Fedora Release Engineering <releng@fedoraproject.org> - 0.9.1-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild

@ -0,0 +1,14 @@
--- scroll_derive-0.9.1/Cargo.toml 1969-12-31T16:00:00-08:00
+++ scroll_derive-0.9.1/Cargo.toml 2018-03-09T17:11:40.884586-08:00
@@ -24,9 +24,9 @@
[lib]
proc-macro = true
[dependencies.quote]
-version = "0.3.15"
+version = "0.4"
[dependencies.syn]
-version = "0.11.11"
+version = "0.12"
[dev-dependencies.scroll]
version = "0.9"
Loading…
Cancel
Save