From 916d7dcd9e244b186f2486e33b99c536fa97271e Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Tue, 15 Nov 2016 21:46:57 +0100 Subject: [PATCH] Update to Rust 1.15.0-nightly (ac635aa95 2016-11-18) --- derive/Cargo.toml | 6 +++--- derive/lib.rs | 14 +++++--------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/derive/Cargo.toml b/derive/Cargo.toml index 2b73b47..d22278b 100644 --- a/derive/Cargo.toml +++ b/derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "heapsize_derive" -version = "0.1.2" +version = "0.1.3" authors = ["The Servo Project Developers"] description = "Automatically generating infrastructure for measuring the total runtime size of an object on the heap" license = "MPL-2.0" @@ -15,6 +15,6 @@ name = "test" path = "test.rs" [dependencies] -syn = "0.9" +syn = "0.10" quote = "0.3" -synstructure = "0.2" +synstructure = "0.4" diff --git a/derive/lib.rs b/derive/lib.rs index a5409a2..6b66127 100644 --- a/derive/lib.rs +++ b/derive/lib.rs @@ -10,7 +10,7 @@ extern crate syn; extern crate synstructure; #[cfg(not(test))] -#[proc_macro_derive(HeapSizeOf)] +#[proc_macro_derive(HeapSizeOf, attributes(ignore_heap_size_of))] pub fn expand_token_stream(input: proc_macro::TokenStream) -> proc_macro::TokenStream { expand_string(&input.to_string()).parse().unwrap() } @@ -20,18 +20,16 @@ fn expand_string(input: &str) -> String { let style = synstructure::BindStyle::Ref.into(); let match_body = synstructure::each_field(&mut type_, &style, |binding| { - let mut ignore = false; - binding.field.attrs.retain(|attr| match attr.value { + let ignore = binding.field.attrs.iter().any(|attr| match attr.value { syn::MetaItem::Word(ref ident) | syn::MetaItem::List(ref ident, _) if ident == "ignore_heap_size_of" => { panic!("#[ignore_heap_size_of] should have an explanation, \ e.g. #[ignore_heap_size_of = \"because reasons\"]"); } syn::MetaItem::NameValue(ref ident, _) if ident == "ignore_heap_size_of" => { - ignore = true; - false // Don’t retain + true } - _ => true // Do retain everything else + _ => false, }); if ignore { None @@ -66,8 +64,6 @@ fn expand_string(input: &str) -> String { } let tokens = quote! { - #type_ - impl #impl_generics ::heapsize::HeapSizeOf for #name #ty_generics #where_clause { #[inline] #[allow(unused_variables, unused_mut, unreachable_code)] @@ -96,7 +92,7 @@ fn test_struct() { $e, expanded) } } - match_count!("struct Foo { bar: Bar, baz: T, z: Arc }", 1); + match_count!("struct", 0); match_count!("ignore_heap_size_of", 0); match_count!("impl ::heapsize::HeapSizeOf for Foo where T: ::heapsize::HeapSizeOf {", 1); match_count!("sum += ::heapsize::HeapSizeOf::heap_size_of_children(", 2);