Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Update to Rust 1.15.0-nightly (ac635aa95 2016-11-18) #67

Merged
merged 1 commit into from
Nov 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
14 changes: 5 additions & 9 deletions derive/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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
Expand Down Expand Up @@ -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)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a decorator now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Expand Down Expand Up @@ -96,7 +92,7 @@ fn test_struct() {
$e, expanded)
}
}
match_count!("struct Foo<T> { bar: Bar, baz: T, z: Arc<T> }", 1);
match_count!("struct", 0);
match_count!("ignore_heap_size_of", 0);
match_count!("impl<T> ::heapsize::HeapSizeOf for Foo<T> where T: ::heapsize::HeapSizeOf {", 1);
match_count!("sum += ::heapsize::HeapSizeOf::heap_size_of_children(", 2);
Expand Down