Skip to content

Commit

Permalink
Format example code with rustfmt 0.99.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Aug 31, 2018
1 parent 06af124 commit f6258c5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
6 changes: 4 additions & 2 deletions examples/heapsize/example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ fn main() {
};

// 10 + 0 + 0 + 6 = 16
println!("heap size = {} + {} + {} + {} = {}",
println!(
"heap size = {} + {} + {} + {} = {}",
demo.a.heap_size_of_children(),
demo.b.heap_size_of_children(),
demo.c.heap_size_of_children(),
demo.d.heap_size_of_children(),
demo.heap_size_of_children());
demo.heap_size_of_children()
);
}
2 changes: 1 addition & 1 deletion examples/heapsize/heapsize_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern crate syn;
extern crate quote;

use proc_macro2::TokenStream;
use syn::{DeriveInput, Data, Fields, Generics, GenericParam};
use syn::{Data, DeriveInput, Fields, GenericParam, Generics};

#[proc_macro_derive(HeapSize)]
pub fn derive_heap_size(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
Expand Down
5 changes: 4 additions & 1 deletion examples/heapsize2/example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ fn main() {
e: "String".to_owned(),
},
};
println!("heap size = {}", heapsize::HeapSize::heap_size_of_children(&demo));
println!(
"heap size = {}",
heapsize::HeapSize::heap_size_of_children(&demo)
);
}
7 changes: 5 additions & 2 deletions examples/heapsize2/heapsize_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ extern crate syn;
extern crate quote;

use proc_macro2::{Span, TokenStream};
use syn::{DeriveInput, Data, Fields, Generics, GenericParam, Index};
use syn::spanned::Spanned;
use syn::{Data, DeriveInput, Fields, GenericParam, Generics, Index};

#[proc_macro_derive(HeapSize)]
pub fn derive_heap_size(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
Expand Down Expand Up @@ -84,7 +84,10 @@ fn heap_size_sum(data: &Data, var: &TokenStream) -> TokenStream {
//
// 0 + HeapSize::heap_size(&self.0) + HeapSize::heap_size(&self.1)
let recurse = fields.unnamed.iter().enumerate().map(|(i, f)| {
let index = Index { index: i as u32, span: call_site };
let index = Index {
index: i as u32,
span: call_site,
};
let access = quote_spanned!(call_site=> #var.#index);
quote_spanned! {f.span()=>
::heapsize::HeapSize::heap_size_of_children(&#access)
Expand Down
24 changes: 18 additions & 6 deletions examples/lazy-static/lazy-static/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ extern crate syn;
extern crate quote;
extern crate proc_macro;

use syn::{Visibility, Ident, Type, Expr};
use proc_macro::TokenStream;
use syn::parse::{Parse, ParseStream, Result};
use syn::spanned::Spanned;
use proc_macro::TokenStream;
use syn::{Expr, Ident, Type, Visibility};

/// Parses the following syntax, which aligns with the input of the real
/// `lazy_static` crate.
Expand Down Expand Up @@ -42,13 +42,23 @@ impl Parse for LazyStatic {
input.parse::<Token![=]>()?;
let init: Expr = input.parse()?;
input.parse::<Token![;]>()?;
Ok(LazyStatic { visibility, name, ty, init })
Ok(LazyStatic {
visibility,
name,
ty,
init,
})
}
}

#[proc_macro]
pub fn lazy_static(input: TokenStream) -> TokenStream {
let LazyStatic { visibility, name, ty, init } = syn::parse(input).unwrap();
let LazyStatic {
visibility,
name,
ty,
init,
} = syn::parse(input).unwrap();

// The warning looks like this.
//
Expand All @@ -58,7 +68,8 @@ pub fn lazy_static(input: TokenStream) -> TokenStream {
// 10 | static ref FOO: String = "lazy_static".to_owned();
// | ^^^
if name == "FOO" {
name.span().unstable()
name.span()
.unstable()
.warning("come on, pick a more creative name")
.emit();
}
Expand All @@ -72,7 +83,8 @@ pub fn lazy_static(input: TokenStream) -> TokenStream {
// | ^^
if let Expr::Tuple(ref init) = init {
if init.elems.is_empty() {
init.span().unstable()
init.span()
.unstable()
.error("I can't think of a legitimate use for lazily initializing the value `()`")
.emit();
return TokenStream::new();
Expand Down

0 comments on commit f6258c5

Please sign in to comment.