Format with rustfmt 0.3.4-nightly
diff --git a/src/attr.rs b/src/attr.rs
index 875f452..90d9af9 100644
--- a/src/attr.rs
+++ b/src/attr.rs
@@ -3,7 +3,7 @@
use std::iter;
-use proc_macro2::{Delimiter, TokenNode, TokenTree, TokenStream, Spacing};
+use proc_macro2::{Delimiter, Spacing, TokenNode, TokenStream, TokenTree};
#[cfg(feature = "extra-traits")]
use std::hash::{Hash, Hasher};
@@ -39,10 +39,8 @@
#[cfg(feature = "extra-traits")]
impl PartialEq for Attribute {
fn eq(&self, other: &Self) -> bool {
- self.style == other.style
- && self.pound_token == other.pound_token
- && self.bracket_token == other.bracket_token
- && self.path == other.path
+ self.style == other.style && self.pound_token == other.pound_token
+ && self.bracket_token == other.bracket_token && self.path == other.path
&& TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
&& self.is_sugared_doc == other.is_sugared_doc
}
@@ -51,7 +49,8 @@
#[cfg(feature = "extra-traits")]
impl Hash for Attribute {
fn hash<H>(&self, state: &mut H)
- where H: Hasher
+ where
+ H: Hasher,
{
self.style.hash(state);
self.pound_token.hash(state);
@@ -109,9 +108,7 @@
}
}
-fn nested_meta_item_from_tokens(tts: &[TokenTree])
- -> Option<(NestedMetaItem, &[TokenTree])>
-{
+fn nested_meta_item_from_tokens(tts: &[TokenTree]) -> Option<(NestedMetaItem, &[TokenTree])> {
assert!(!tts.is_empty());
match tts[0].kind {
@@ -154,7 +151,7 @@
Some((MetaItem::List(list).into(), &tts[2..]))
}
- None => None
+ None => None,
};
}
}
@@ -162,13 +159,13 @@
Some((MetaItem::Term(ident).into(), &tts[1..]))
}
- _ => None
+ _ => None,
}
}
-fn list_of_nested_meta_items_from_tokens(mut tts: &[TokenTree])
- -> Option<Delimited<NestedMetaItem, Token![,]>>
-{
+fn list_of_nested_meta_items_from_tokens(
+ mut tts: &[TokenTree],
+) -> Option<Delimited<NestedMetaItem, Token![,]>> {
let mut delimited = Delimited::new();
let mut first = true;
@@ -180,11 +177,11 @@
let tok = Token;
tts = &tts[1..];
if tts.is_empty() {
- break
+ break;
}
Some(tok)
} else {
- return None
+ return None;
};
let (nested, rest) = match nested_meta_item_from_tokens(tts) {
Some(pair) => pair,
@@ -200,7 +197,6 @@
Some(delimited)
}
-
ast_enum! {
/// Distinguishes between Attributes that decorate items and Attributes that
/// are contained as statements within items. These two cases need to be
@@ -300,7 +296,8 @@
}
impl<'a, T> FilterAttrs<'a> for T
- where T: IntoIterator<Item = &'a Attribute>
+where
+ T: IntoIterator<Item = &'a Attribute>,
{
type Ret = iter::Filter<T::IntoIter, fn(&&Attribute) -> bool>;
@@ -329,8 +326,8 @@
pub mod parsing {
use super::*;
use cursor::Cursor;
- use {PResult, parse_error};
- use proc_macro2::{TokenNode, Spacing, TokenTree};
+ use {parse_error, PResult};
+ use proc_macro2::{Spacing, TokenNode, TokenTree};
fn eq() -> TokenTree {
TokenTree {
@@ -422,15 +419,18 @@
Some((rest, span, lit)) => {
let literal = lit.to_string();
if literal.starts_with("//") || literal.starts_with("/*") {
- Ok((rest, TokenTree {
- span: span,
- kind: TokenNode::Literal(lit)
- }))
+ Ok((
+ rest,
+ TokenTree {
+ span: span,
+ kind: TokenNode::Literal(lit),
+ },
+ ))
} else {
parse_error()
}
}
- _ => parse_error()
+ _ => parse_error(),
}
}
}
@@ -438,7 +438,7 @@
#[cfg(feature = "printing")]
mod printing {
use super::*;
- use quote::{Tokens, ToTokens};
+ use quote::{ToTokens, Tokens};
impl ToTokens for Attribute {
fn to_tokens(&self, tokens: &mut Tokens) {
@@ -449,7 +449,7 @@
let value = pair.lit.value.to_string();
if value.starts_with('/') {
pair.lit.to_tokens(tokens);
- return
+ return;
}
}
}
diff --git a/src/cursor.rs b/src/cursor.rs
index 0ed3bb4..69eb5f1 100644
--- a/src/cursor.rs
+++ b/src/cursor.rs
@@ -86,9 +86,7 @@
entries[idx] = Entry::Group(span, delim, inner);
}
- SynomBuffer {
- data: entries
- }
+ SynomBuffer { data: entries }
}
/// Create a new SynomBuffer, which contains the data from the given
@@ -99,9 +97,7 @@
/// Create a cursor referencing the first token in the input.
pub fn begin(&self) -> Cursor {
- unsafe {
- Cursor::create(&self.data[0], &self.data[self.data.len() - 1])
- }
+ unsafe { Cursor::create(&self.data[0], &self.data[self.data.len() - 1]) }
}
}
@@ -145,8 +141,7 @@
// object in global storage.
struct UnsafeSyncEntry(Entry);
unsafe impl Sync for UnsafeSyncEntry {}
- static EMPTY_ENTRY: UnsafeSyncEntry =
- UnsafeSyncEntry(Entry::End(0 as *const Entry));
+ static EMPTY_ENTRY: UnsafeSyncEntry = UnsafeSyncEntry(Entry::End(0 as *const Entry));
Cursor {
ptr: &EMPTY_ENTRY.0,
@@ -234,7 +229,7 @@
outside: unsafe { self.bump() },
})
}
- _ => None
+ _ => None,
}
}
@@ -243,14 +238,8 @@
pub fn word(mut self) -> Option<(Cursor<'a>, Span, Term)> {
self.ignore_none();
match *self.entry() {
- Entry::Term(span, sym) => {
- Some((
- unsafe { self.bump() },
- span,
- sym,
- ))
- }
- _ => None
+ Entry::Term(span, sym) => Some((unsafe { self.bump() }, span, sym)),
+ _ => None,
}
}
@@ -259,15 +248,8 @@
pub fn op(mut self) -> Option<(Cursor<'a>, Span, char, Spacing)> {
self.ignore_none();
match *self.entry() {
- Entry::Op(span, chr, kind) => {
- Some((
- unsafe { self.bump() },
- span,
- chr,
- kind,
- ))
- }
- _ => None
+ Entry::Op(span, chr, kind) => Some((unsafe { self.bump() }, span, chr, kind)),
+ _ => None,
}
}
@@ -276,14 +258,8 @@
pub fn literal(mut self) -> Option<(Cursor<'a>, Span, Literal)> {
self.ignore_none();
match *self.entry() {
- Entry::Literal(span, ref lit) => {
- Some((
- unsafe { self.bump() },
- span,
- lit.clone(),
- ))
- }
- _ => None
+ Entry::Literal(span, ref lit) => Some((unsafe { self.bump() }, span, lit.clone())),
+ _ => None,
}
}
@@ -313,33 +289,24 @@
kind: TokenNode::Group(delim, stream),
}
}
- Entry::Literal(span, ref lit) => {
- TokenTree {
- span: span,
- kind: TokenNode::Literal(lit.clone()),
- }
- }
- Entry::Term(span, sym) => {
- TokenTree {
- span: span,
- kind: TokenNode::Term(sym),
- }
- }
- Entry::Op(span, chr, kind) => {
- TokenTree {
- span: span,
- kind: TokenNode::Op(chr, kind),
- }
- }
+ Entry::Literal(span, ref lit) => TokenTree {
+ span: span,
+ kind: TokenNode::Literal(lit.clone()),
+ },
+ Entry::Term(span, sym) => TokenTree {
+ span: span,
+ kind: TokenNode::Term(sym),
+ },
+ Entry::Op(span, chr, kind) => TokenTree {
+ span: span,
+ kind: TokenNode::Op(chr, kind),
+ },
Entry::End(..) => {
return None;
}
};
- Some((
- unsafe { self.bump() },
- tree
- ))
+ Some((unsafe { self.bump() }, tree))
}
}
diff --git a/src/data.rs b/src/data.rs
index 0f75b35..d9b436b 100644
--- a/src/data.rs
+++ b/src/data.rs
@@ -203,7 +203,7 @@
#[cfg(feature = "printing")]
mod printing {
use super::*;
- use quote::{Tokens, ToTokens};
+ use quote::{ToTokens, Tokens};
impl ToTokens for Variant {
fn to_tokens(&self, tokens: &mut Tokens) {
@@ -275,7 +275,6 @@
}
impl ToTokens for VisInherited {
- fn to_tokens(&self, _tokens: &mut Tokens) {
- }
+ fn to_tokens(&self, _tokens: &mut Tokens) {}
}
}
diff --git a/src/delimited.rs b/src/delimited.rs
index 044ffc9..3430bf6 100644
--- a/src/delimited.rs
+++ b/src/delimited.rs
@@ -7,14 +7,12 @@
#[cfg_attr(feature = "extra-traits", derive(Eq, PartialEq, Hash))]
#[cfg_attr(feature = "clone-impls", derive(Clone))]
pub struct Delimited<T, D> {
- inner: Vec<(T, Option<D>)>
+ inner: Vec<(T, Option<D>)>,
}
impl<T, D> Delimited<T, D> {
pub fn new() -> Delimited<T, D> {
- Delimited {
- inner: Vec::new(),
- }
+ Delimited { inner: Vec::new() }
}
pub fn is_empty(&self) -> bool {
@@ -42,51 +40,53 @@
}
pub fn first(&self) -> Option<Element<&T, &D>> {
- self.inner.first().map(|&(ref t, ref d)| {
- match *d {
- Some(ref d) => Element::Delimited(t, d),
- None => Element::End(t),
- }
+ self.inner.first().map(|&(ref t, ref d)| match *d {
+ Some(ref d) => Element::Delimited(t, d),
+ None => Element::End(t),
})
}
pub fn first_mut(&mut self) -> Option<Element<&mut T, &mut D>> {
- self.inner.first_mut().map(|&mut (ref mut t, ref mut d)| {
- match *d {
+ self.inner
+ .first_mut()
+ .map(|&mut (ref mut t, ref mut d)| match *d {
Some(ref mut d) => Element::Delimited(t, d),
None => Element::End(t),
- }
- })
+ })
}
pub fn last(&self) -> Option<Element<&T, &D>> {
- self.inner.last().map(|&(ref t, ref d)| {
- match *d {
- Some(ref d) => Element::Delimited(t, d),
- None => Element::End(t),
- }
+ self.inner.last().map(|&(ref t, ref d)| match *d {
+ Some(ref d) => Element::Delimited(t, d),
+ None => Element::End(t),
})
}
pub fn last_mut(&mut self) -> Option<Element<&mut T, &mut D>> {
- self.inner.last_mut().map(|&mut (ref mut t, ref mut d)| {
- match *d {
+ self.inner
+ .last_mut()
+ .map(|&mut (ref mut t, ref mut d)| match *d {
Some(ref mut d) => Element::Delimited(t, d),
None => Element::End(t),
- }
- })
+ })
}
pub fn iter(&self) -> Iter<T, D> {
- Iter { inner: self.inner.iter() }
+ Iter {
+ inner: self.inner.iter(),
+ }
}
pub fn iter_mut(&mut self) -> IterMut<T, D> {
- IterMut { inner: self.inner.iter_mut() }
+ IterMut {
+ inner: self.inner.iter_mut(),
+ }
}
pub fn items(&self) -> Items<T, D> {
- Items { inner: self.inner.iter() }
+ Items {
+ inner: self.inner.iter(),
+ }
}
pub fn push(&mut self, token: Element<T, D>) {
@@ -113,7 +113,10 @@
self.inner[len - 1].1 = Some(delimiter);
}
- pub fn push_default(&mut self, token: T) where D: Default {
+ pub fn push_default(&mut self, token: T)
+ where
+ D: Default,
+ {
if self.is_empty() || self.trailing_delim() {
self.inner.push((token, None));
} else {
@@ -122,11 +125,9 @@
}
pub fn pop(&mut self) -> Option<Element<T, D>> {
- self.inner.pop().map(|e| {
- match e {
- (t, Some(d)) => Element::Delimited(t, d),
- (t, None) => Element::End(t),
- }
+ self.inner.pop().map(|e| match e {
+ (t, Some(d)) => Element::Delimited(t, d),
+ (t, None) => Element::End(t),
})
}
@@ -155,21 +156,30 @@
impl<T, D> From<Vec<(T, Option<D>)>> for Delimited<T, D> {
fn from(v: Vec<(T, Option<D>)>) -> Self {
- Delimited {
- inner: v,
- }
+ Delimited { inner: v }
}
}
impl<T, D> From<Vec<T>> for Delimited<T, D>
- where D: Default,
+where
+ D: Default,
{
fn from(v: Vec<T>) -> Self {
let len = v.len();
Delimited {
- inner: v.into_iter().enumerate().map(|(i, item)| {
- (item, if i + 1 == len {None} else {Some(D::default())})
- }).collect(),
+ inner: v.into_iter()
+ .enumerate()
+ .map(|(i, item)| {
+ (
+ item,
+ if i + 1 == len {
+ None
+ } else {
+ Some(D::default())
+ },
+ )
+ })
+ .collect(),
}
}
}
@@ -183,7 +193,8 @@
}
impl<T, D> FromIterator<T> for Delimited<T, D>
- where D: Default,
+where
+ D: Default,
{
fn from_iter<I: IntoIterator<Item = T>>(i: I) -> Self {
let mut ret = Delimited::new();
@@ -204,7 +215,8 @@
}
impl<T, D> Extend<T> for Delimited<T, D>
- where D: Default,
+where
+ D: Default,
{
fn extend<I: IntoIterator<Item = T>>(&mut self, i: I) {
for element in i {
@@ -236,7 +248,9 @@
type IntoIter = IntoIter<T, D>;
fn into_iter(self) -> Self::IntoIter {
- IntoIter { inner: self.inner.into_iter() }
+ IntoIter {
+ inner: self.inner.into_iter(),
+ }
}
}
@@ -254,11 +268,9 @@
type Item = Element<&'a T, &'a D>;
fn next(&mut self) -> Option<Element<&'a T, &'a D>> {
- self.inner.next().map(|pair| {
- match pair.1 {
- Some(ref delimited) => Element::Delimited(&pair.0, delimited),
- None => Element::End(&pair.0),
- }
+ self.inner.next().map(|pair| match pair.1 {
+ Some(ref delimited) => Element::Delimited(&pair.0, delimited),
+ None => Element::End(&pair.0),
})
}
}
@@ -271,11 +283,9 @@
type Item = Element<&'a mut T, &'a mut D>;
fn next(&mut self) -> Option<Element<&'a mut T, &'a mut D>> {
- self.inner.next().map(|pair| {
- match pair.1 {
- Some(ref mut delimited) => Element::Delimited(&mut pair.0, delimited),
- None => Element::End(&mut pair.0),
- }
+ self.inner.next().map(|pair| match pair.1 {
+ Some(ref mut delimited) => Element::Delimited(&mut pair.0, delimited),
+ None => Element::End(&mut pair.0),
})
}
}
@@ -300,11 +310,9 @@
type Item = Element<T, D>;
fn next(&mut self) -> Option<Element<T, D>> {
- self.inner.next().map(|pair| {
- match pair.1 {
- Some(v) => Element::Delimited(pair.0, v),
- None => Element::End(pair.0)
- }
+ self.inner.next().map(|pair| match pair.1 {
+ Some(v) => Element::Delimited(pair.0, v),
+ None => Element::End(pair.0),
})
}
}
@@ -317,22 +325,19 @@
impl<T, D> Element<T, D> {
pub fn into_item(self) -> T {
match self {
- Element::Delimited(t, _) |
- Element::End(t) => t,
+ Element::Delimited(t, _) | Element::End(t) => t,
}
}
pub fn item(&self) -> &T {
match *self {
- Element::Delimited(ref t, _) |
- Element::End(ref t) => t,
+ Element::Delimited(ref t, _) | Element::End(ref t) => t,
}
}
pub fn item_mut(&mut self) -> &mut T {
match *self {
- Element::Delimited(ref mut t, _) |
- Element::End(ref mut t) => t,
+ Element::Delimited(ref mut t, _) | Element::End(ref mut t) => t,
}
}
@@ -356,41 +361,38 @@
use super::Delimited;
use synom::Synom;
use cursor::Cursor;
- use {PResult, parse_error};
+ use {parse_error, PResult};
impl<T, D> Delimited<T, D>
- where T: Synom,
- D: Synom,
+ where
+ T: Synom,
+ D: Synom,
{
- pub fn parse_separated(input: Cursor) -> PResult<Self>
- {
+ pub fn parse_separated(input: Cursor) -> PResult<Self> {
Self::parse(input, T::parse, false)
}
- pub fn parse_separated_nonempty(input: Cursor) -> PResult<Self>
- {
+ pub fn parse_separated_nonempty(input: Cursor) -> PResult<Self> {
Self::parse_separated_nonempty_with(input, T::parse)
}
- pub fn parse_terminated(input: Cursor) -> PResult<Self>
- {
+ pub fn parse_terminated(input: Cursor) -> PResult<Self> {
Self::parse_terminated_with(input, T::parse)
}
- pub fn parse_terminated_nonempty(input: Cursor) -> PResult<Self>
- {
+ pub fn parse_terminated_nonempty(input: Cursor) -> PResult<Self> {
Self::parse_terminated_nonempty_with(input, T::parse)
}
}
impl<T, D> Delimited<T, D>
- where D: Synom,
+ where
+ D: Synom,
{
pub fn parse_separated_nonempty_with(
- input: Cursor,
- parse: fn(Cursor) -> PResult<T>)
- -> PResult<Self>
- {
+ input: Cursor,
+ parse: fn(Cursor) -> PResult<T>,
+ ) -> PResult<Self> {
match Self::parse(input, parse, false) {
Ok((_, ref b)) if b.is_empty() => parse_error(),
other => other,
@@ -398,29 +400,27 @@
}
pub fn parse_terminated_with(
- input: Cursor,
- parse: fn(Cursor) -> PResult<T>)
- -> PResult<Self>
- {
+ input: Cursor,
+ parse: fn(Cursor) -> PResult<T>,
+ ) -> PResult<Self> {
Self::parse(input, parse, true)
}
pub fn parse_terminated_nonempty_with(
- input: Cursor,
- parse: fn(Cursor) -> PResult<T>)
- -> PResult<Self>
- {
+ input: Cursor,
+ parse: fn(Cursor) -> PResult<T>,
+ ) -> PResult<Self> {
match Self::parse(input, parse, true) {
Ok((_, ref b)) if b.is_empty() => parse_error(),
other => other,
}
}
- fn parse(mut input: Cursor,
- parse: fn(Cursor) -> PResult<T>,
- terminated: bool)
- -> PResult<Self>
- {
+ fn parse(
+ mut input: Cursor,
+ parse: fn(Cursor) -> PResult<T>,
+ terminated: bool,
+ ) -> PResult<Self> {
let mut res = Delimited::new();
// get the first element
@@ -466,12 +466,12 @@
#[cfg(feature = "printing")]
mod printing {
use super::*;
- use quote::{Tokens, ToTokens};
-
+ use quote::{ToTokens, Tokens};
impl<T, D> ToTokens for Delimited<T, D>
- where T: ToTokens,
- D: ToTokens,
+ where
+ T: ToTokens,
+ D: ToTokens,
{
fn to_tokens(&self, tokens: &mut Tokens) {
tokens.append_all(self.iter())
@@ -479,8 +479,9 @@
}
impl<T, D> ToTokens for Element<T, D>
- where T: ToTokens,
- D: ToTokens,
+ where
+ T: ToTokens,
+ D: ToTokens,
{
fn to_tokens(&self, tokens: &mut Tokens) {
match *self {
diff --git a/src/derive.rs b/src/derive.rs
index 7fc5097..da3f2ea 100644
--- a/src/derive.rs
+++ b/src/derive.rs
@@ -21,7 +21,6 @@
}
}
-
ast_enum_of_structs! {
/// Body of a derived struct or enum.
pub enum Body {
@@ -99,7 +98,6 @@
}
}
-
named!(struct_body -> (WhereClause, VariantData, Option<Token![;]>), alt!(
do_parse!(
wh: syn!(WhereClause) >>
@@ -165,7 +163,7 @@
use super::*;
use attr::FilterAttrs;
use data::VariantData;
- use quote::{Tokens, ToTokens};
+ use quote::{ToTokens, Tokens};
impl ToTokens for DeriveInput {
fn to_tokens(&self, tokens: &mut Tokens) {
diff --git a/src/error.rs b/src/error.rs
index d1bb670..bd33775 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -51,4 +51,3 @@
ParseError(Some(msg.into()))
}
}
-
diff --git a/src/expr.rs b/src/expr.rs
index b244de2..6f81edb 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -639,16 +639,16 @@
// see https://github.com/rust-lang/rust/blob/eb8f2586e
// /src/libsyntax/parse/classify.rs#L17-L37
match expr.node {
- ExprKind::Unsafe(..) |
- ExprKind::Block(..) |
- ExprKind::If(..) |
- ExprKind::IfLet(..) |
- ExprKind::Match(..) |
- ExprKind::While(..) |
- ExprKind::WhileLet(..) |
- ExprKind::Loop(..) |
- ExprKind::ForLoop(..) |
- ExprKind::Catch(..) => false,
+ ExprKind::Unsafe(..)
+ | ExprKind::Block(..)
+ | ExprKind::If(..)
+ | ExprKind::IfLet(..)
+ | ExprKind::Match(..)
+ | ExprKind::While(..)
+ | ExprKind::WhileLet(..)
+ | ExprKind::Loop(..)
+ | ExprKind::ForLoop(..)
+ | ExprKind::Catch(..) => false,
_ => true,
}
}
@@ -659,7 +659,7 @@
use ty::parsing::qpath;
#[cfg(feature = "full")]
- use proc_macro2::{Span, TokenStream, TokenNode, Delimiter, Term};
+ use proc_macro2::{Delimiter, Span, Term, TokenNode, TokenStream};
use synom::Synom;
use cursor::Cursor;
#[cfg(feature = "full")]
@@ -708,10 +708,7 @@
// Parse an arbitrary expression.
#[cfg(feature = "full")]
- fn ambiguous_expr(i: Cursor,
- allow_struct: bool,
- allow_block: bool)
- -> PResult<Expr> {
+ fn ambiguous_expr(i: Cursor, allow_struct: bool, allow_block: bool) -> PResult<Expr> {
map!(
i,
call!(assign_expr, allow_struct, allow_block),
@@ -720,10 +717,7 @@
}
#[cfg(not(feature = "full"))]
- fn ambiguous_expr(i: Cursor,
- allow_struct: bool,
- allow_block: bool)
- -> PResult<Expr> {
+ fn ambiguous_expr(i: Cursor, allow_struct: bool, allow_block: bool) -> PResult<Expr> {
map!(
i,
// NOTE: We intentionally skip assign_expr, placement_expr, and
@@ -880,7 +874,10 @@
//
// NOTE: This operator appears to be parsed as left-associative, but errors
// if it is used in a non-associative manner.
- binop!(compare_expr, bitor_expr, alt!(
+ binop!(
+ compare_expr,
+ bitor_expr,
+ alt!(
punct!(==) => { BinOp::Eq }
|
punct!(!=) => { BinOp::Ne }
@@ -899,59 +896,74 @@
)
|
punct!(>) => { BinOp::Gt }
- ));
+ )
+ );
// <bitxor> | <bitxor> ...
- binop!(bitor_expr, bitxor_expr, do_parse!(
- not!(punct!(||)) >>
- not!(punct!(|=)) >>
- t: punct!(|) >>
- (BinOp::BitOr(t))
- ));
+ binop!(
+ bitor_expr,
+ bitxor_expr,
+ do_parse!(not!(punct!(||)) >> not!(punct!(|=)) >> t: punct!(|) >> (BinOp::BitOr(t)))
+ );
// <bitand> ^ <bitand> ...
- binop!(bitxor_expr, bitand_expr, do_parse!(
- // NOTE: Make sure we aren't looking at ^=.
- not!(punct!(^=)) >>
- t: punct!(^) >>
- (BinOp::BitXor(t))
- ));
+ binop!(
+ bitxor_expr,
+ bitand_expr,
+ do_parse!(
+ // NOTE: Make sure we aren't looking at ^=.
+ not!(punct!(^=)) >> t: punct!(^) >> (BinOp::BitXor(t))
+ )
+ );
// <shift> & <shift> ...
- binop!(bitand_expr, shift_expr, do_parse!(
- // NOTE: Make sure we aren't looking at && or &=.
- not!(punct!(&&)) >>
- not!(punct!(&=)) >>
- t: punct!(&) >>
- (BinOp::BitAnd(t))
- ));
+ binop!(
+ bitand_expr,
+ shift_expr,
+ do_parse!(
+ // NOTE: Make sure we aren't looking at && or &=.
+ not!(punct!(&&)) >> not!(punct!(&=)) >> t: punct!(&) >> (BinOp::BitAnd(t))
+ )
+ );
// <arith> << <arith> ...
// <arith> >> <arith> ...
- binop!(shift_expr, arith_expr, alt!(
+ binop!(
+ shift_expr,
+ arith_expr,
+ alt!(
punct!(<<) => { BinOp::Shl }
|
punct!(>>) => { BinOp::Shr }
- ));
+ )
+ );
// <term> + <term> ...
// <term> - <term> ...
- binop!(arith_expr, term_expr, alt!(
+ binop!(
+ arith_expr,
+ term_expr,
+ alt!(
punct!(+) => { BinOp::Add }
|
punct!(-) => { BinOp::Sub }
- ));
+ )
+ );
// <cast> * <cast> ...
// <cast> / <cast> ...
// <cast> % <cast> ...
- binop!(term_expr, cast_expr, alt!(
+ binop!(
+ term_expr,
+ cast_expr,
+ alt!(
punct!(*) => { BinOp::Mul }
|
punct!(/) => { BinOp::Div }
|
punct!(%) => { BinOp::Rem }
- ));
+ )
+ );
// <unary> as <ty>
// <unary> : <ty>
@@ -1203,7 +1215,6 @@
syn!(ExprPath) => { ExprKind::Path }
));
-
#[cfg(feature = "full")]
named!(expr_nosemi -> Expr, map!(alt!(
syn!(ExprIf) => { ExprKind::If }
@@ -1400,7 +1411,6 @@
(else_, expr)
));
-
#[cfg(feature = "full")]
impl Synom for ExprForLoop {
named!(parse -> Self, do_parse!(
@@ -2257,7 +2267,7 @@
use super::*;
#[cfg(feature = "full")]
use attr::FilterAttrs;
- use quote::{Tokens, ToTokens};
+ use quote::{ToTokens, Tokens};
// If the given expression is a bare `ExprStruct`, wraps it in parenthesis
// before appending it to `Tokens`.
@@ -2406,19 +2416,18 @@
}
#[cfg(feature = "full")]
- fn maybe_wrap_else(tokens: &mut Tokens,
- else_token: &Option<Token![else]>,
- if_false: &Option<Box<Expr>>)
- {
+ fn maybe_wrap_else(
+ tokens: &mut Tokens,
+ else_token: &Option<Token![else]>,
+ if_false: &Option<Box<Expr>>,
+ ) {
if let Some(ref if_false) = *if_false {
TokensOrDefault(else_token).to_tokens(tokens);
// If we are not one of the valid expressions to exist in an else
// clause, wrap ourselves in a block.
match if_false.node {
- ExprKind::If(_) |
- ExprKind::IfLet(_) |
- ExprKind::Block(_) => {
+ ExprKind::If(_) | ExprKind::IfLet(_) | ExprKind::Block(_) => {
if_false.to_tokens(tokens);
}
_ => {
@@ -2515,7 +2524,7 @@
self.match_token.to_tokens(tokens);
wrap_bare_struct(tokens, &self.expr);
self.brace_token.surround(tokens, |tokens| {
- for (i, arm) in self.arms.iter().enumerate() {
+ for (i, arm) in self.arms.iter().enumerate() {
arm.to_tokens(tokens);
// Ensure that we have a comma after a non-block arm, except
// for the last one.
@@ -2552,7 +2561,11 @@
self.or1_token.to_tokens(tokens);
for item in self.decl.inputs.iter() {
match **item.item() {
- FnArg::Captured(ArgCaptured { ref pat, ty: Type::Infer(_), .. }) => {
+ FnArg::Captured(ArgCaptured {
+ ref pat,
+ ty: Type::Infer(_),
+ ..
+ }) => {
pat.to_tokens(tokens);
}
_ => item.item().to_tokens(tokens),
@@ -2874,8 +2887,8 @@
// If we need a comma before the middle or standalone .. token,
// then make sure it's present.
- if !self.front.empty_or_trailing() &&
- (self.middle.is_some() || self.dot2_token.is_some())
+ if !self.front.empty_or_trailing()
+ && (self.middle.is_some() || self.dot2_token.is_some())
{
<Token![,]>::default().to_tokens(tokens);
}
diff --git a/src/file.rs b/src/file.rs
index 0cc1428..fd3d5b2 100644
--- a/src/file.rs
+++ b/src/file.rs
@@ -35,7 +35,7 @@
mod printing {
use super::*;
use attr::FilterAttrs;
- use quote::{Tokens, ToTokens};
+ use quote::{ToTokens, Tokens};
impl ToTokens for File {
fn to_tokens(&self, tokens: &mut Tokens) {
diff --git a/src/generics.rs b/src/generics.rs
index 12d33d0..fee556c 100644
--- a/src/generics.rs
+++ b/src/generics.rs
@@ -400,7 +400,7 @@
mod printing {
use super::*;
use attr::FilterAttrs;
- use quote::{Tokens, ToTokens};
+ use quote::{ToTokens, Tokens};
/// Returns true if the generics object has no lifetimes or ty_params.
fn empty_normal_generics(generics: &Generics) -> bool {
diff --git a/src/helper.rs b/src/helper.rs
index 63378c8..93df003 100644
--- a/src/helper.rs
+++ b/src/helper.rs
@@ -209,7 +209,6 @@
};
}
-
/// Same as the `parens` macro, but for brackets.
#[macro_export]
macro_rules! brackets {
diff --git a/src/ident.rs b/src/ident.rs
index 7cdaf06..1e717c9 100644
--- a/src/ident.rs
+++ b/src/ident.rs
@@ -68,7 +68,7 @@
/// If `syn` is used to parse existing Rust source code, it is often useful to
/// convert the `Ident` to a more generic string data type at some point. The
/// methods `as_ref()` and `to_string()` achieve this.
-///
+///
/// ```rust
/// # use syn::Ident;
/// # let ident = Ident::from("another_identifier");
@@ -92,7 +92,6 @@
}
impl Ident {
-
/// Creates a new `Ident` from the structured items. This is mainly used
/// by the parser to create `Ident`s from existing Rust source code.
///
@@ -196,7 +195,8 @@
}
impl<T: ?Sized> PartialEq<T> for Ident
- where T: AsRef<str>
+where
+ T: AsRef<str>,
{
fn eq(&self, other: &T) -> bool {
self.as_ref() == other.as_ref()
@@ -228,7 +228,7 @@
use super::*;
use synom::Synom;
use cursor::Cursor;
- use {PResult, parse_error};
+ use {parse_error, PResult};
impl Synom for Ident {
fn parse(input: Cursor) -> PResult<Self> {
@@ -241,20 +241,23 @@
}
match sym.as_str() {
// From https://doc.rust-lang.org/grammar.html#keywords
- "abstract" | "alignof" | "as" | "become" | "box" | "break" | "const" | "continue" |
- "crate" | "do" | "else" | "enum" | "extern" | "false" | "final" | "fn" | "for" |
- "if" | "impl" | "in" | "let" | "loop" | "macro" | "match" | "mod" | "move" |
- "mut" | "offsetof" | "override" | "priv" | "proc" | "pub" | "pure" | "ref" |
- "return" | "Self" | "self" | "sizeof" | "static" | "struct" | "super" | "trait" |
- "true" | "type" | "typeof" | "unsafe" | "unsized" | "use" | "virtual" | "where" |
- "while" | "yield" => return parse_error(),
+ "abstract" | "alignof" | "as" | "become" | "box" | "break" | "const"
+ | "continue" | "crate" | "do" | "else" | "enum" | "extern" | "false" | "final"
+ | "fn" | "for" | "if" | "impl" | "in" | "let" | "loop" | "macro" | "match"
+ | "mod" | "move" | "mut" | "offsetof" | "override" | "priv" | "proc" | "pub"
+ | "pure" | "ref" | "return" | "Self" | "self" | "sizeof" | "static" | "struct"
+ | "super" | "trait" | "true" | "type" | "typeof" | "unsafe" | "unsized" | "use"
+ | "virtual" | "where" | "while" | "yield" => return parse_error(),
_ => {}
}
- Ok((rest, Ident {
- span: span,
- sym: sym,
- }))
+ Ok((
+ rest,
+ Ident {
+ span: span,
+ sym: sym,
+ },
+ ))
}
fn description() -> Option<&'static str> {
@@ -266,8 +269,8 @@
#[cfg(feature = "printing")]
mod printing {
use super::*;
- use quote::{Tokens, ToTokens};
- use proc_macro2::{TokenTree, TokenNode};
+ use quote::{ToTokens, Tokens};
+ use proc_macro2::{TokenNode, TokenTree};
impl ToTokens for Ident {
fn to_tokens(&self, tokens: &mut Tokens) {
diff --git a/src/item.rs b/src/item.rs
index 17fbe6c..d38d25f 100644
--- a/src/item.rs
+++ b/src/item.rs
@@ -215,9 +215,7 @@
#[cfg(feature = "extra-traits")]
impl PartialEq for ItemMacro2 {
fn eq(&self, other: &Self) -> bool {
- self.attrs == other.attrs
- && self.vis == other.vis
- && self.macro_token == other.macro_token
+ self.attrs == other.attrs && self.vis == other.vis && self.macro_token == other.macro_token
&& self.ident == other.ident
&& TokenTreeHelper(&self.args) == TokenTreeHelper(&other.args)
&& TokenTreeHelper(&self.body) == TokenTreeHelper(&other.body)
@@ -227,7 +225,8 @@
#[cfg(feature = "extra-traits")]
impl Hash for ItemMacro2 {
fn hash<H>(&self, state: &mut H)
- where H: Hasher
+ where
+ H: Hasher,
{
self.attrs.hash(state);
self.vis.hash(state);
@@ -241,28 +240,24 @@
impl From<DeriveInput> for Item {
fn from(input: DeriveInput) -> Item {
match input.body {
- Body::Enum(data) => {
- Item::Enum(ItemEnum {
- attrs: input.attrs,
- vis: input.vis,
- enum_token: data.enum_token,
- ident: input.ident,
- generics: input.generics,
- brace_token: data.brace_token,
- variants: data.variants,
- })
- }
- Body::Struct(data) => {
- Item::Struct(ItemStruct {
- attrs: input.attrs,
- vis: input.vis,
- struct_token: data.struct_token,
- ident: input.ident,
- generics: input.generics,
- data: data.data,
- semi_token: data.semi_token,
- })
- }
+ Body::Enum(data) => Item::Enum(ItemEnum {
+ attrs: input.attrs,
+ vis: input.vis,
+ enum_token: data.enum_token,
+ ident: input.ident,
+ generics: input.generics,
+ brace_token: data.brace_token,
+ variants: data.variants,
+ }),
+ Body::Struct(data) => Item::Struct(ItemStruct {
+ attrs: input.attrs,
+ vis: input.vis,
+ struct_token: data.struct_token,
+ ident: input.ident,
+ generics: input.generics,
+ data: data.data,
+ semi_token: data.semi_token,
+ }),
}
}
}
@@ -1340,7 +1335,7 @@
use super::*;
use attr::FilterAttrs;
use data::VariantData;
- use quote::{Tokens, ToTokens};
+ use quote::{ToTokens, Tokens};
impl ToTokens for ItemExternCrate {
fn to_tokens(&self, tokens: &mut Tokens) {
diff --git a/src/lib.rs b/src/lib.rs
index e133f75..106a045 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,15 +1,10 @@
#![doc(html_root_url = "https://dtolnay.github.io/syn")]
+#![cfg_attr(feature = "cargo-clippy",
+ allow(const_static_lifetime, doc_markdown, large_enum_variant, match_bool,
+ redundant_closure))]
-#![cfg_attr(feature = "cargo-clippy", allow(
- const_static_lifetime,
- doc_markdown,
- large_enum_variant,
- match_bool,
- redundant_closure,
-))]
-
-extern crate proc_macro;
extern crate proc_macro2;
+extern crate proc_macro;
extern crate unicode_xid;
#[cfg(any(feature = "printing", feature = "parsing"))]
@@ -32,33 +27,29 @@
pub mod token;
mod attr;
-pub use attr::{Attribute, AttrStyle, MetaItem, NestedMetaItem, MetaItemList,
- MetaNameValue};
+pub use attr::{AttrStyle, Attribute, MetaItem, MetaItemList, MetaNameValue, NestedMetaItem};
mod data;
-pub use data::{Field, Variant, VariantData, Visibility, VisRestricted, VisCrate,
- VisPublic, VisInherited};
+pub use data::{Field, Variant, VariantData, VisCrate, VisInherited, VisPublic, VisRestricted,
+ Visibility};
mod expr;
-pub use expr::{Expr, ExprKind, ExprBox, ExprInPlace, ExprArray, ExprCall,
- ExprMethodCall, ExprTuple, ExprBinary, ExprUnary, ExprCast,
- ExprType, ExprIf, ExprIfLet, ExprWhile, ExprWhileLet,
- ExprForLoop, ExprLoop, ExprMatch, ExprClosure, ExprBlock,
- ExprAssign, ExprAssignOp, ExprField, ExprTupField, ExprIndex,
- ExprRange, ExprPath, ExprAddrOf, ExprBreak, ExprContinue,
- ExprRet, ExprStruct, ExprRepeat, ExprParen, ExprTry, ExprCatch,
- ExprGroup, ExprYield, ExprUnsafe};
+pub use expr::{Expr, ExprAddrOf, ExprArray, ExprAssign, ExprAssignOp, ExprBinary, ExprBlock,
+ ExprBox, ExprBreak, ExprCall, ExprCast, ExprCatch, ExprClosure, ExprContinue,
+ ExprField, ExprForLoop, ExprGroup, ExprIf, ExprIfLet, ExprInPlace, ExprIndex,
+ ExprKind, ExprLoop, ExprMatch, ExprMethodCall, ExprParen, ExprPath, ExprRange,
+ ExprRepeat, ExprRet, ExprStruct, ExprTry, ExprTupField, ExprTuple, ExprType,
+ ExprUnary, ExprUnsafe, ExprWhile, ExprWhileLet, ExprYield};
#[cfg(feature = "full")]
-pub use expr::{Arm, BindingMode, Block, CaptureBy, FieldPat, FieldValue, Local,
- MacStmtStyle, Pat, RangeLimits, Stmt, PatIdent, PatWild,
- PatStruct, PatTuple, PatTupleStruct, PatPath, PatBox, PatRef,
- PatLit, PatRange, PatSlice, InPlaceKind};
+pub use expr::{Arm, BindingMode, Block, CaptureBy, FieldPat, FieldValue, InPlaceKind, Local,
+ MacStmtStyle, Pat, PatBox, PatIdent, PatLit, PatPath, PatRange, PatRef, PatSlice,
+ PatStruct, PatTuple, PatTupleStruct, PatWild, RangeLimits, Stmt};
mod generics;
-pub use generics::{Generics, GenericParam, LifetimeDef, TraitBoundModifier, TypeParam, TypeParamBound,
- WhereBoundPredicate, WhereClause, WhereEqPredicate, WherePredicate,
- WhereRegionPredicate, BoundLifetimes, ConstParam};
+pub use generics::{BoundLifetimes, ConstParam, GenericParam, Generics, LifetimeDef,
+ TraitBoundModifier, TypeParam, TypeParamBound, WhereBoundPredicate,
+ WhereClause, WhereEqPredicate, WherePredicate, WhereRegionPredicate};
#[cfg(feature = "printing")]
pub use generics::{ImplGenerics, Turbofish, TypeGenerics};
@@ -68,15 +59,13 @@
#[cfg(feature = "full")]
mod item;
#[cfg(feature = "full")]
-pub use item::{Constness, Defaultness, FnArg, FnDecl, ForeignItem, ItemForeignMod,
- ImplItem, ImplPolarity, Item, MethodSig,
- TraitItem, ItemExternCrate, ItemUse,
- ItemStatic, ItemConst, ItemFn, ItemMacro, ItemMacro2, ItemMod, ItemType, ItemEnum,
- ItemStruct, ItemUnion, ItemTrait, ItemDefaultImpl, ItemImpl,
- UsePath, UseGlob, UseList, ForeignItemFn, ForeignItemStatic, ForeignItemType,
- TraitItemConst, TraitItemMacro, TraitItemMethod, TraitItemType,
- ImplItemConst, ImplItemMacro, ImplItemMethod, ImplItemType, ArgSelfRef,
- ArgSelf, ArgCaptured, UseTree};
+pub use item::{ArgCaptured, ArgSelf, ArgSelfRef, Constness, Defaultness, FnArg, FnDecl,
+ ForeignItem, ForeignItemFn, ForeignItemStatic, ForeignItemType, ImplItem,
+ ImplItemConst, ImplItemMacro, ImplItemMethod, ImplItemType, ImplPolarity, Item,
+ ItemConst, ItemDefaultImpl, ItemEnum, ItemExternCrate, ItemFn, ItemForeignMod,
+ ItemImpl, ItemMacro, ItemMacro2, ItemMod, ItemStatic, ItemStruct, ItemTrait,
+ ItemType, ItemUnion, ItemUse, MethodSig, TraitItem, TraitItemConst, TraitItemMacro,
+ TraitItemMethod, TraitItemType, UseGlob, UseList, UsePath, UseTree};
#[cfg(feature = "full")]
mod file;
@@ -93,19 +82,17 @@
pub use mac::Macro;
mod derive;
-pub use derive::{Body, DeriveInput, BodyEnum, BodyStruct};
+pub use derive::{Body, BodyEnum, BodyStruct, DeriveInput};
mod op;
pub use op::{BinOp, UnOp};
mod ty;
-pub use ty::{Abi, AbiKind, AngleBracketedGenericArguments, BareFnArg,
- BareFnArgName, BareFnType, ReturnType, MutType, Mutability,
- ParenthesizedGenericArguments, Path, PathArguments, PathSegment,
- PolyTraitRef, QSelf, Type, TypeBinding, Unsafety, TypeSlice,
- TypeArray, TypePtr, TypeReference, TypeBareFn, TypeNever, TypeTuple,
- TypePath, TypeTraitObject, TypeImplTrait, TypeParen, TypeInfer,
- TypeGroup, GenericArgument};
+pub use ty::{Abi, AbiKind, AngleBracketedGenericArguments, BareFnArg, BareFnArgName, BareFnType,
+ GenericArgument, MutType, Mutability, ParenthesizedGenericArguments, Path,
+ PathArguments, PathSegment, PolyTraitRef, QSelf, ReturnType, Type, TypeArray,
+ TypeBareFn, TypeBinding, TypeGroup, TypeImplTrait, TypeInfer, TypeNever, TypeParen,
+ TypePath, TypePtr, TypeReference, TypeSlice, TypeTraitObject, TypeTuple, Unsafety};
#[cfg(feature = "printing")]
pub use ty::PathTokens;
@@ -184,14 +171,16 @@
/// ```
#[cfg(feature = "parsing")]
pub fn parse<T>(tokens: proc_macro::TokenStream) -> Result<T, ParseError>
- where T: Synom,
+where
+ T: Synom,
{
_parse(tokens.into())
}
#[cfg(feature = "parsing")]
fn _parse<T>(tokens: proc_macro2::TokenStream) -> Result<T, ParseError>
- where T: Synom,
+where
+ T: Synom,
{
let buf = SynomBuffer::new(tokens);
let result = T::parse(buf.begin());
@@ -335,7 +324,8 @@
#[cfg(feature = "printing")]
impl<'a, T> quote::ToTokens for TokensOrDefault<'a, T>
- where T: quote::ToTokens + Default,
+where
+ T: quote::ToTokens + Default,
{
fn to_tokens(&self, tokens: &mut quote::Tokens) {
match *self.0 {
diff --git a/src/lifetime.rs b/src/lifetime.rs
index 5d3c191..27ae9a2 100644
--- a/src/lifetime.rs
+++ b/src/lifetime.rs
@@ -17,9 +17,11 @@
let s = sym.as_str();
if !s.starts_with('\'') {
- panic!("lifetime name must start with apostrophe as in \"'a\", \
- got {:?}",
- s);
+ panic!(
+ "lifetime name must start with apostrophe as in \"'a\", \
+ got {:?}",
+ s
+ );
}
if s == "'" {
@@ -92,7 +94,7 @@
use super::*;
use synom::Synom;
use cursor::Cursor;
- use {PResult, parse_error};
+ use {parse_error, PResult};
impl Synom for Lifetime {
fn parse(input: Cursor) -> PResult<Self> {
@@ -104,10 +106,13 @@
return parse_error();
}
- Ok((rest, Lifetime {
- sym: sym,
- span: span,
- }))
+ Ok((
+ rest,
+ Lifetime {
+ sym: sym,
+ span: span,
+ },
+ ))
}
}
}
@@ -115,8 +120,8 @@
#[cfg(feature = "printing")]
mod printing {
use super::*;
- use quote::{Tokens, ToTokens};
- use proc_macro2::{TokenTree, TokenNode};
+ use quote::{ToTokens, Tokens};
+ use proc_macro2::{TokenNode, TokenTree};
impl ToTokens for Lifetime {
fn to_tokens(&self, tokens: &mut Tokens) {
diff --git a/src/lit.rs b/src/lit.rs
index 9480563..81af734 100644
--- a/src/lit.rs
+++ b/src/lit.rs
@@ -1,7 +1,7 @@
use std::fmt;
use std::hash::{Hash, Hasher};
-use proc_macro2::{self, Span, Literal, TokenNode, TokenTree, Term};
+use proc_macro2::{self, Literal, Span, Term, TokenNode, TokenTree};
#[derive(Clone)]
pub struct Lit {
@@ -77,9 +77,7 @@
fn eq(&self, other: &LitKind) -> bool {
match (self, other) {
(&LitKind::Bool(b1), &LitKind::Bool(b2)) => b1 == b2,
- (&LitKind::Other(ref l1), &LitKind::Other(ref l2)) => {
- l1.to_string() == l2.to_string()
- }
+ (&LitKind::Other(ref l1), &LitKind::Other(ref l2)) => l1.to_string() == l2.to_string(),
_ => false,
}
}
@@ -101,17 +99,18 @@
use super::*;
use synom::Synom;
use cursor::Cursor;
- use {PResult, parse_error};
+ use {parse_error, PResult};
impl Synom for Lit {
fn parse(input: Cursor) -> PResult<Self> {
match input.literal() {
- Some((rest, span, lit)) => {
- Ok((rest, Lit {
+ Some((rest, span, lit)) => Ok((
+ rest,
+ Lit {
span: span,
- value: LitKind::Other(lit)
- }))
- }
+ value: LitKind::Other(lit),
+ },
+ )),
_ => match input.word() {
Some((rest, span, sym)) => {
let kind = if sym.as_str() == "true" {
@@ -122,13 +121,16 @@
return parse_error();
};
- Ok((rest, Lit {
- span: span,
- value: kind
- }))
+ Ok((
+ rest,
+ Lit {
+ span: span,
+ value: kind,
+ },
+ ))
}
_ => parse_error(),
- }
+ },
}
}
}
@@ -137,7 +139,7 @@
#[cfg(feature = "printing")]
mod printing {
use super::*;
- use quote::{Tokens, ToTokens};
+ use quote::{ToTokens, Tokens};
impl ToTokens for Lit {
fn to_tokens(&self, tokens: &mut Tokens) {
diff --git a/src/mac.rs b/src/mac.rs
index 1de6a2a..f093a8c 100644
--- a/src/mac.rs
+++ b/src/mac.rs
@@ -1,6 +1,6 @@
use super::*;
-use proc_macro2::{TokenNode, TokenTree, Delimiter};
+use proc_macro2::{Delimiter, TokenNode, TokenTree};
#[cfg(feature = "extra-traits")]
use proc_macro2::TokenStream;
@@ -24,8 +24,7 @@
#[cfg(feature = "extra-traits")]
impl PartialEq for Macro {
fn eq(&self, other: &Self) -> bool {
- self.path == other.path
- && self.bang_token == other.bang_token
+ self.path == other.path && self.bang_token == other.bang_token
&& TokenTreeHelper(&self.tokens) == TokenTreeHelper(&other.tokens)
}
}
@@ -33,7 +32,8 @@
#[cfg(feature = "extra-traits")]
impl Hash for Macro {
fn hash<H>(&self, state: &mut H)
- where H: Hasher
+ where
+ H: Hasher,
{
self.path.hash(state);
self.bang_token.hash(state);
@@ -65,10 +65,10 @@
match (&self.0.kind, &other.0.kind) {
(&TokenNode::Group(d1, ref s1), &TokenNode::Group(d2, ref s2)) => {
match (d1, d2) {
- (Delimiter::Parenthesis, Delimiter::Parenthesis) |
- (Delimiter::Brace, Delimiter::Brace) |
- (Delimiter::Bracket, Delimiter::Bracket) |
- (Delimiter::None, Delimiter::None) => {}
+ (Delimiter::Parenthesis, Delimiter::Parenthesis)
+ | (Delimiter::Brace, Delimiter::Brace)
+ | (Delimiter::Bracket, Delimiter::Bracket)
+ | (Delimiter::None, Delimiter::None) => {}
_ => return false,
}
@@ -81,24 +81,21 @@
None => return false,
};
if TokenTreeHelper(&item1) != TokenTreeHelper(&item2) {
- return false
+ return false;
}
}
s2.next().is_none()
}
(&TokenNode::Op(o1, k1), &TokenNode::Op(o2, k2)) => {
o1 == o2 && match (k1, k2) {
- (Spacing::Alone, Spacing::Alone) |
- (Spacing::Joint, Spacing::Joint) => true,
+ (Spacing::Alone, Spacing::Alone) | (Spacing::Joint, Spacing::Joint) => true,
_ => false,
}
}
(&TokenNode::Literal(ref l1), &TokenNode::Literal(ref l2)) => {
l1.to_string() == l2.to_string()
}
- (&TokenNode::Term(ref s1), &TokenNode::Term(ref s2)) => {
- s1.as_str() == s2.as_str()
- }
+ (&TokenNode::Term(ref s1), &TokenNode::Term(ref s2)) => s1.as_str() == s2.as_str(),
_ => false,
}
}
@@ -176,7 +173,7 @@
use proc_macro2::{TokenNode, TokenTree};
use synom::Synom;
use cursor::Cursor;
- use {PResult, parse_error};
+ use {parse_error, PResult};
impl Synom for Macro {
named!(parse -> Self, do_parse!(
@@ -193,9 +190,13 @@
pub fn parse_tt_delimited(input: Cursor) -> PResult<TokenTree> {
match input.token_tree() {
- Some((rest, token @ TokenTree { kind: TokenNode::Group(..), .. })) => {
- Ok((rest, token))
- }
+ Some((
+ rest,
+ token @ TokenTree {
+ kind: TokenNode::Group(..),
+ ..
+ },
+ )) => Ok((rest, token)),
_ => parse_error(),
}
}
@@ -204,7 +205,7 @@
#[cfg(feature = "printing")]
mod printing {
use super::*;
- use quote::{Tokens, ToTokens};
+ use quote::{ToTokens, Tokens};
impl ToTokens for Macro {
fn to_tokens(&self, tokens: &mut Tokens) {
diff --git a/src/op.rs b/src/op.rs
index b5a86cc..93c6073 100644
--- a/src/op.rs
+++ b/src/op.rs
@@ -154,7 +154,7 @@
#[cfg(feature = "printing")]
mod printing {
use super::*;
- use quote::{Tokens, ToTokens};
+ use quote::{ToTokens, Tokens};
impl ToTokens for BinOp {
fn to_tokens(&self, tokens: &mut Tokens) {
diff --git a/src/parsers.rs b/src/parsers.rs
index ae17365..8ca6dc7 100644
--- a/src/parsers.rs
+++ b/src/parsers.rs
@@ -1,5 +1,5 @@
use cursor::Cursor;
-use error::{PResult, parse_error};
+use error::{parse_error, PResult};
/// Define a function from a parser combination.
///
@@ -421,7 +421,6 @@
};
}
-
/// Produce the given value without parsing anything. Useful as an argument to
/// `switch!`.
///
diff --git a/src/token.rs b/src/token.rs
index 3ad1f2b..cfff6f6 100644
--- a/src/token.rs
+++ b/src/token.rs
@@ -462,10 +462,10 @@
#[cfg(feature = "parsing")]
mod parsing {
- use proc_macro2::{Span, Delimiter, Spacing};
+ use proc_macro2::{Delimiter, Spacing, Span};
use cursor::Cursor;
- use {PResult, parse_error};
+ use {parse_error, PResult};
pub trait FromSpans: Sized {
fn from_spans(spans: &[Span]) -> Self;
@@ -489,11 +489,9 @@
}
}
- pub fn op<'a, T, R>(s: &str,
- mut tokens: Cursor<'a>,
- new: fn(T) -> R)
- -> PResult<'a, R>
- where T: FromSpans,
+ pub fn op<'a, T, R>(s: &str, mut tokens: Cursor<'a>, new: fn(T) -> R) -> PResult<'a, R>
+ where
+ T: FromSpans,
{
let mut spans = [Span::default(); 3];
assert!(s.len() <= spans.len());
@@ -511,17 +509,13 @@
*slot = span;
tokens = rest;
}
- _ => return parse_error()
+ _ => return parse_error(),
}
}
Ok((tokens, new(T::from_spans(&spans))))
}
- pub fn sym<'a, T>(sym: &str,
- tokens: Cursor<'a>,
- new: fn(Span) -> T)
- -> PResult<'a, T>
- {
+ pub fn sym<'a, T>(sym: &str, tokens: Cursor<'a>, new: fn(Span) -> T) -> PResult<'a, T> {
if let Some((rest, span, s)) = tokens.word() {
if s.as_str() == sym {
return Ok((rest, new(span)));
@@ -530,12 +524,14 @@
parse_error()
}
- pub fn delim<'a, F, R, T>(delim: &str,
- tokens: Cursor<'a>,
- new: fn(Span) -> T,
- f: F)
- -> PResult<'a, (R, T)>
- where F: FnOnce(Cursor) -> PResult<R>
+ pub fn delim<'a, F, R, T>(
+ delim: &str,
+ tokens: Cursor<'a>,
+ new: fn(Span) -> T,
+ f: F,
+ ) -> PResult<'a, (R, T)>
+ where
+ F: FnOnce(Cursor) -> PResult<R>,
{
// NOTE: We should support none-delimited sequences here.
let delim = match delim {
@@ -562,7 +558,7 @@
#[cfg(feature = "printing")]
mod printing {
- use proc_macro2::{Span, TokenTree, TokenNode, Spacing, Term};
+ use proc_macro2::{Spacing, Span, Term, TokenNode, TokenTree};
use quote::Tokens;
pub fn op(s: &str, spans: &[Span], tokens: &mut Tokens) {
@@ -593,7 +589,8 @@
}
pub fn delim<F>(s: &str, span: &Span, tokens: &mut Tokens, f: F)
- where F: FnOnce(&mut Tokens)
+ where
+ F: FnOnce(&mut Tokens),
{
tokens.append_delimited(s, *span, f)
}
diff --git a/src/ty.rs b/src/ty.rs
index 6a9f314..201b257 100644
--- a/src/ty.rs
+++ b/src/ty.rs
@@ -125,7 +125,8 @@
pub struct PathTokens<'a>(pub &'a Option<QSelf>, pub &'a Path);
impl<T> From<T> for Path
- where T: Into<PathSegment>
+where
+ T: Into<PathSegment>,
{
fn from(segment: T) -> Self {
Path {
@@ -152,7 +153,8 @@
}
impl<T> From<T> for PathSegment
- where T: Into<Ident>
+where
+ T: Into<Ident>,
{
fn from(ident: T) -> Self {
PathSegment {
@@ -229,7 +231,6 @@
}
}
-
ast_struct! {
/// A path like `Foo(A,B) -> C`
pub struct ParenthesizedGenericArguments {
@@ -845,7 +846,7 @@
#[cfg(feature = "printing")]
mod printing {
use super::*;
- use quote::{Tokens, ToTokens};
+ use quote::{ToTokens, Tokens};
impl ToTokens for TypeSlice {
fn to_tokens(&self, tokens: &mut Tokens) {
@@ -1046,7 +1047,7 @@
_ => token::Brace::default().surround(tokens, |tokens| {
e.to_tokens(tokens);
}),
- }
+ },
}
}
}