Format with rustfmt 0.99.2
diff --git a/src/expr.rs b/src/expr.rs
index b7695d7..eaae23f 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -1068,8 +1068,22 @@
BinOp::BitAnd(_) => Precedence::BitAnd,
BinOp::BitOr(_) => Precedence::BitOr,
BinOp::Shl(_) | BinOp::Shr(_) => Precedence::Shift,
- BinOp::Eq(_) | BinOp::Lt(_) | BinOp::Le(_) | BinOp::Ne(_) | BinOp::Ge(_) | BinOp::Gt(_) => Precedence::Compare,
- BinOp::AddEq(_) | BinOp::SubEq(_) | BinOp::MulEq(_) | BinOp::DivEq(_) | BinOp::RemEq(_) | BinOp::BitXorEq(_) | BinOp::BitAndEq(_) | BinOp::BitOrEq(_) | BinOp::ShlEq(_) | BinOp::ShrEq(_) => Precedence::Assign,
+ BinOp::Eq(_)
+ | BinOp::Lt(_)
+ | BinOp::Le(_)
+ | BinOp::Ne(_)
+ | BinOp::Ge(_)
+ | BinOp::Gt(_) => Precedence::Compare,
+ BinOp::AddEq(_)
+ | BinOp::SubEq(_)
+ | BinOp::MulEq(_)
+ | BinOp::DivEq(_)
+ | BinOp::RemEq(_)
+ | BinOp::BitXorEq(_)
+ | BinOp::BitAndEq(_)
+ | BinOp::BitOrEq(_)
+ | BinOp::ShlEq(_)
+ | BinOp::ShrEq(_) => Precedence::Assign,
}
}
}
@@ -1086,9 +1100,19 @@
}
#[cfg(feature = "full")]
- fn parse_expr(input: ParseStream, mut lhs: Expr, allow_struct: AllowStruct, base: Precedence) -> Result<Expr> {
+ fn parse_expr(
+ input: ParseStream,
+ mut lhs: Expr,
+ allow_struct: AllowStruct,
+ base: Precedence,
+ ) -> Result<Expr> {
loop {
- if input.fork().parse::<BinOp>().ok().map_or(false, |op| Precedence::of(&op) >= base) {
+ if input
+ .fork()
+ .parse::<BinOp>()
+ .ok()
+ .map_or(false, |op| Precedence::of(&op) >= base)
+ {
let op: BinOp = input.parse()?;
let precedence = Precedence::of(&op);
let mut rhs = unary_expr(input, allow_struct)?;
@@ -1106,7 +1130,11 @@
op: op,
right: Box::new(rhs),
});
- } else if Precedence::Assign >= base && input.peek(Token![=]) && !input.peek(Token![==]) && !input.peek(Token![=>]) {
+ } else if Precedence::Assign >= base
+ && input.peek(Token![=])
+ && !input.peek(Token![==])
+ && !input.peek(Token![=>])
+ {
let eq_token: Token![=] = input.parse()?;
let mut rhs = unary_expr(input, allow_struct)?;
loop {
@@ -1192,9 +1220,19 @@
}
#[cfg(not(feature = "full"))]
- fn parse_expr(input: ParseStream, mut lhs: Expr, allow_struct: AllowStruct, base: Precedence) -> Result<Expr> {
+ fn parse_expr(
+ input: ParseStream,
+ mut lhs: Expr,
+ allow_struct: AllowStruct,
+ base: Precedence,
+ ) -> Result<Expr> {
loop {
- if input.fork().parse::<BinOp>().ok().map_or(false, |op| Precedence::of(&op) >= base) {
+ if input
+ .fork()
+ .parse::<BinOp>()
+ .ok()
+ .map_or(false, |op| Precedence::of(&op) >= base)
+ {
let op: BinOp = input.parse()?;
let precedence = Precedence::of(&op);
let mut rhs = unary_expr(input, allow_struct)?;
@@ -1245,10 +1283,7 @@
}
// Parse an arbitrary expression.
- fn ambiguous_expr(
- input: ParseStream,
- allow_struct: AllowStruct,
- ) -> Result<Expr> {
+ fn ambiguous_expr(input: ParseStream, allow_struct: AllowStruct) -> Result<Expr> {
let lhs = unary_expr(input, allow_struct)?;
parse_expr(input, lhs, allow_struct, Precedence::Any)
}
@@ -1258,10 +1293,7 @@
// &mut <trailer>
// box <trailer>
#[cfg(feature = "full")]
- fn unary_expr(
- input: ParseStream,
- allow_struct: AllowStruct,
- ) -> Result<Expr> {
+ fn unary_expr(input: ParseStream, allow_struct: AllowStruct) -> Result<Expr> {
let ahead = input.fork();
ahead.call(Attribute::parse_outer)?;
if ahead.peek(Token![&])
@@ -1298,10 +1330,7 @@
// XXX: This duplication is ugly
#[cfg(not(feature = "full"))]
- fn unary_expr(
- input: ParseStream,
- allow_struct: AllowStruct,
- ) -> Result<Expr> {
+ fn unary_expr(input: ParseStream, allow_struct: AllowStruct) -> Result<Expr> {
let ahead = input.fork();
ahead.call(Attribute::parse_outer)?;
if ahead.peek(Token![*]) || ahead.peek(Token![!]) || ahead.peek(Token![-]) {
@@ -1336,10 +1365,7 @@
// <atom> [ <expr> ] ...
// <atom> ? ...
#[cfg(feature = "full")]
- fn trailer_expr(
- input: ParseStream,
- allow_struct: AllowStruct,
- ) -> Result<Expr> {
+ fn trailer_expr(input: ParseStream, allow_struct: AllowStruct) -> Result<Expr> {
let mut e = atom_expr(input, allow_struct)?;
let mut attrs = e.replace_attrs(Vec::new());
@@ -1439,10 +1465,7 @@
// XXX: Duplication == ugly
#[cfg(not(feature = "full"))]
- fn trailer_expr(
- input: ParseStream,
- allow_struct: AllowStruct,
- ) -> Result<Expr> {
+ fn trailer_expr(input: ParseStream, allow_struct: AllowStruct) -> Result<Expr> {
let mut e = atom_expr(input, allow_struct)?;
loop {
@@ -1567,11 +1590,11 @@
return Err(input.error("expected loop or block expression"));
};
match expr {
- Expr::WhileLet(ExprWhileLet { ref mut label, .. }) |
- Expr::While(ExprWhile { ref mut label, .. }) |
- Expr::ForLoop(ExprForLoop { ref mut label, .. }) |
- Expr::Loop(ExprLoop { ref mut label, .. }) |
- Expr::Block(ExprBlock { ref mut label, .. }) => *label = Some(the_label),
+ Expr::WhileLet(ExprWhileLet { ref mut label, .. })
+ | Expr::While(ExprWhile { ref mut label, .. })
+ | Expr::ForLoop(ExprForLoop { ref mut label, .. })
+ | Expr::Loop(ExprLoop { ref mut label, .. })
+ | Expr::Block(ExprBlock { ref mut label, .. }) => *label = Some(the_label),
_ => unreachable!(),
}
expr
@@ -1827,10 +1850,7 @@
let mut pats = Punctuated::new();
let value: Pat = input.parse()?;
pats.push_value(value);
- while input.peek(Token![|])
- && !input.peek(Token![||])
- && !input.peek(Token![|=])
- {
+ while input.peek(Token![|]) && !input.peek(Token![||]) && !input.peek(Token![|=]) {
let punct = input.parse()?;
pats.push_punct(punct);
let value: Pat = input.parse()?;
@@ -2249,7 +2269,11 @@
}
#[cfg(feature = "full")]
- fn expr_struct_helper(input: ParseStream, outer_attrs: Vec<Attribute>, path: Path) -> Result<ExprStruct> {
+ fn expr_struct_helper(
+ input: ParseStream,
+ outer_attrs: Vec<Attribute>,
+ path: Path,
+ ) -> Result<ExprStruct> {
let content;
let brace_token = braced!(content in input);
let inner_attrs = content.call(Attribute::parse_inner)?;
@@ -2489,8 +2513,9 @@
|| ahead.peek(Token![union]) && ahead.peek2(Ident)
|| ahead.peek(Token![auto]) && ahead.peek2(Token![trait])
|| ahead.peek(Token![trait])
- || ahead.peek(Token![default]) && (ahead.peek2(Token![unsafe]) || ahead.peek2(Token![impl]))
- || ahead.peek(Token![impl])
+ || ahead.peek(Token![default])
+ && (ahead.peek2(Token![unsafe]) || ahead.peek2(Token![impl ]))
+ || ahead.peek(Token![impl ])
|| ahead.peek(Token![macro])
{
input.parse().map(Stmt::Item)
diff --git a/src/item.rs b/src/item.rs
index 349fa05..b061179 100644
--- a/src/item.rs
+++ b/src/item.rs
@@ -1610,7 +1610,8 @@
let mut bounds = Punctuated::new();
if colon_token.is_some() {
- while !input.peek(Token![where]) && !input.peek(Token![=]) && !input.peek(Token![;]) {
+ while !input.peek(Token![where]) && !input.peek(Token![=]) && !input.peek(Token![;])
+ {
if !bounds.is_empty() {
bounds.push_punct(input.parse()?);
}
diff --git a/src/lit.rs b/src/lit.rs
index fc7284e..51ade4b 100644
--- a/src/lit.rs
+++ b/src/lit.rs
@@ -436,26 +436,24 @@
impl Parse for Lit {
fn parse(input: ParseStream) -> Result<Self> {
- input.step_cursor(|cursor| {
- match cursor.literal() {
- Some((lit, rest)) => Ok((Lit::new(lit), rest)),
- _ => match cursor.ident() {
- Some((ident, rest)) => Ok((
- Lit::Bool(LitBool {
- value: if ident == "true" {
- true
- } else if ident == "false" {
- false
- } else {
- return Err(cursor.error("expected literal"));
- },
- span: ident.span(),
- }),
- rest,
- )),
- _ => Err(cursor.error("expected literal"))
- },
- }
+ input.step_cursor(|cursor| match cursor.literal() {
+ Some((lit, rest)) => Ok((Lit::new(lit), rest)),
+ _ => match cursor.ident() {
+ Some((ident, rest)) => Ok((
+ Lit::Bool(LitBool {
+ value: if ident == "true" {
+ true
+ } else if ident == "false" {
+ false
+ } else {
+ return Err(cursor.error("expected literal"));
+ },
+ span: ident.span(),
+ }),
+ rest,
+ )),
+ _ => Err(cursor.error("expected literal")),
+ },
})
}
}
diff --git a/src/path.rs b/src/path.rs
index 4cdf2de..4a63b65 100644
--- a/src/path.rs
+++ b/src/path.rs
@@ -227,10 +227,10 @@
#[cfg(feature = "parsing")]
pub mod parsing {
use super::*;
- use parse::{Parse, ParseStream, Result};
- use synom::ext::IdentExt;
#[cfg(feature = "full")]
use expr;
+ use parse::{Parse, ParseStream, Result};
+ use synom::ext::IdentExt;
impl Parse for Path {
fn parse(input: ParseStream) -> Result<Self> {
diff --git a/tests/test_generics.rs b/tests/test_generics.rs
index aac8d71..d3b33ed 100644
--- a/tests/test_generics.rs
+++ b/tests/test_generics.rs
@@ -112,18 +112,12 @@
fn test_ty_param_bound() {
let tokens = quote!('a);
let expected = TypeParamBound::Lifetime(Lifetime::new("'a", Span::call_site()));
- assert_eq!(
- expected,
- syn::parse2::<TypeParamBound>(tokens).unwrap()
- );
+ assert_eq!(expected, syn::parse2::<TypeParamBound>(tokens).unwrap());
let tokens = quote!('_);
println!("{:?}", tokens);
let expected = TypeParamBound::Lifetime(Lifetime::new("'_", Span::call_site()));
- assert_eq!(
- expected,
- syn::parse2::<TypeParamBound>(tokens).unwrap()
- );
+ assert_eq!(expected, syn::parse2::<TypeParamBound>(tokens).unwrap());
let tokens = quote!(Debug);
let expected = TypeParamBound::Trait(TraitBound {
@@ -132,10 +126,7 @@
lifetimes: None,
path: ident("Debug").into(),
});
- assert_eq!(
- expected,
- syn::parse2::<TypeParamBound>(tokens).unwrap()
- );
+ assert_eq!(expected, syn::parse2::<TypeParamBound>(tokens).unwrap());
let tokens = quote!(?Sized);
let expected = TypeParamBound::Trait(TraitBound {
@@ -144,10 +135,7 @@
lifetimes: None,
path: ident("Sized").into(),
});
- assert_eq!(
- expected,
- syn::parse2::<TypeParamBound>(tokens).unwrap()
- );
+ assert_eq!(expected, syn::parse2::<TypeParamBound>(tokens).unwrap());
}
#[test]