Format with rustfmt
diff --git a/src/attr.rs b/src/attr.rs
index 58405b6..6d5ed4a 100644
--- a/src/attr.rs
+++ b/src/attr.rs
@@ -319,7 +319,7 @@
use cursor::Cursor;
use parse_error;
use synom::PResult;
- use proc_macro2::{Spacing, Span, TokenNode, TokenTree, Literal};
+ use proc_macro2::{Literal, Spacing, Span, TokenNode, TokenTree};
fn eq(span: Span) -> TokenTree {
TokenTree {
@@ -421,12 +421,8 @@
Some((span, lit, rest)) => {
let string = lit.to_string();
let ok = match style {
- Comment::Inner => {
- string.starts_with("//!") || string.starts_with("/*!")
- }
- Comment::Outer => {
- string.starts_with("///") || string.starts_with("/**")
- }
+ Comment::Inner => string.starts_with("//!") || string.starts_with("/*!"),
+ Comment::Outer => string.starts_with("///") || string.starts_with("/**"),
};
if ok {
Ok((
diff --git a/src/derive.rs b/src/derive.rs
index df65393..680d510 100644
--- a/src/derive.rs
+++ b/src/derive.rs
@@ -152,23 +152,21 @@
self.ident.to_tokens(tokens);
self.generics.to_tokens(tokens);
match self.data {
- Data::Struct(ref data) => {
- match data.fields {
- Fields::Named(ref fields) => {
- self.generics.where_clause.to_tokens(tokens);
- fields.to_tokens(tokens);
- }
- Fields::Unnamed(ref fields) => {
- fields.to_tokens(tokens);
- self.generics.where_clause.to_tokens(tokens);
- TokensOrDefault(&data.semi_token).to_tokens(tokens);
- }
- Fields::Unit => {
- self.generics.where_clause.to_tokens(tokens);
- TokensOrDefault(&data.semi_token).to_tokens(tokens);
- }
+ Data::Struct(ref data) => match data.fields {
+ Fields::Named(ref fields) => {
+ self.generics.where_clause.to_tokens(tokens);
+ fields.to_tokens(tokens);
}
- }
+ Fields::Unnamed(ref fields) => {
+ fields.to_tokens(tokens);
+ self.generics.where_clause.to_tokens(tokens);
+ TokensOrDefault(&data.semi_token).to_tokens(tokens);
+ }
+ Fields::Unit => {
+ self.generics.where_clause.to_tokens(tokens);
+ TokensOrDefault(&data.semi_token).to_tokens(tokens);
+ }
+ },
Data::Enum(ref data) => {
self.generics.where_clause.to_tokens(tokens);
data.brace_token.surround(tokens, |tokens| {
diff --git a/src/expr.rs b/src/expr.rs
index ebaca63..0cc2d30 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -403,47 +403,45 @@
#[cfg(feature = "full")]
pub fn replace_attrs(&mut self, new: Vec<Attribute>) -> Vec<Attribute> {
match *self {
- Expr::Box(ExprBox { ref mut attrs, .. }) |
- Expr::InPlace(ExprInPlace { ref mut attrs, .. }) |
- Expr::Array(ExprArray { ref mut attrs, .. }) |
- Expr::Call(ExprCall { ref mut attrs, .. }) |
- Expr::MethodCall(ExprMethodCall { ref mut attrs, .. }) |
- Expr::Tuple(ExprTuple { ref mut attrs, .. }) |
- Expr::Binary(ExprBinary { ref mut attrs, .. }) |
- Expr::Unary(ExprUnary { ref mut attrs, .. }) |
- Expr::Lit(ExprLit { ref mut attrs, .. }) |
- Expr::Cast(ExprCast { ref mut attrs, .. }) |
- Expr::Type(ExprType { ref mut attrs, .. }) |
- Expr::If(ExprIf { ref mut attrs, .. }) |
- Expr::IfLet(ExprIfLet { ref mut attrs, .. }) |
- Expr::While(ExprWhile { ref mut attrs, .. }) |
- Expr::WhileLet(ExprWhileLet { ref mut attrs, .. }) |
- Expr::ForLoop(ExprForLoop { ref mut attrs, .. }) |
- Expr::Loop(ExprLoop { ref mut attrs, .. }) |
- Expr::Match(ExprMatch { ref mut attrs, .. }) |
- Expr::Closure(ExprClosure { ref mut attrs, .. }) |
- Expr::Unsafe(ExprUnsafe { ref mut attrs, .. }) |
- Expr::Block(ExprBlock { ref mut attrs, .. }) |
- Expr::Assign(ExprAssign { ref mut attrs, .. }) |
- Expr::AssignOp(ExprAssignOp { ref mut attrs, .. }) |
- Expr::Field(ExprField { ref mut attrs, .. }) |
- Expr::Index(ExprIndex { ref mut attrs, .. }) |
- Expr::Range(ExprRange { ref mut attrs, .. }) |
- Expr::Path(ExprPath { ref mut attrs, .. }) |
- Expr::AddrOf(ExprAddrOf { ref mut attrs, .. }) |
- Expr::Break(ExprBreak { ref mut attrs, .. }) |
- Expr::Continue(ExprContinue { ref mut attrs, .. }) |
- Expr::Return(ExprReturn { ref mut attrs, .. }) |
- Expr::Macro(ExprMacro { ref mut attrs, .. }) |
- Expr::Struct(ExprStruct { ref mut attrs, .. }) |
- Expr::Repeat(ExprRepeat { ref mut attrs, .. }) |
- Expr::Paren(ExprParen { ref mut attrs, .. }) |
- Expr::Group(ExprGroup { ref mut attrs, .. }) |
- Expr::Try(ExprTry { ref mut attrs, .. }) |
- Expr::Catch(ExprCatch { ref mut attrs, .. }) |
- Expr::Yield(ExprYield { ref mut attrs, .. }) => {
- mem::replace(attrs, new)
- }
+ Expr::Box(ExprBox { ref mut attrs, .. })
+ | Expr::InPlace(ExprInPlace { ref mut attrs, .. })
+ | Expr::Array(ExprArray { ref mut attrs, .. })
+ | Expr::Call(ExprCall { ref mut attrs, .. })
+ | Expr::MethodCall(ExprMethodCall { ref mut attrs, .. })
+ | Expr::Tuple(ExprTuple { ref mut attrs, .. })
+ | Expr::Binary(ExprBinary { ref mut attrs, .. })
+ | Expr::Unary(ExprUnary { ref mut attrs, .. })
+ | Expr::Lit(ExprLit { ref mut attrs, .. })
+ | Expr::Cast(ExprCast { ref mut attrs, .. })
+ | Expr::Type(ExprType { ref mut attrs, .. })
+ | Expr::If(ExprIf { ref mut attrs, .. })
+ | Expr::IfLet(ExprIfLet { ref mut attrs, .. })
+ | Expr::While(ExprWhile { ref mut attrs, .. })
+ | Expr::WhileLet(ExprWhileLet { ref mut attrs, .. })
+ | Expr::ForLoop(ExprForLoop { ref mut attrs, .. })
+ | Expr::Loop(ExprLoop { ref mut attrs, .. })
+ | Expr::Match(ExprMatch { ref mut attrs, .. })
+ | Expr::Closure(ExprClosure { ref mut attrs, .. })
+ | Expr::Unsafe(ExprUnsafe { ref mut attrs, .. })
+ | Expr::Block(ExprBlock { ref mut attrs, .. })
+ | Expr::Assign(ExprAssign { ref mut attrs, .. })
+ | Expr::AssignOp(ExprAssignOp { ref mut attrs, .. })
+ | Expr::Field(ExprField { ref mut attrs, .. })
+ | Expr::Index(ExprIndex { ref mut attrs, .. })
+ | Expr::Range(ExprRange { ref mut attrs, .. })
+ | Expr::Path(ExprPath { ref mut attrs, .. })
+ | Expr::AddrOf(ExprAddrOf { ref mut attrs, .. })
+ | Expr::Break(ExprBreak { ref mut attrs, .. })
+ | Expr::Continue(ExprContinue { ref mut attrs, .. })
+ | Expr::Return(ExprReturn { ref mut attrs, .. })
+ | Expr::Macro(ExprMacro { ref mut attrs, .. })
+ | Expr::Struct(ExprStruct { ref mut attrs, .. })
+ | Expr::Repeat(ExprRepeat { ref mut attrs, .. })
+ | Expr::Paren(ExprParen { ref mut attrs, .. })
+ | Expr::Group(ExprGroup { ref mut attrs, .. })
+ | Expr::Try(ExprTry { ref mut attrs, .. })
+ | Expr::Catch(ExprCatch { ref mut attrs, .. })
+ | Expr::Yield(ExprYield { ref mut attrs, .. }) => mem::replace(attrs, new),
Expr::Verbatim(_) => {
// TODO
Vec::new()
@@ -2568,7 +2566,7 @@
use attr::FilterAttrs;
use quote::{ToTokens, Tokens};
#[cfg(feature = "full")]
- use proc_macro2::{TokenTree, TokenNode, Literal};
+ use proc_macro2::{Literal, TokenNode, TokenTree};
// If the given expression is a bare `ExprStruct`, wraps it in parenthesis
// before appending it to `Tokens`.
@@ -2589,8 +2587,7 @@
}
#[cfg(not(feature = "full"))]
- fn attrs_to_tokens(_attrs: &[Attribute], _tokens: &mut Tokens) {
- }
+ fn attrs_to_tokens(_attrs: &[Attribute], _tokens: &mut Tokens) {}
#[cfg(feature = "full")]
impl ToTokens for ExprBox {
@@ -2724,10 +2721,7 @@
}
#[cfg(feature = "full")]
- fn maybe_wrap_else(
- tokens: &mut Tokens,
- else_: &Option<(Token![else], Box<Expr>)>,
- ) {
+ fn maybe_wrap_else(tokens: &mut Tokens, else_: &Option<(Token![else], Box<Expr>)>) {
if let Some((ref else_token, ref else_)) = *else_ {
else_token.to_tokens(tokens);
diff --git a/src/gen_helper.rs b/src/gen_helper.rs
index 5754ac3..f91ebcd 100644
--- a/src/gen_helper.rs
+++ b/src/gen_helper.rs
@@ -1,24 +1,32 @@
#[cfg(feature = "fold")]
pub mod fold {
- use punctuated::{Punctuated, Element};
+ use punctuated::{Element, Punctuated};
use fold::Folder;
use proc_macro2::Span;
pub trait FoldHelper {
type Item;
- fn lift<F>(self, f: F) -> Self where F: FnMut(Self::Item) -> Self::Item;
+ fn lift<F>(self, f: F) -> Self
+ where
+ F: FnMut(Self::Item) -> Self::Item;
}
impl<T> FoldHelper for Vec<T> {
type Item = T;
- fn lift<F>(self, f: F) -> Self where F: FnMut(Self::Item) -> Self::Item {
+ fn lift<F>(self, f: F) -> Self
+ where
+ F: FnMut(Self::Item) -> Self::Item,
+ {
self.into_iter().map(f).collect()
}
}
impl<T, U> FoldHelper for Punctuated<T, U> {
type Item = T;
- fn lift<F>(self, mut f: F) -> Self where F: FnMut(Self::Item) -> Self::Item {
+ fn lift<F>(self, mut f: F) -> Self
+ where
+ F: FnMut(Self::Item) -> Self::Item,
+ {
self.into_elements()
.map(Element::into_tuple)
.map(|(t, u)| Element::new(f(t), u))
@@ -54,7 +62,11 @@
impl Spans for [Span; 3] {
fn fold<F: Folder + ?Sized>(&self, folder: &mut F) -> Self {
- [folder.fold_span(self[0]), folder.fold_span(self[1]), folder.fold_span(self[2])]
+ [
+ folder.fold_span(self[0]),
+ folder.fold_span(self[1]),
+ folder.fold_span(self[2]),
+ ]
}
}
}
@@ -64,7 +76,10 @@
use proc_macro2::Span;
use visit::Visitor;
- pub fn tokens_helper<'ast, V: Visitor<'ast> + ?Sized, S: Spans>(visitor: &mut V, spans: &'ast S) {
+ pub fn tokens_helper<'ast, V: Visitor<'ast> + ?Sized, S: Spans>(
+ visitor: &mut V,
+ spans: &'ast S,
+ ) {
spans.visit(visitor);
}
diff --git a/src/generics.rs b/src/generics.rs
index 0f0e31d..7206e31 100644
--- a/src/generics.rs
+++ b/src/generics.rs
@@ -84,7 +84,11 @@
/// # }
/// ```
pub fn split_for_impl(&self) -> (ImplGenerics, TypeGenerics, Option<&WhereClause>) {
- (ImplGenerics(self), TypeGenerics(self), self.where_clause.as_ref())
+ (
+ ImplGenerics(self),
+ TypeGenerics(self),
+ self.where_clause.as_ref(),
+ )
}
}
diff --git a/src/item.rs b/src/item.rs
index 0dfc951..ee1c93d 100644
--- a/src/item.rs
+++ b/src/item.rs
@@ -1,8 +1,8 @@
use super::*;
use derive::{Data, DeriveInput};
use punctuated::Punctuated;
-use proc_macro2::{TokenStream};
-use token::{Paren, Brace};
+use proc_macro2::TokenStream;
+use token::{Brace, Paren};
#[cfg(feature = "extra-traits")]
use tt::TokenStreamHelper;
@@ -544,7 +544,7 @@
pub mod parsing {
use super::*;
- use synom::{Synom, Cursor, PResult};
+ use synom::{Cursor, PResult, Synom};
impl_synom!(Item "item" alt!(
syn!(ItemExternCrate) => { Item::ExternCrate }
@@ -1094,7 +1094,7 @@
braces!(epsilon!()) >>
end: call!(grab_cursor) >>
({
- let mut tts = begin.token_stream().into_iter().collect::<Vec<_>>();
+ let tts = begin.token_stream().into_iter().collect::<Vec<_>>();
let len = tts.len() - end.token_stream().into_iter().count();
ItemVerbatim {
tts: tts.into_iter().take(len).collect(),
diff --git a/src/lib.rs b/src/lib.rs
index f73939e..f3752f4 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -29,7 +29,8 @@
#[cfg(any(feature = "full", feature = "derive"))]
mod data;
#[cfg(any(feature = "full", feature = "derive"))]
-pub use data::{Field, Fields, FieldsNamed, FieldsUnnamed, Variant, VisCrate, VisPublic, VisRestricted, Visibility};
+pub use data::{Field, Fields, FieldsNamed, FieldsUnnamed, Variant, VisCrate, VisPublic,
+ VisRestricted, Visibility};
#[cfg(any(feature = "full", feature = "derive"))]
mod expr;
@@ -37,21 +38,23 @@
pub use expr::{Expr, ExprAddrOf, ExprArray, ExprAssign, ExprAssignOp, ExprBinary, ExprBlock,
ExprBox, ExprBreak, ExprCall, ExprCast, ExprCatch, ExprClosure, ExprContinue,
ExprField, ExprForLoop, ExprGroup, ExprIf, ExprIfLet, ExprInPlace, ExprIndex,
- ExprLit, ExprLoop, ExprMacro, ExprMatch, ExprMethodCall, ExprParen, ExprPath, ExprRange,
- ExprRepeat, ExprReturn, ExprStruct, ExprTry, ExprTuple, ExprType,
- ExprUnary, ExprUnsafe, ExprVerbatim, ExprWhile, ExprWhileLet, ExprYield, Index, Member};
+ ExprLit, ExprLoop, ExprMacro, ExprMatch, ExprMethodCall, ExprParen, ExprPath,
+ ExprRange, ExprRepeat, ExprReturn, ExprStruct, ExprTry, ExprTuple, ExprType,
+ ExprUnary, ExprUnsafe, ExprVerbatim, ExprWhile, ExprWhileLet, ExprYield, Index,
+ Member};
#[cfg(feature = "full")]
pub use expr::{Arm, Block, FieldPat, FieldValue, GenericMethodArgument, Label, Local,
- MethodTurbofish, Pat, PatBox, PatIdent, PatLit, PatMacro, PatPath, PatRange, PatRef, PatSlice,
- PatStruct, PatTuple, PatTupleStruct, PatVerbatim, PatWild, RangeLimits, Stmt};
+ MethodTurbofish, Pat, PatBox, PatIdent, PatLit, PatMacro, PatPath, PatRange,
+ PatRef, PatSlice, PatStruct, PatTuple, PatTupleStruct, PatVerbatim, PatWild,
+ RangeLimits, Stmt};
#[cfg(any(feature = "full", feature = "derive"))]
mod generics;
#[cfg(any(feature = "full", feature = "derive"))]
-pub use generics::{BoundLifetimes, ConstParam, GenericParam, Generics, LifetimeDef,
- PredicateEq, PredicateLifetime, PredicateType, TraitBound, TraitBoundModifier,
- TypeParam, TypeParamBound, WhereClause, WherePredicate};
+pub use generics::{BoundLifetimes, ConstParam, GenericParam, Generics, LifetimeDef, PredicateEq,
+ PredicateLifetime, PredicateType, TraitBound, TraitBoundModifier, TypeParam,
+ TypeParamBound, WhereClause, WherePredicate};
#[cfg(all(any(feature = "full", feature = "derive"), feature = "printing"))]
pub use generics::{ImplGenerics, Turbofish, TypeGenerics};
@@ -61,13 +64,14 @@
#[cfg(feature = "full")]
mod item;
#[cfg(feature = "full")]
-pub use item::{ArgCaptured, ArgSelf, ArgSelfRef, FnArg, FnDecl,
- ForeignItem, ForeignItemFn, ForeignItemStatic, ForeignItemType, ForeignItemVerbatim, ImplItem,
- ImplItemConst, ImplItemMacro, ImplItemMethod, ImplItemType, ImplItemVerbatim, Item,
- ItemConst, ItemEnum, ItemExternCrate, ItemFn, ItemForeignMod,
- ItemImpl, ItemMacro, ItemMacro2, ItemMod, ItemStatic, ItemStruct, ItemTrait,
- ItemType, ItemUnion, ItemUse, ItemVerbatim, MethodSig, TraitItem, TraitItemConst, TraitItemMacro,
- TraitItemMethod, TraitItemType, TraitItemVerbatim, UseGlob, UseList, UsePath, UseTree};
+pub use item::{ArgCaptured, ArgSelf, ArgSelfRef, FnArg, FnDecl, ForeignItem, ForeignItemFn,
+ ForeignItemStatic, ForeignItemType, ForeignItemVerbatim, ImplItem, ImplItemConst,
+ ImplItemMacro, ImplItemMethod, ImplItemType, ImplItemVerbatim, Item, ItemConst,
+ ItemEnum, ItemExternCrate, ItemFn, ItemForeignMod, ItemImpl, ItemMacro, ItemMacro2,
+ ItemMod, ItemStatic, ItemStruct, ItemTrait, ItemType, ItemUnion, ItemUse,
+ ItemVerbatim, MethodSig, TraitItem, TraitItemConst, TraitItemMacro,
+ TraitItemMethod, TraitItemType, TraitItemVerbatim, UseGlob, UseList, UsePath,
+ UseTree};
#[cfg(feature = "full")]
mod file;
@@ -82,8 +86,8 @@
#[cfg(any(feature = "full", feature = "derive"))]
mod lit;
#[cfg(any(feature = "full", feature = "derive"))]
-pub use lit::{Lit, LitStr, LitByteStr, LitByte, LitChar, LitInt, LitFloat, LitBool, LitVerbatim,
- StrStyle, IntSuffix, FloatSuffix};
+pub use lit::{FloatSuffix, IntSuffix, Lit, LitBool, LitByte, LitByteStr, LitChar, LitFloat,
+ LitInt, LitStr, LitVerbatim, StrStyle};
#[cfg(any(feature = "full", feature = "derive"))]
mod mac;
@@ -103,15 +107,15 @@
#[cfg(any(feature = "full", feature = "derive"))]
mod ty;
#[cfg(any(feature = "full", feature = "derive"))]
-pub use ty::{Abi, BareFnArg, BareFnArgName, ReturnType, Type, TypeArray,
- TypeBareFn, TypeGroup, TypeImplTrait, TypeInfer, TypeMacro, TypeNever, TypeParen,
- TypePath, TypePtr, TypeReference, TypeSlice, TypeTraitObject, TypeTuple, TypeVerbatim};
+pub use ty::{Abi, BareFnArg, BareFnArgName, ReturnType, Type, TypeArray, TypeBareFn, TypeGroup,
+ TypeImplTrait, TypeInfer, TypeMacro, TypeNever, TypeParen, TypePath, TypePtr,
+ TypeReference, TypeSlice, TypeTraitObject, TypeTuple, TypeVerbatim};
#[cfg(any(feature = "full", feature = "derive"))]
mod path;
#[cfg(any(feature = "full", feature = "derive"))]
-pub use path::{Path, PathSegment, PathArguments, GenericArgument, AngleBracketedGenericArguments,
- Binding, ParenthesizedGenericArguments, QSelf};
+pub use path::{AngleBracketedGenericArguments, Binding, GenericArgument,
+ ParenthesizedGenericArguments, Path, PathArguments, PathSegment, QSelf};
#[cfg(all(any(feature = "full", feature = "derive"), feature = "printing"))]
pub use path::PathTokens;
diff --git a/src/lit.rs b/src/lit.rs
index cf1e062..440d8d2 100644
--- a/src/lit.rs
+++ b/src/lit.rs
@@ -180,10 +180,7 @@
pub fn suffix(&self) -> FloatSuffix {
let value = self.token.to_string();
- for (s, suffix) in vec![
- ("f32", FloatSuffix::F32),
- ("f64", FloatSuffix::F64),
- ] {
+ for (s, suffix) in vec![("f32", FloatSuffix::F32), ("f64", FloatSuffix::F64)] {
if value.ends_with(s) {
return suffix;
}
@@ -352,25 +349,33 @@
let value = token.to_string();
match value::byte(&value, 0) {
- b'"' | b'r' => return Lit::Str(LitStr {
- token: token,
- span: span,
- }),
- b'b' => match value::byte(&value, 1) {
- b'"' | b'r' => return Lit::ByteStr(LitByteStr {
+ b'"' | b'r' => {
+ return Lit::Str(LitStr {
token: token,
span: span,
- }),
- b'\'' => return Lit::Byte(LitByte {
- token: token,
- span: span,
- }),
- _ => {}
+ })
}
- b'\'' => return Lit::Char(LitChar {
- token: token,
- span: span,
- }),
+ b'b' => match value::byte(&value, 1) {
+ b'"' | b'r' => {
+ return Lit::ByteStr(LitByteStr {
+ token: token,
+ span: span,
+ })
+ }
+ b'\'' => {
+ return Lit::Byte(LitByte {
+ token: token,
+ span: span,
+ })
+ }
+ _ => {}
+ },
+ b'\'' => {
+ return Lit::Char(LitChar {
+ token: token,
+ span: span,
+ })
+ }
b'0'...b'9' => if number_is_int(&value) {
return Lit::Int(LitInt {
token: token,
@@ -387,13 +392,13 @@
token: token,
span: span,
});
- }
+ },
_ => if value == "true" || value == "false" {
return Lit::Bool(LitBool {
value: value == "true",
span: span,
});
- }
+ },
}
panic!("Unrecognized literal: {}", value);
@@ -482,11 +487,7 @@
fn to_tokens(&self, tokens: &mut Tokens) {
tokens.append(TokenTree {
span: self.span,
- kind: TokenNode::Term(Term::intern(if self.value {
- "true"
- } else {
- "false"
- })),
+ kind: TokenNode::Term(Term::intern(if self.value { "true" } else { "false" })),
});
}
}
@@ -560,19 +561,15 @@
b'0' => '\0',
b'\'' => '\'',
b'"' => '"',
- b'\r' | b'\n' => {
- loop {
- let ch = next_chr(s);
- if ch.is_whitespace() {
- s = &s[ch.len_utf8()..];
- } else {
- continue 'outer;
- }
+ b'\r' | b'\n' => loop {
+ let ch = next_chr(s);
+ if ch.is_whitespace() {
+ s = &s[ch.len_utf8()..];
+ } else {
+ continue 'outer;
}
- }
- b => {
- panic!("unexpected byte {:?} after \\ character in byte literal", b)
- }
+ },
+ b => panic!("unexpected byte {:?} after \\ character in byte literal", b),
}
}
b'\r' => {
@@ -647,20 +644,16 @@
b'0' => b'\0',
b'\'' => b'\'',
b'"' => b'"',
- b'\r' | b'\n' => {
- loop {
- let byte = byte(s, 0);
- let ch = char::from_u32(byte as u32).unwrap();
- if ch.is_whitespace() {
- s = &s[1..];
- } else {
- continue 'outer;
- }
+ b'\r' | b'\n' => loop {
+ let byte = byte(s, 0);
+ let ch = char::from_u32(byte as u32).unwrap();
+ if ch.is_whitespace() {
+ s = &s[1..];
+ } else {
+ continue 'outer;
}
- }
- b => {
- panic!("unexpected byte {:?} after \\ character in byte literal", b)
- }
+ },
+ b => panic!("unexpected byte {:?} after \\ character in byte literal", b),
}
}
b'\r' => {
@@ -709,9 +702,7 @@
b'0' => b'\0',
b'\'' => b'\'',
b'"' => b'"',
- b => {
- panic!("unexpected byte {:?} after \\ character in byte literal", b)
- }
+ b => panic!("unexpected byte {:?} after \\ character in byte literal", b),
}
}
b => {
@@ -751,9 +742,7 @@
b'0' => '\0',
b'\'' => '\'',
b'"' => '"',
- b => {
- panic!("unexpected byte {:?} after \\ character in byte literal", b)
- }
+ b => panic!("unexpected byte {:?} after \\ character in byte literal", b),
}
}
_ => {
@@ -767,7 +756,8 @@
}
fn backslash_x<S>(s: &S) -> (u8, &S)
- where S: Index<RangeFrom<usize>, Output=S> + AsRef<[u8]> + ?Sized
+ where
+ S: Index<RangeFrom<usize>, Output = S> + AsRef<[u8]> + ?Sized,
{
let mut ch = 0;
let b0 = byte(s, 0);
diff --git a/src/mac.rs b/src/mac.rs
index 028f6d2..b8a1b80 100644
--- a/src/mac.rs
+++ b/src/mac.rs
@@ -1,6 +1,6 @@
use super::*;
use proc_macro2::TokenStream;
-use token::{Paren, Brace, Bracket};
+use token::{Brace, Bracket, Paren};
#[cfg(feature = "extra-traits")]
use std::hash::{Hash, Hasher};
diff --git a/src/parsers.rs b/src/parsers.rs
index 38c7ab0..14584d5 100644
--- a/src/parsers.rs
+++ b/src/parsers.rs
@@ -1123,7 +1123,7 @@
/// implementation is provided by Syn or is one that you write.
///
/// [`Synom`]: synom/trait.Synom.html
-///
+///
/// - **Syntax:** `syn!(TYPE)`
/// - **Output:** `TYPE`
///
diff --git a/src/punctuated.rs b/src/punctuated.rs
index dc8c4ea..ccf7597 100644
--- a/src/punctuated.rs
+++ b/src/punctuated.rs
@@ -93,7 +93,10 @@
}
pub fn trailing_punct(&self) -> bool {
- self.inner.last().map(|last| last.1.is_some()).unwrap_or(false)
+ self.inner
+ .last()
+ .map(|last| last.1.is_some())
+ .unwrap_or(false)
}
/// Returns true if either this `Punctuated` is empty, or it has a trailing
@@ -101,7 +104,10 @@
///
/// Equivalent to `punctuated.is_empty() || punctuated.trailing_punct()`.
pub fn empty_or_trailing(&self) -> bool {
- self.inner.last().map(|last| last.1.is_some()).unwrap_or(true)
+ self.inner
+ .last()
+ .map(|last| last.1.is_some())
+ .unwrap_or(true)
}
}
diff --git a/src/spanned.rs b/src/spanned.rs
index a2fe6d3..507703a 100644
--- a/src/spanned.rs
+++ b/src/spanned.rs
@@ -1,5 +1,5 @@
use proc_macro2::{Span, TokenStream};
-use quote::{Tokens, ToTokens};
+use quote::{ToTokens, Tokens};
pub trait Spanned {
/// Returns a `Span` covering the complete contents of this AST node, or
diff --git a/src/tt.rs b/src/tt.rs
index cc4e047..5fb5b9d 100644
--- a/src/tt.rs
+++ b/src/tt.rs
@@ -1,9 +1,9 @@
-use proc_macro2::{TokenNode, TokenStream, TokenTree, Delimiter};
+use proc_macro2::{Delimiter, TokenNode, TokenStream, TokenTree};
use cursor::Cursor;
use parse_error;
use synom::PResult;
use MacroDelimiter;
-use token::{Paren, Brace, Bracket};
+use token::{Brace, Bracket, Paren};
#[cfg(feature = "extra-traits")]
use std::hash::{Hash, Hasher};
diff --git a/tests/test_derive_input.rs b/tests/test_derive_input.rs
index ae7bcfc..d7d0b6a 100644
--- a/tests/test_derive_input.rs
+++ b/tests/test_derive_input.rs
@@ -294,7 +294,11 @@
elems: punctuated![
Expr::Lit(ExprLit {
attrs: Vec::new(),
- lit: Lit::Int(LitInt::new(0, IntSuffix::None, Default::default())),
+ lit: Lit::Int(LitInt::new(
+ 0,
+ IntSuffix::None,
+ Default::default()
+ )),
}),
Expr::Lit(ExprLit {
attrs: Vec::new(),
@@ -506,7 +510,10 @@
vis: Visibility::Restricted(VisRestricted {
path: Box::new(Path {
leading_colon: None,
- segments: punctuated![PathSegment::from("m"), PathSegment::from("n")],
+ segments: punctuated![
+ PathSegment::from("m"),
+ PathSegment::from("n")
+ ],
}),
in_token: Some(Default::default()),
paren_token: Default::default(),
diff --git a/tests/test_lit.rs b/tests/test_lit.rs
index bd8a980..53a7ee0 100644
--- a/tests/test_lit.rs
+++ b/tests/test_lit.rs
@@ -1,14 +1,20 @@
-extern crate syn;
-extern crate quote;
extern crate proc_macro2;
+extern crate quote;
+extern crate syn;
-use syn::{Lit, IntSuffix, FloatSuffix};
+use syn::{FloatSuffix, IntSuffix, Lit};
use quote::ToTokens;
-use proc_macro2::{TokenStream, TokenNode, Span};
+use proc_macro2::{Span, TokenNode, TokenStream};
use std::str::FromStr;
fn lit(s: &str) -> Lit {
- match TokenStream::from_str(s).unwrap().into_iter().next().unwrap().kind {
+ match TokenStream::from_str(s)
+ .unwrap()
+ .into_iter()
+ .next()
+ .unwrap()
+ .kind
+ {
TokenNode::Literal(lit) => Lit::new(lit, Span::default()),
_ => panic!(),
}
@@ -38,8 +44,10 @@
test_string("\"'\"", "'");
test_string("\"\"", "");
test_string("\"\\u{1F415}\"", "\u{1F415}");
- test_string("\"contains\nnewlines\\\nescaped newlines\"",
- "contains\nnewlinesescaped newlines");
+ test_string(
+ "\"contains\nnewlines\\\nescaped newlines\"",
+ "contains\nnewlinesescaped newlines",
+ );
test_string("r\"raw\nstring\\\nhere\"", "raw\nstring\\\nhere");
}
@@ -65,8 +73,10 @@
test_byte_string("b\"\\\"\"", b"\"");
test_byte_string("b\"'\"", b"'");
test_byte_string("b\"\"", b"");
- test_byte_string("b\"contains\nnewlines\\\nescaped newlines\"",
- b"contains\nnewlinesescaped newlines");
+ test_byte_string(
+ "b\"contains\nnewlines\\\nescaped newlines\"",
+ b"contains\nnewlinesescaped newlines",
+ );
test_byte_string("br\"raw\nstring\\\nhere\"", b"raw\nstring\\\nhere");
}
diff --git a/tests/test_precedence.rs b/tests/test_precedence.rs
index 2b8d0a4..f5f170f 100644
--- a/tests/test_precedence.rs
+++ b/tests/test_precedence.rs
@@ -299,10 +299,7 @@
let attrs = node.replace_attrs(Vec::new());
Expr::Paren(ExprParen {
attrs: attrs,
- expr: Box::new(fold_expr(
- folder,
- node,
- )),
+ expr: Box::new(fold_expr(folder, node)),
paren_token: token::Paren::default(),
})
}
@@ -313,10 +310,7 @@
match expr {
Expr::Group(_) => unreachable!(),
Expr::Paren(p) => paren(self, *p.expr),
- Expr::If(..)
- | Expr::Unsafe(..)
- | Expr::Block(..)
- | Expr::IfLet(..) => {
+ Expr::If(..) | Expr::Unsafe(..) | Expr::Block(..) | Expr::IfLet(..) => {
fold_expr(self, expr)
}
node => paren(self, node),