Bump syn/quote in deny_public_fields

This commit is contained in:
Bastien Orivel 2018-02-12 14:29:47 +01:00
parent 0653f3097c
commit 0a0d37bea3
4 changed files with 64 additions and 15 deletions

View file

@ -4,24 +4,22 @@
extern crate proc_macro;
extern crate syn;
#[macro_use]
extern crate synstructure;
#[proc_macro_derive(DenyPublicFields)]
pub fn expand_token_stream(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
expand_string(&input.to_string()).parse().unwrap()
}
use std::str::FromStr;
fn expand_string(input: &str) -> String {
let type_ = syn::parse_macro_input(input).unwrap();
decl_derive!([DenyPublicFields] => deny_public_fields_derive);
let style = synstructure::BindStyle::Ref.into();
synstructure::each_field(&type_, &style, |binding| {
if binding.field.vis != syn::Visibility::Inherited {
fn deny_public_fields_derive(s: synstructure::Structure) -> proc_macro::TokenStream {
s.each(|binding| {
if binding.ast().vis != syn::Visibility::Inherited {
panic!("Field `{}` should not be public",
binding.field.ident.as_ref().unwrap_or(&binding.ident));
binding.ast().ident.as_ref().unwrap_or(&binding.binding));
}
"".to_owned()
});
"".to_owned()
proc_macro::TokenStream::from_str("").unwrap()
}