Repository: Marwes/combine (language: rust)

Issue:
`any()` should not produce ConsumedErr
Maybe it's a simple clerical error. `any()` should behave the same way as `satisfy(|_| true)`.
https://github.com/Marwes/combine/blob/75209e894f084f2bd0a0742b65c08bb7598f090b/src/combinator.rs#L48
https://github.com/Marwes/combine/blob/75209e894f084f2bd0a0742b65c08bb7598f090b/src/combinator.rs#L94


Discussion / hints:

Fix patch:
diff --git a/benches/http.rs b/benches/http.rs
index b73743a5..e68ad040 100644
--- a/benches/http.rs
+++ b/benches/http.rs
@@ -42,7 +42,11 @@ fn is_http_version(c: u8) -> bool {
 
 fn parse_http_request(input: &[u8]) -> Result<((Request, Vec<Header>), &[u8]), ParseError<&[u8]>> {
     // Making a closure, because parser instances cannot be reused
-    let end_of_line = || (token(b'\r'), token(b'\n')).map(|_| b'\r').or(token(b'\n'));
+    let end_of_line = || {
+        (token(b'\r'), token(b'\n'))
+            .map(|_| b'\r')
+            .or(token(b'\n'))
+    };
 
     let http_version = range(&b"HTTP/"[..]).with(take_while1(is_http_version));
 
@@ -52,12 +56,12 @@ fn parse_http_request(input: &[u8]) -> Result<((Request, Vec<Header>), &[u8]), P
                         take_while1(is_space),
                         http_version)
             .map(|(method, _, uri, _, version)| {
-                Request {
-                    method: method,
-                    uri: uri,
-                    version: version,
-                }
-            });
+                     Request {
+                         method: method,
+                         uri: uri,
+                         version: version,
+                     }
+                 });
 
 
     let message_header_line = (take_while1(is_horizontal_space),
diff --git a/src/char.rs b/src/char.rs
index f003bad3..8b563809 100644
--- a/src/char.rs
+++ b/src/char.rs
@@ -187,7 +187,9 @@ impl<I> Parser for Str<I>
     type Output = &'static str;
     #[inline]
     fn parse_lazy(&mut self, input: Self::Input) -> ConsumedResult<Self::Output, Self::Input> {
-        tokens(eq, self.0.into(), self.0.chars()).parse_lazy(input).map(|_| self.0)
+        tokens(eq, self.0.into(), self.0.chars())
+            .parse_lazy(input)
+            .map(|_| self.0)
     }
     fn add_error(&mut self, errors: &mut ParseError<Self::Input>) {
         tokens(eq, self.0.into(), self.0.chars()).add_error(errors)
@@ -224,7 +226,9 @@ impl<C, I> Parser for StrCmp<C, I>
     type Output = &'static str;
     #[inline]
     fn parse_lazy(&mut self, input: Self::Input) -> ConsumedResult<Self::Output, Self::Input> {
-        tokens(&mut self.1, self.0.into(), self.0.chars()).parse_lazy(input).map(|_| self.0)
+        tokens(&mut self.1, self.0.into(), self.0.chars())
+            .parse_lazy(input)
+            .map(|_| self.0)
     }
     fn add_error(&mut self, errors: &mut ParseError<Self::Input>) {
         tokens(&mut self.1, self.0.into(), self.0.chars()).add_error(errors)
@@ -272,10 +276,7 @@ mod tests {
         let result = string("a").parse(State::new("b"));
         assert!(result.is_err());
         assert_eq!(result.unwrap_err().position,
-                   SourcePosition {
-                       line: 1,
-                       column: 1,
-                   });
+                   SourcePosition { line: 1, column: 1 });
     }
 
     #[test]
@@ -283,10 +284,7 @@ mod tests {
         let result = string("abc").parse(State::new("bc"));
         assert_eq!(result,
                    Err(ParseError {
-                           position: SourcePosition {
-                               line: 1,
-                               column: 1,
-                           },
+                           position: SourcePosition { line: 1, column: 1 },
                            errors: vec![Error::Unexpected('b'.into()),
                                         Error::Expected("abc".into())],
                        }));
diff --git a/src/combinator.rs b/src/combinator.rs
index 57db7825..3aa5c10b 100644
--- a/src/combinator.rs
+++ b/src/combinator.rs
@@ -45,7 +45,7 @@ impl<I> Parser for Any<I>
         let position = input.position();
         match input.uncons() {
             Ok(x) => ConsumedOk((x, input)),
-            Err(err) => ConsumedErr(ParseError::new(position, err)),
+            Err(err) => EmptyErr(ParseError::new(position, err)),
         }
     }
 }
@@ -206,7 +206,9 @@ impl<I> Parser for Token<I>
         satisfy_impl(input, |c| if c == self.c { Some(c) } else { None })
     }
     fn add_error(&mut self, error: &mut ParseError<Self::Input>) {
-        error.errors.push(Error::Expected(Info::Token(self.c.clone())));
+        error
+            .errors
+            .push(Error::Expected(Info::Token(self.c.clone())));
     }
 }
 
@@ -260,7 +262,7 @@ impl<C, T, I> Parser for Tokens<C, T, I>
                     if !(self.cmp)(c, other.clone()) {
                         return if consumed {
                                    let errors = vec![Error::Unexpected(Info::Token(other)),
-                                              Error::Expected(self.expected.clone())];
+                                                     Error::Expected(self.expected.clone())];
                                    let error = ParseError::from_errors(start, errors);
                                    ConsumedErr(error)
                                } else {
@@ -272,13 +274,13 @@ impl<C, T, I> Parser for Tokens<C, T, I>
                 }
                 Err(error) => {
                     return error.combine_consumed(|mut error| {
-                        error.position = start;
-                        if consumed {
-                            ConsumedErr(error)
-                        } else {
-                            EmptyErr(error)
-                        }
-                    })
+                                                      error.position = start;
+                                                      if consumed {
+                                                          ConsumedErr(error)
+                                                      } else {
+                                                          EmptyErr(error)
+                                                      }
+                                                  })
                 }
             }
         }
@@ -430,13 +432,7 @@ impl<T, I> Parser for OneOf<T, I>
 
     #[inline]
     fn parse_lazy(&mut self, input: I) -> ConsumedResult<I::Item, I> {
-        satisfy(|c| {
-                    self.tokens
-                        .clone()
-                        .into_iter()
-                        .any(|t| t == c)
-                })
-                .parse_lazy(input)
+        satisfy(|c| self.tokens.clone().into_iter().any(|t| t == c)).parse_lazy(input)
     }
 
     fn add_error(&mut self, errors: &mut ParseError<Self::Input>) {
@@ -488,13 +484,7 @@ impl<T, I> Parser for NoneOf<T, I>
 
     #[inline]
     fn parse_lazy(&mut self, input: I) -> ConsumedResult<I::Item, I> {
-        satisfy(|c| {
-                    self.tokens
-                        .clone()
-                        .into_iter()
-                        .all(|t| t != c)
-                })
-                .parse_lazy(input)
+        satisfy(|c| self.tokens.clone().into_iter().all(|t| t != c)).parse_lazy(input)
     }
 }
 
@@ -1080,14 +1070,12 @@ impl<F, P, S> Parser for SepBy1<F, P, S>
         let (first, rest) = ctry!(self.parser.parse_lazy(input.clone()));
 
         rest.combine_consumed(move |input| {
-            let rest = (&mut self.separator).with(&mut self.parser);
-            let mut iter = Iter::new(rest, input);
-            let result = Some(first)
-                .into_iter()
-                .chain(iter.by_ref())
-                .collect();
-            iter.into_result_fast(result)
-        })
+                                  let rest = (&mut self.separator).with(&mut self.parser);
+                                  let mut iter = Iter::new(rest, input);
+                                  let result =
+                                      Some(first).into_iter().chain(iter.by_ref()).collect();
+                                  iter.into_result_fast(result)
+                              })
     }
 
     fn add_error(&mut self, errors: &mut ParseError<Self::Input>) {
@@ -1219,7 +1207,10 @@ impl<F, P, S> Parser for SepEndBy1<F, P, S>
             // `iter` yields Option<P::Output>, by using flat map we make sure that we stop
             // iterating once a None element is received, i.e `self.parser` did not parse
             // successfully
-            let result = Some(first).into_iter().chain(iter.by_ref().flat_map(|x| x)).collect();
+            let result = Some(first)
+                .into_iter()
+                .chain(iter.by_ref().flat_map(|x| x))
+                .collect();
             iter.into_result_fast(result)
         })
     }
@@ -1419,7 +1410,9 @@ impl<I, P, Op> Parser for Chainl1<P, Op>
     fn parse_lazy(&mut self, input: I) -> ConsumedResult<P::Output, I> {
         let (mut l, mut input) = ctry!(self.0.parse_lazy(input));
         loop {
-            match (&mut self.1, &mut self.0).parse_lazy(input.clone().into_inner()).into() {
+            match (&mut self.1, &mut self.0)
+                      .parse_lazy(input.clone().into_inner())
+                      .into() {
                 Ok(((op, r), rest)) => {
                     l = op(l, r);
                     input = input.merge(rest);
@@ -1687,7 +1680,7 @@ impl<I, P> Parser for Message<P>
             ConsumedErr(mut err) => {
                 err.add_error(Error::Message(self.1.clone()));
                 ConsumedErr(err)
-            },
+            }
 
             // The message will be added in `add_error`
             EmptyErr(err) => EmptyErr(err),
@@ -1893,12 +1886,14 @@ impl<P> Parser for Expected<P>
     fn parse_stream(&mut self, input: Self::Input) -> ParseResult<Self::Output, Self::Input> {
         // add_error is only called on unconsumed inputs but we want this expected message to always
         // replace the ones always present in the ParseError
-        self.0.parse_stream(input).map_err(|errors| {
-                                               errors.map(|mut errors| {
-                                                              errors.set_expected(self.1.clone());
-                                                              errors
-                                                          })
-                                           })
+        self.0
+            .parse_stream(input)
+            .map_err(|errors| {
+                         errors.map(|mut errors| {
+                                        errors.set_expected(self.1.clone());
+                                        errors
+                                    })
+                     })
     }
 
     #[inline]
@@ -1912,15 +1907,17 @@ impl<P> Parser for Expected<P>
         // Replace all expected errors that where added from the previous add_error
         // with this expected error
         let mut i = 0;
-        errors.errors.retain(|e| if i < start {
-                                 i += 1;
-                                 true
-                             } else {
-                                 match *e {
-                                     Error::Expected(_) => false,
-                                     _ => true,
-                                 }
-                             });
+        errors
+            .errors
+            .retain(|e| if i < start {
+                        i += 1;
+                        true
+                    } else {
+                        match *e {
+                            Error::Expected(_) => false,
+                            _ => true,
+                        }
+                    });
         errors.add_error(Error::Expected(self.1.clone()));
     }
 }
@@ -2155,7 +2152,10 @@ mod tests {
     /// The expected combinator should retain only errors that are not `Expected`
     #[test]
     fn expected_retain_errors() {
-        let mut parser = digit().message("message").expected("N/A").expected("my expected digit");
+        let mut parser = digit()
+            .message("message")
+            .expected("N/A")
+            .expected("my expected digit");
         assert_eq!(parser.parse(State::new("a")),
                    Err(ParseError {
                            position: <char as Positioner>::start(),
@@ -2186,7 +2186,9 @@ mod tests {
     fn token_clone_but_not_copy() {
         // Verify we can use token() with a StreamSlice with an item type that is Clone but not
         // Copy.
-        let input = &[CloneOnly { s: "x".to_string() }, CloneOnly { s: "y".to_string() }][..];
+        let input = &[CloneOnly { s: "x".to_string() },
+                      CloneOnly { s: "y".to_string() }]
+                         [..];
         let result = token(CloneOnly { s: "x".to_string() }).parse(input);
         assert_eq!(result,
                    Ok((CloneOnly { s: "x".to_string() }, &[CloneOnly { s: "y".to_string() }][..])));
@@ -2198,31 +2200,35 @@ mod tests {
         // parse_stream correctly on either side
         let input = "hi";
 
-        let mut ok        = char('h').message("not expected");
-        let mut empty0    = char('o').message("expected message");
-        let mut empty1    = char('o').message("expected message").map(|x| x);
-        let mut empty2    = char('o').map(|x| x).message("expected message");
+        let mut ok = char('h').message("not expected");
+        let mut empty0 = char('o').message("expected message");
+        let mut empty1 = char('o').message("expected message").map(|x| x);
+        let mut empty2 = char('o').map(|x| x).message("expected message");
         let mut consumed0 = char('h').with(char('o')).message("expected message");
-        let mut consumed1 = char('h').with(char('o')).message("expected message").map(|x| x);
-        let mut consumed2 = char('h').with(char('o')).map(|x| x).message("expected message");
+        let mut consumed1 = char('h')
+            .with(char('o'))
+            .message("expected message")
+            .map(|x| x);
+        let mut consumed2 = char('h')
+            .with(char('o'))
+            .map(|x| x)
+            .message("expected message");
 
         assert!(ok.parse(State::new(input)).is_ok());
 
-        let empty_expected =
-            Err(ParseError {
-               position: SourcePosition { line: 1, column: 1 },
-               errors: vec![Error::Unexpected('h'.into()),
-                            Error::Expected('o'.into()),
-                            Error::Message("expected message".into())],
-            });
-
-        let consumed_expected =
-            Err(ParseError {
-               position: SourcePosition { line: 1, column: 2 },
-               errors: vec![Error::Unexpected('i'.into()),
-                            Error::Expected('o'.into()),
-                            Error::Message("expected message".into())],
-            });
+        let empty_expected = Err(ParseError {
+                                     position: SourcePosition { line: 1, column: 1 },
+                                     errors: vec![Error::Unexpected('h'.into()),
+                                                  Error::Expected('o'.into()),
+                                                  Error::Message("expected message".into())],
+                                 });
+
+        let consumed_expected = Err(ParseError {
+                                        position: SourcePosition { line: 1, column: 2 },
+                                        errors: vec![Error::Unexpected('i'.into()),
+                                                     Error::Expected('o'.into()),
+                                                     Error::Message("expected message".into())],
+                                    });
 
         assert_eq!(empty0.parse(State::new(input)), empty_expected);
         assert_eq!(empty1.parse(State::new(input)), empty_expected);
@@ -2232,4 +2238,9 @@ mod tests {
         assert_eq!(consumed1.parse(State::new(input)), consumed_expected);
         assert_eq!(consumed2.parse(State::new(input)), consumed_expected);
     }
+
+    #[test]
+    fn issue_99() {
+        assert!(any().map(|_| ()).or(eof()).parse("").is_ok());
+    }
 }
diff --git a/src/lib.rs b/src/lib.rs
index 8a3651bc..23738e1a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -217,7 +217,9 @@ mod tests {
     fn integer<'a, I>(input: I) -> ParseResult<i64, I>
         where I: Stream<Item = char>
     {
-        let (s, input) = try!(many1::<String, _>(digit()).expected("integer").parse_stream(input));
+        let (s, input) = try!(many1::<String, _>(digit())
+                                  .expected("integer")
+                                  .parse_stream(input));
         let mut n = 0;
         for c in s.chars() {
             n = n * 10 + (c as i64 - '0' as i64);
@@ -238,18 +240,18 @@ mod tests {
     }
     #[test]
     fn iterator() {
-        let result =
-            parser(integer).parse(from_iter("123".chars())).map(|(i, mut input)| {
-                                                                    (i, input.uncons().is_err())
-                                                                });
+        let result = parser(integer)
+            .parse(from_iter("123".chars()))
+            .map(|(i, mut input)| (i, input.uncons().is_err()));
         assert_eq!(result, Ok((123i64, true)));
     }
     #[test]
     fn field() {
         let word = || many(alpha_num());
         let spaces = spaces();
-        let c_decl =
-            (word(), spaces.clone(), char(':'), spaces, word()).map(|t| (t.0, t.4)).parse("x: int");
+        let c_decl = (word(), spaces.clone(), char(':'), spaces, word())
+            .map(|t| (t.0, t.4))
+            .parse("x: int");
         assert_eq!(c_decl, Ok((("x".to_string(), "int".to_string()), "")));
     }
     #[test]
@@ -257,13 +259,11 @@ mod tests {
         let source = r"
 123
 ";
-        let result =
-            (spaces(), parser(integer), spaces()).map(|t| t.1).parse_stream(State::new(source));
+        let result = (spaces(), parser(integer), spaces())
+            .map(|t| t.1)
+            .parse_stream(State::new(source));
         let state = Consumed::Consumed(State {
-                                           position: SourcePosition {
-                                               line: 3,
-                                               column: 1,
-                                           },
+                                           position: SourcePosition { line: 3, column: 1 },
                                            input: "",
                                        });
         assert_eq!(result, Ok((123i64, state)));
@@ -287,7 +287,8 @@ mod tests {
         let array = between(char('['), char(']'), sep_by(parser(expr), char(','))).expected("[");
         let paren_expr = between(char('('), char(')'), parser(term)).expected("(");
         let spaces = spaces();
-        spaces.clone()
+        spaces
+            .clone()
             .with(word.map(Expr::Id)
                       .or(integer.map(Expr::Int))
                       .or(array.map(Expr::Array))
@@ -312,10 +313,7 @@ mod tests {
 ";
         let result = parser(expr).parse(State::new(input));
         let err = ParseError {
-            position: SourcePosition {
-                line: 2,
-                column: 1,
-            },
+            position: SourcePosition { line: 2, column: 1 },
             errors: vec![Error::Unexpected(','.into()),
                          Error::Expected("integer".into()),
                          Error::Expected("identifier".into()),
@@ -369,49 +367,36 @@ mod tests {
     }
     #[test]
     fn error_position() {
-        let mut p = string("let").skip(parser(follow)).map(|x| x.to_string()).or(many1(digit()));
+        let mut p = string("let")
+            .skip(parser(follow))
+            .map(|x| x.to_string())
+            .or(many1(digit()));
         match p.parse(State::new("le123")) {
             Ok(_) => assert!(false),
-            Err(err) => {
-                assert_eq!(err.position,
-                           SourcePosition {
-                               line: 1,
-                               column: 1,
-                           })
-            }
+            Err(err) => assert_eq!(err.position, SourcePosition { line: 1, column: 1 }),
         }
         match p.parse(State::new("let1")) {
             Ok(_) => assert!(false),
-            Err(err) => {
-                assert_eq!(err.position,
-                           SourcePosition {
-                               line: 1,
-                               column: 4,
-                           })
-            }
+            Err(err) => assert_eq!(err.position, SourcePosition { line: 1, column: 4 }),
         }
     }
 
     #[test]
     fn sep_by_error_consume() {
         let mut p = sep_by::<Vec<_>, _, _>(string("abc"), char(','));
-        let err = p.parse(State::new("ab,abc")).map(|x| format!("{:?}", x)).unwrap_err();
-        assert_eq!(err.position,
-                   SourcePosition {
-                       line: 1,
-                       column: 1,
-                   });
+        let err = p.parse(State::new("ab,abc"))
+            .map(|x| format!("{:?}", x))
+            .unwrap_err();
+        assert_eq!(err.position, SourcePosition { line: 1, column: 1 });
     }
 
     #[test]
     fn optional_error_consume() {
         let mut p = optional(string("abc"));
-        let err = p.parse(State::new("ab")).map(|x| format!("{:?}", x)).unwrap_err();
-        assert_eq!(err.position,
-                   SourcePosition {
-                       line: 1,
-                       column: 1,
-                   });
+        let err = p.parse(State::new("ab"))
+            .map(|x| format!("{:?}", x))
+            .unwrap_err();
+        assert_eq!(err.position, SourcePosition { line: 1, column: 1 });
     }
     #[test]
     fn chainl1_error_consume() {
@@ -428,11 +413,7 @@ mod tests {
         let result = p.parse(State::new("[1][2][]"));
         assert!(result.is_err(), format!("{:?}", result));
         let error = result.map(|x| format!("{:?}", x)).unwrap_err();
-        assert_eq!(error.position,
-                   SourcePosition {
-                       line: 1,
-                       column: 8,
-                   });
+        assert_eq!(error.position, SourcePosition { line: 1, column: 8 });
     }
 
     #[test]
@@ -553,11 +534,11 @@ mod tests {
         // Test that the fresh ExtractedError is Display, so that the internal errors can be
         // inspected by consuming code; and that the ExtractedError can be coerced to StdError.
         let _ = result.map_err(|err| {
-            let s = format!("{}", err);
-            assert!(s.starts_with("Parse error at 0"));
-            assert!(s.contains("Expected"));
-            let err: Box<StdError> = Box::new(err);
-            err
-        });
+                                   let s = format!("{}", err);
+                                   assert!(s.starts_with("Parse error at 0"));
+                                   assert!(s.contains("Expected"));
+                                   let err: Box<StdError> = Box::new(err);
+                                   err
+                               });
     }
 }
diff --git a/src/primitives.rs b/src/primitives.rs
index 983bdfab..8ed8e53c 100644
--- a/src/primitives.rs
+++ b/src/primitives.rs
@@ -7,8 +7,8 @@ use std::io::{Read, Bytes};
 
 use self::FastResult::*;
 
-use combinator::{AndThen, and_then, Expected, expected, FlatMap, flat_map, Iter, Map, map, Message,
-                 message, Or, or, Skip, skip, Then, then, With, with};
+use combinator::{AndThen, and_then, Expected, expected, FlatMap, flat_map, Iter, Map, map,
+                 Message, message, Or, or, Skip, skip, Then, then, With, with};
 
 #[macro_export]
 macro_rules! ctry {
@@ -217,10 +217,12 @@ impl<T, R> Error<T, R> {
         // First print the token that we did not expect
         // There should really just be one unexpected message at this point though we print them
         // all to be safe
-        let unexpected = errors.iter().filter(|e| match **e {
-                                                  Error::Unexpected(_) => true,
-                                                  _ => false,
-                                              });
+        let unexpected = errors
+            .iter()
+            .filter(|e| match **e {
+                        Error::Unexpected(_) => true,
+                        _ => false,
+                    });
         for error in unexpected {
             try!(writeln!(f, "{}", error));
         }
@@ -228,10 +230,12 @@ impl<T, R> Error<T, R> {
         // Then we print out all the things that were expected in a comma separated list
         // 'Expected 'a', 'expression' or 'let'
         let iter = || {
-            errors.iter().filter_map(|e| match *e {
-                                         Error::Expected(ref err) => Some(err),
-                                         _ => None,
-                                     })
+            errors
+                .iter()
+                .filter_map(|e| match *e {
+                                Error::Expected(ref err) => Some(err),
+                                _ => None,
+                            })
         };
         let expected_count = iter().count();
         for (i, message) in iter().enumerate() {
@@ -247,11 +251,13 @@ impl<T, R> Error<T, R> {
             try!(writeln!(f, ""));
         }
         // If there are any generic messages we print them out last
-        let messages = errors.iter().filter(|e| match **e {
-                                                Error::Message(_) |
-                                                Error::Other(_) => true,
-                                                _ => false,
-                                            });
+        let messages = errors
+            .iter()
+            .filter(|e| match **e {
+                        Error::Message(_) |
+                        Error::Other(_) => true,
+                        _ => false,
+                    });
         for error in messages {
             try!(writeln!(f, "{}", error));
         }
@@ -476,10 +482,11 @@ impl<S: StreamOnce> ParseError<S> {
     /// Remvoes all `Expected` errors in `self` and adds `info` instead.
     pub fn set_expected(&mut self, info: Info<S::Item, S::Range>) {
         // Remove all other expected messages
-        self.errors.retain(|e| match *e {
-                               Error::Expected(_) => false,
-                               _ => true,
-                           });
+        self.errors
+            .retain(|e| match *e {
+                        Error::Expected(_) => false,
+                        _ => true,
+                    });
         self.errors.push(Error::Expected(info));
     }
 
@@ -677,10 +684,12 @@ impl<I, E> RangeStream for State<I>
     #[inline]
     fn uncons_range(&mut self, size: usize) -> Result<I::Range, Error<I::Item, I::Range>> {
         let position = &mut self.position;
-        self.input.uncons_range(size).map(|value| {
-                                              value.update(position);
-                                              value
-                                          })
+        self.input
+            .uncons_range(size)
+            .map(|value| {
+                     value.update(position);
+                     value
+                 })
     }
 
     #[inline]
@@ -688,12 +697,13 @@ impl<I, E> RangeStream for State<I>
         where F: FnMut(I::Item) -> bool
     {
         let position = &mut self.position;
-        self.input.uncons_while(|t| if predicate(t.clone()) {
-                                    t.update(position);
-                                    true
-                                } else {
-                                    false
-                                })
+        self.input
+            .uncons_while(|t| if predicate(t.clone()) {
+                              t.update(position);
+                              true
+                          } else {
+                              false
+                          })
     }
 }
 
@@ -735,7 +745,9 @@ pub fn uncons<I>(mut input: I) -> ParseResult<I::Item, I>
     where I: Stream
 {
     let position = input.position();
-    let x = try!(input.uncons().map_err(|err| Consumed::Empty(ParseError::new(position, err))));
+    let x = try!(input
+                     .uncons()
+                     .map_err(|err| Consumed::Empty(ParseError::new(position, err))));
     Ok((x, Consumed::Consumed(input)))
 }
 
@@ -962,10 +974,7 @@ impl<'a, T> RangeStream for SliceStream<'a, T>
     fn uncons_while<F>(&mut self, mut f: F) -> Result<&'a [T], Error<&'a T, &'a [T]>>
         where F: FnMut(Self::Item) -> bool
     {
-        let len = self.0
-            .iter()
-            .take_while(|c| f(*c))
-            .count();
+        let len = self.0.iter().take_while(|c| f(*c)).count();
         let (range, rest) = self.0.split_at(len);
         self.0 = rest;
         Ok(range)
@@ -1143,10 +1152,7 @@ impl Positioner for str {
 impl Positioner for char {
     type Position = SourcePosition;
     fn start() -> SourcePosition {
-        SourcePosition {
-            line: 1,
-            column: 1,
-        }
+        SourcePosition { line: 1, column: 1 }
     }
     fn update(&self, position: &mut SourcePosition) {
         position.column += 1;
@@ -1825,7 +1831,9 @@ impl<I> BufferedStreamInner<I>
             // We have backtracked to far
             Err(Error::Message("Backtracked to far".into()))
         } else {
-            Ok(self.buffer[self.buffer.len() - (self.offset - offset)].0.clone())
+            Ok(self.buffer[self.buffer.len() - (self.offset - offset)]
+                   .0
+                   .clone())
         }
     }
 
@@ -1840,7 +1848,9 @@ impl<I> BufferedStreamInner<I>
                 .1
                 .clone()
         } else {
-            self.buffer[self.buffer.len() - (self.offset - offset)].1.clone()
+            self.buffer[self.buffer.len() - (self.offset - offset)]
+                .1
+                .clone()
         }
     }
 }
@@ -1928,7 +1938,9 @@ mod tests {
     #[test]
     fn parse_clone_but_not_copy() {
         // This verifies we can parse slice references with an item type that is Clone but not Copy.
-        let input = &[CloneOnly { s: "x".to_string() }, CloneOnly { s: "y".to_string() }][..];
+        let input = &[CloneOnly { s: "x".to_string() },
+                      CloneOnly { s: "y".to_string() }]
+                         [..];
         let result = ::range::take_while(|c: CloneOnly| c.s == "x".to_string()).parse(input);
         assert_eq!(result,
                    Ok((&[CloneOnly { s: "x".to_string() }][..],


Test patch:
diff --git a/tests/buffered_stream.rs b/tests/buffered_stream.rs
index 874e2118..ff309335 100644
--- a/tests/buffered_stream.rs
+++ b/tests/buffered_stream.rs
@@ -7,15 +7,19 @@ use combine::{StreamOnce, Parser, choice, from_iter, many, many1, sep_by, try};
 #[test]
 fn shared_stream_buffer() {
     // Iterator that can't be cloned
-    let text = "10,222,3,44".chars().map(|c| if c.is_digit(10) {
-                                             (c as u8 + 1) as char
-                                         } else {
-                                             c
-                                         });
+    let text = "10,222,3,44"
+        .chars()
+        .map(|c| if c.is_digit(10) {
+                 (c as u8 + 1) as char
+             } else {
+                 c
+             });
     let buffer = BufferedStream::new(from_iter(text), 1);
     let int: &mut Parser<Input = _, Output = _> =
         &mut many(digit()).map(|s: String| s.parse::<i64>().unwrap());
-    let result = sep_by(int, char(',')).parse(buffer.as_stream()).map(|t| t.0);
+    let result = sep_by(int, char(','))
+        .parse(buffer.as_stream())
+        .map(|t| t.0);
     assert_eq!(result, Ok(vec![21, 333, 4, 55]));
 }
 
@@ -27,8 +31,9 @@ fn shared_stream_backtrack() {
     let buffer = BufferedStream::new(from_iter(&mut iter), 2);
     let stream = buffer.as_stream();
 
-    let value: &mut Parser<Input = _, Output = _> =
-        &mut choice([try(string("apple")), try(string("orange")), try(string("ananas"))]);
+    let value: &mut Parser<Input = _, Output = _> = &mut choice([try(string("apple")),
+                                                                 try(string("orange")),
+                                                                 try(string("ananas"))]);
     let mut parser = sep_by(value, char(','));
     let result = parser.parse(stream).map(|t| t.0);
     assert_eq!(result, Ok(vec!["apple", "apple", "ananas", "orange"]));
@@ -42,12 +47,14 @@ fn shared_stream_insufficent_backtrack() {
     let buffer = BufferedStream::new(from_iter(&mut iter), 1);
     let stream = buffer.as_stream();
 
-    let value: &mut Parser<Input = _, Output = _> =
-        &mut choice([try(string("apple")), try(string("orange")), try(string("ananas"))]);
+    let value: &mut Parser<Input = _, Output = _> = &mut choice([try(string("apple")),
+                                                                 try(string("orange")),
+                                                                 try(string("ananas"))]);
     let mut parser = sep_by(value, char(','));
     let result: Result<Vec<&str>, _> = parser.parse(stream).map(|t| t.0);
     assert!(result.is_err());
-    assert!(result.unwrap_err()
+    assert!(result
+                .unwrap_err()
                 .errors
                 .iter()
                 .any(|err| *err == Error::Message("Backtracked to far".into())));
@@ -60,7 +67,9 @@ fn always_output_end_of_input_after_end_of_input() {
     let text = "10".chars();
     let buffer = BufferedStream::new(from_iter(text), 1);
     let int = many1(digit()).map(|s: String| s.parse::<i64>().unwrap());
-    let result = many(spaces().with(int)).parse(buffer.as_stream()).map(|t| t.0);
+    let result = many(spaces().with(int))
+        .parse(buffer.as_stream())
+        .map(|t| t.0);
     assert_eq!(result, Ok(vec![10]));
 }
 
diff --git a/tests/date.rs b/tests/date.rs
index 1722a052..8ba12ead 100644
--- a/tests/date.rs
+++ b/tests/date.rs
@@ -45,7 +45,9 @@ fn two_digits<I>() -> FnPtrParser<i32, I>
     fn two_digits_<I>(input: I) -> ParseResult<i32, I>
         where I: Stream<Item = char>
     {
-        (digit(), digit()).map(two_digits_to_int).parse_stream(input)
+        (digit(), digit())
+            .map(two_digits_to_int)
+            .parse_stream(input)
     }
     parser(two_digits_)
 }
@@ -77,13 +79,13 @@ fn date<I>(input: I) -> ParseResult<Date, I>
 {
     (many::<String, _>(digit()), char('-'), two_digits(), char('-'), two_digits())
         .map(|(year, _, month, _, day)| {
-            // Its ok to just unwrap since we only parsed digits
-            Date {
-                year: year.parse().unwrap(),
-                month: month,
-                day: day,
-            }
-        })
+                 // Its ok to just unwrap since we only parsed digits
+                 Date {
+                     year: year.parse().unwrap(),
+                     month: month,
+                     day: day,
+                 }
+             })
         .parse_stream(input)
 }
 
diff --git a/tests/ini.rs b/tests/ini.rs
index 23d28667..e73688b5 100644
--- a/tests/ini.rs
+++ b/tests/ini.rs
@@ -78,12 +78,16 @@ type=LL(1)
         global: HashMap::new(),
         sections: HashMap::new(),
     };
-    expected.global.insert(String::from("language"), String::from("rust"));
+    expected
+        .global
+        .insert(String::from("language"), String::from("rust"));
 
     let mut section = HashMap::new();
     section.insert(String::from("name"), String::from("combine"));
     section.insert(String::from("type"), String::from("LL(1)"));
-    expected.sections.insert(String::from("section"), section);
+    expected
+        .sections
+        .insert(String::from("section"), section);
 
     let result = parser(ini).parse(text).map(|t| t.0);
     assert_eq!(result, Ok(expected));
@@ -95,10 +99,7 @@ fn ini_error() {
     let result = parser(ini).parse(State::new(text)).map(|t| t.0);
     assert_eq!(result,
                Err(ParseError {
-                       position: SourcePosition {
-                           line: 1,
-                           column: 7,
-                       },
+                       position: SourcePosition { line: 1, column: 7 },
                        errors: vec![Error::end_of_input(), Error::Expected("section".into())],
                    }));
 }