Made clippy also check _derive, fixed clippy warnings
This commit is contained in:
parent
cffc9fcffa
commit
6361ad7d69
|
|
@ -1,3 +1,8 @@
|
||||||
|
[workspace]
|
||||||
|
members = [
|
||||||
|
"derive"
|
||||||
|
]
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "bincode"
|
name = "bincode"
|
||||||
version = "2.0.0-dev" # remember to update html_root_url and bincode_derive
|
version = "2.0.0-dev" # remember to update html_root_url and bincode_derive
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use proc_macro::TokenStream;
|
||||||
use proc_macro2::TokenStream as TokenStream2;
|
use proc_macro2::TokenStream as TokenStream2;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use quote::ToTokens;
|
use quote::ToTokens;
|
||||||
use syn::{spanned::Spanned, Field, Fields, Generics, Ident, Index, Variant};
|
use syn::{spanned::Spanned, Fields, Generics, Ident, Index, Variant};
|
||||||
pub struct DeriveEnum {
|
pub struct DeriveEnum {
|
||||||
name: Ident,
|
name: Ident,
|
||||||
generics: Generics,
|
generics: Generics,
|
||||||
|
|
@ -21,7 +21,7 @@ impl DeriveEnum {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_encodable(self) -> Result<TokenStream> {
|
pub fn generate_encodable(self) -> Result<TokenStream> {
|
||||||
let DeriveEnum {
|
let DeriveEnum {
|
||||||
name,
|
name,
|
||||||
generics,
|
generics,
|
||||||
|
|
@ -56,7 +56,7 @@ impl DeriveEnum {
|
||||||
Ok(result.into())
|
Ok(result.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_decodable(self) -> Result<TokenStream> {
|
pub fn generate_decodable(self) -> Result<TokenStream> {
|
||||||
let DeriveEnum {
|
let DeriveEnum {
|
||||||
name,
|
name,
|
||||||
generics,
|
generics,
|
||||||
|
|
@ -145,7 +145,7 @@ fn fields_to_names(fields: &Fields) -> Vec<TokenStream2> {
|
||||||
|
|
||||||
fn field_names_to_encodable(names: &[TokenStream2]) -> Vec<TokenStream2> {
|
fn field_names_to_encodable(names: &[TokenStream2]) -> Vec<TokenStream2> {
|
||||||
names
|
names
|
||||||
.into_iter()
|
.iter()
|
||||||
.map(|field| {
|
.map(|field| {
|
||||||
quote! {
|
quote! {
|
||||||
bincode::enc::Encodeable::encode(#field, &mut encoder)?;
|
bincode::enc::Encodeable::encode(#field, &mut encoder)?;
|
||||||
|
|
@ -165,7 +165,7 @@ fn fields_to_constructable_names(fields: &Fields) -> Vec<TokenStream2> {
|
||||||
.unnamed
|
.unnamed
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, f)| Index::from(i).to_token_stream())
|
.map(|(i, _)| Index::from(i).to_token_stream())
|
||||||
.collect(),
|
.collect(),
|
||||||
syn::Fields::Unit => Vec::new(),
|
syn::Fields::Unit => Vec::new(),
|
||||||
}
|
}
|
||||||
|
|
@ -173,7 +173,7 @@ fn fields_to_constructable_names(fields: &Fields) -> Vec<TokenStream2> {
|
||||||
|
|
||||||
fn field_names_to_decodable(names: &[TokenStream2]) -> Vec<TokenStream2> {
|
fn field_names_to_decodable(names: &[TokenStream2]) -> Vec<TokenStream2> {
|
||||||
names
|
names
|
||||||
.into_iter()
|
.iter()
|
||||||
.map(|field| {
|
.map(|field| {
|
||||||
quote! {
|
quote! {
|
||||||
#field: bincode::de::Decodable::decode(&mut decoder)?,
|
#field: bincode::de::Decodable::decode(&mut decoder)?,
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use proc_macro2::TokenStream as TokenStream2;
|
use proc_macro2::TokenStream as TokenStream2;
|
||||||
use quote::{quote, quote_spanned, ToTokens};
|
use quote::{quote, ToTokens};
|
||||||
use syn::{spanned::Spanned, Generics, Ident, Index};
|
use syn::{Generics, Ident, Index};
|
||||||
|
|
||||||
pub struct DeriveStruct {
|
pub struct DeriveStruct {
|
||||||
name: Ident,
|
name: Ident,
|
||||||
|
|
@ -33,7 +33,7 @@ impl DeriveStruct {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_encodable(self) -> Result<TokenStream> {
|
pub fn generate_encodable(self) -> Result<TokenStream> {
|
||||||
let DeriveStruct {
|
let DeriveStruct {
|
||||||
name,
|
name,
|
||||||
generics,
|
generics,
|
||||||
|
|
@ -63,7 +63,7 @@ impl DeriveStruct {
|
||||||
Ok(result.into())
|
Ok(result.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_decodable(self) -> Result<TokenStream> {
|
pub fn generate_decodable(self) -> Result<TokenStream> {
|
||||||
let DeriveStruct {
|
let DeriveStruct {
|
||||||
name,
|
name,
|
||||||
generics,
|
generics,
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,11 @@ fn derive_encodable_inner(input: DeriveInput) -> Result<TokenStream> {
|
||||||
match input.data {
|
match input.data {
|
||||||
syn::Data::Struct(struct_definition) => {
|
syn::Data::Struct(struct_definition) => {
|
||||||
DeriveStruct::parse(input.ident, input.generics, struct_definition)
|
DeriveStruct::parse(input.ident, input.generics, struct_definition)
|
||||||
.and_then(|str| str.to_encodable())
|
.and_then(|str| str.generate_encodable())
|
||||||
}
|
}
|
||||||
syn::Data::Enum(enum_definition) => {
|
syn::Data::Enum(enum_definition) => {
|
||||||
DeriveEnum::parse(input.ident, input.generics, enum_definition)
|
DeriveEnum::parse(input.ident, input.generics, enum_definition)
|
||||||
.and_then(|str| str.to_encodable())
|
.and_then(|str| str.generate_encodable())
|
||||||
}
|
}
|
||||||
syn::Data::Union(_) => Err(Error::UnionNotSupported),
|
syn::Data::Union(_) => Err(Error::UnionNotSupported),
|
||||||
}
|
}
|
||||||
|
|
@ -42,11 +42,11 @@ fn derive_decodable_inner(input: DeriveInput) -> Result<TokenStream> {
|
||||||
match input.data {
|
match input.data {
|
||||||
syn::Data::Struct(struct_definition) => {
|
syn::Data::Struct(struct_definition) => {
|
||||||
DeriveStruct::parse(input.ident, input.generics, struct_definition)
|
DeriveStruct::parse(input.ident, input.generics, struct_definition)
|
||||||
.and_then(|str| str.to_decodable())
|
.and_then(|str| str.generate_decodable())
|
||||||
}
|
}
|
||||||
syn::Data::Enum(enum_definition) => {
|
syn::Data::Enum(enum_definition) => {
|
||||||
DeriveEnum::parse(input.ident, input.generics, enum_definition)
|
DeriveEnum::parse(input.ident, input.generics, enum_definition)
|
||||||
.and_then(|str| str.to_decodable())
|
.and_then(|str| str.generate_decodable())
|
||||||
}
|
}
|
||||||
syn::Data::Union(_) => Err(Error::UnionNotSupported),
|
syn::Data::Union(_) => Err(Error::UnionNotSupported),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue