Repository: Marwes/combine (language: rust)

Issue:
Fixes to `try` and `expected`
* `try` used to report errors twice in some cases. Fix that.

* Change `expected` in the same way as `message` from earlier.  
Regarding your comment earlier: I would expect `(expr, operator, expr).expected("binary expression").parse("1")` to output "expected binary expression"... Can you tell me why you think this is wrong?  
Also, doesn't `message` fulfil the role of `context` as you've described it previously?



Both have unit tests (which have illustrative failures pre-fixes)


Discussion / hints:
> Regarding your comment earlier: I would expect (expr, operator, expr).expected("binary expression").parse("1") to output "expected binary expression"... Can you tell me why you think this is wrong?

Because the location of the reported error is at `operator` ie.

```
1
 ^ Expected binary expression
```
But at that location we expect an operator
I see, that makes sense actually. Although that wasn't the behaviour before, I'll fix up my PR so it matches what you described.
This contradicts the test `ini_error` in `tests/ini.rs` (which assumes my behaviour instead of yours). Which should I take as authoritative? :)

IMO we should adopt your semantics, and change the INI parser so that the "section" string is a `message("while parsing section")` rather than an `expected("section")`

Fix patch:
diff --git a/benches/http.rs b/benches/http.rs
index e68ad040..fa0bcc2c 100644
--- a/benches/http.rs
+++ b/benches/http.rs
@@ -21,8 +21,26 @@ struct Header<'a> {
 
 fn is_token(c: u8) -> bool {
     match c {
-        128...255 | 0...31 | b'(' | b')' | b'<' | b'>' | b'@' | b',' | b';' | b':' | b'\\' |
-        b'"' | b'/' | b'[' | b']' | b'?' | b'=' | b'{' | b'}' | b' ' => false,
+        128...255 |
+        0...31 |
+        b'(' |
+        b')' |
+        b'<' |
+        b'>' |
+        b'@' |
+        b',' |
+        b';' |
+        b':' |
+        b'\\' |
+        b'"' |
+        b'/' |
+        b'[' |
+        b']' |
+        b'?' |
+        b'=' |
+        b'{' |
+        b'}' |
+        b' ' => false,
         _ => true,
     }
 }
@@ -42,43 +60,48 @@ 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));
 
-    let request_line = (take_while1(is_token),
-                        take_while1(is_space),
-                        take_while1(is_not_space),
-                        take_while1(is_space),
-                        http_version)
-            .map(|(method, _, uri, _, version)| {
-                     Request {
-                         method: method,
-                         uri: uri,
-                         version: version,
-                     }
-                 });
-
-
-    let message_header_line = (take_while1(is_horizontal_space),
-                               take_while1(|c| c != b'\r' && c != b'\n'),
-                               end_of_line())
-            .map(|(_, line, _)| line);
-
-    let message_header = (take_while1(is_token), token(b':'), many1(message_header_line))
-        .map(|(name, _, value)| {
-                 Header {
-                     name: name,
-                     value: value,
-                 }
-             });
-
-    let mut request = (request_line, end_of_line(), many(message_header), end_of_line())
-        .map(|(request, _, headers, _)| (request, headers));
+    let request_line = (
+        take_while1(is_token),
+        take_while1(is_space),
+        take_while1(is_not_space),
+        take_while1(is_space),
+        http_version,
+    ).map(|(method, _, uri, _, version)| {
+            Request {
+                method: method,
+                uri: uri,
+                version: version,
+            }
+        });
+
+
+    let message_header_line = (
+        take_while1(is_horizontal_space),
+        take_while1(|c| c != b'\r' && c != b'\n'),
+        end_of_line(),
+    ).map(|(_, line, _)| line);
+
+    let message_header = (
+        take_while1(is_token),
+        token(b':'),
+        many1(message_header_line),
+    ).map(|(name, _, value)| {
+            Header {
+                name: name,
+                value: value,
+            }
+        });
+
+    let mut request = (
+        request_line,
+        end_of_line(),
+        many(message_header),
+        end_of_line(),
+    ).map(|(request, _, headers, _)| (request, headers));
 
     request.parse(input)
 }
diff --git a/benches/json.rs b/benches/json.rs
index 9c6572d9..aef619a5 100644
--- a/benches/json.rs
+++ b/benches/json.rs
@@ -8,8 +8,8 @@ use std::fs::File;
 use std::path::Path;
 
 use pc::primitives::{Consumed, Parser, ParseError, ParseResult, State, Stream, BufferedStream};
-use pc::combinator::{any, between, choice, many, many1, optional, parser, satisfy, sep_by, Expected,
-                     FnParser, Skip};
+use pc::combinator::{any, between, choice, many, many1, optional, parser, satisfy, sep_by,
+                     Expected, FnParser, Skip};
 use pc::char::{char, digit, spaces, Spaces, string};
 use pc::from_iter;
 
@@ -24,8 +24,9 @@ enum Value {
 }
 
 fn lex<P>(p: P) -> Skip<P, Spaces<P::Input>>
-    where P: Parser,
-          P::Input: Stream<Item = char>
+where
+    P: Parser,
+    P::Input: Stream<Item = char>,
 {
     p.skip(spaces())
 }
@@ -35,13 +36,15 @@ type FnPtrParser<O, I> = FnParser<I, fn(I) -> ParseResult<O, I>>;
 type JsonParser<O, I> = Expected<FnPtrParser<O, I>>;
 
 fn fn_parser<O, I>(f: fn(I) -> ParseResult<O, I>, err: &'static str) -> JsonParser<O, I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
     parser(f).expected(err)
 }
 
 impl<I> Json<I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
     fn integer() -> JsonParser<i64, I> {
         fn_parser(Json::<I>::integer_, "integer")
@@ -59,7 +62,9 @@ impl<I> Json<I>
         fn_parser(Json::<I>::number_, "number")
     }
     fn number_(input: I) -> ParseResult<f64, I> {
-        let i = char('0').map(|_| 0.0).or(Json::<I>::integer().map(|x| x as f64));
+        let i = char('0')
+            .map(|_| 0.0)
+            .or(Json::<I>::integer().map(|x| x as f64));
         let fractional = many(digit()).map(|digits: String| {
             let mut magnitude = 1.0;
             digits.chars().fold(0.0, |acc, d| {
@@ -71,23 +76,24 @@ impl<I> Json<I>
             })
         });
 
-        let exp = satisfy(|c| c == 'e' || c == 'E').with(optional(char('-'))
-                                                             .and(Json::<I>::integer()));
-        lex(optional(char('-'))
+        let exp =
+            satisfy(|c| c == 'e' || c == 'E').with(optional(char('-')).and(Json::<I>::integer()));
+        lex(
+            optional(char('-'))
                 .and(i)
                 .map(|(sign, n)| if sign.is_some() { -n } else { n })
                 .and(optional(char('.')).with(fractional))
                 .map(|(x, y)| if x >= 0.0 { x + y } else { x - y })
                 .and(optional(exp))
                 .map(|(n, exp_option)| match exp_option {
-                         Some((sign, e)) => {
-            let e = if sign.is_some() { -e } else { e };
-            n * 10.0f64.powi(e as i32)
-        }
-                         None => n,
-                     }))
-                .parse_lazy(input)
-                .into()
+                    Some((sign, e)) => {
+                        let e = if sign.is_some() { -e } else { e };
+                        n * 10.0f64.powi(e as i32)
+                    }
+                    None => n,
+                }),
+        ).parse_lazy(input)
+            .into()
     }
 
     fn char() -> JsonParser<char, I> {
@@ -111,8 +117,10 @@ impl<I> Json<I>
         match c {
             '\\' => input.combine(|input| back_slash_char.parse_stream(input)),
             '"' => {
-                Err(Consumed::Empty(ParseError::from_errors(input.into_inner().position(),
-                                                            Vec::new())))
+                Err(Consumed::Empty(ParseError::from_errors(
+                    input.into_inner().position(),
+                    Vec::new(),
+                )))
             }
             _ => Ok((c, input)),
         }
@@ -121,7 +129,9 @@ impl<I> Json<I>
         fn_parser(Json::<I>::string_, "string")
     }
     fn string_(input: I) -> ParseResult<String, I> {
-        between(char('"'), lex(char('"')), many(Json::<I>::char())).parse_lazy(input).into()
+        between(char('"'), lex(char('"')), many(Json::<I>::char()))
+            .parse_lazy(input)
+            .into()
     }
 
     fn object() -> JsonParser<Value, I> {
@@ -130,7 +140,10 @@ impl<I> Json<I>
     fn object_(input: I) -> ParseResult<Value, I> {
         let field = (Json::<I>::string(), lex(char(':')), Json::<I>::value()).map(|t| (t.0, t.2));
         let fields = sep_by(field, lex(char(',')));
-        between(lex(char('{')), lex(char('}')), fields).map(Value::Object).parse_lazy(input).into()
+        between(lex(char('{')), lex(char('}')), fields)
+            .map(Value::Object)
+            .parse_lazy(input)
+            .into()
     }
 
     fn value() -> FnPtrParser<Value, I> {
@@ -138,22 +151,22 @@ impl<I> Json<I>
     }
     #[allow(unconditional_recursion)]
     fn value_(input: I) -> ParseResult<Value, I> {
-        let mut array = between(lex(char('[')),
-                                lex(char(']')),
-                                sep_by(Json::<I>::value(), lex(char(','))))
-                .map(Value::Array);
-
-        choice::<[&mut Parser<Input = I, Output = Value>;
-                  7],
-                 _>([&mut Json::<I>::string().map(Value::String),
-                     &mut Json::<I>::object(),
-                     &mut array,
-                     &mut Json::<I>::number().map(Value::Number),
-                     &mut lex(string("false").map(|_| Value::Bool(false))),
-                     &mut lex(string("true").map(|_| Value::Bool(true))),
-                     &mut lex(string("null").map(|_| Value::Null))])
-                .parse_lazy(input)
-                .into()
+        let mut array = between(
+            lex(char('[')),
+            lex(char(']')),
+            sep_by(Json::<I>::value(), lex(char(','))),
+        ).map(Value::Array);
+
+        choice::<[&mut Parser<Input = I, Output = Value>; 7], _>([
+            &mut Json::<I>::string().map(Value::String),
+            &mut Json::<I>::object(),
+            &mut array,
+            &mut Json::<I>::number().map(Value::Number),
+            &mut lex(string("false").map(|_| Value::Bool(false))),
+            &mut lex(string("true").map(|_| Value::Bool(true))),
+            &mut lex(string("null").map(|_| Value::Null)),
+        ]).parse_lazy(input)
+            .into()
     }
 }
 
@@ -173,19 +186,22 @@ fn json_test() {
     "null" : null
 }"#;
     let result = Json::value().parse(input);
-    let expected = Object(vec![("array", Array(vec![Number(1.0), String("".to_string())])),
-                               ("object", Object(HashMap::new())),
-                               ("number", Number(3.14)),
-                               ("small_number", Number(0.59)),
-                               ("int", Number(-100.)),
-                               ("exp", Number(-1e2)),
-                               ("exp_neg", Number(23E-2)),
-                               ("true", Bool(true)),
-                               ("false", Bool(false)),
-                               ("null", Null)]
-                                  .into_iter()
-                                  .map(|(k, v)| (k.to_string(), v))
-                                  .collect());
+    let expected = Object(
+        vec![
+            ("array", Array(vec![Number(1.0), String("".to_string())])),
+            ("object", Object(HashMap::new())),
+            ("number", Number(3.14)),
+            ("small_number", Number(0.59)),
+            ("int", Number(-100.)),
+            ("exp", Number(-1e2)),
+            ("exp_neg", Number(23E-2)),
+            ("true", Bool(true)),
+            ("false", Bool(false)),
+            ("null", Null),
+        ].into_iter()
+            .map(|(k, v)| (k.to_string(), v))
+            .collect(),
+    );
     match result {
         Ok(result) => assert_eq!(result, (expected, "")),
         Err(e) => {
@@ -211,9 +227,9 @@ fn bench_json(bencher: &mut ::test::Bencher) {
         }
     }
     bencher.iter(|| {
-                     let result = parser.parse(State::new(&data[..]));
-                     ::test::black_box(result)
-                 });
+        let result = parser.parse(State::new(&data[..]));
+        ::test::black_box(result)
+    });
 }
 
 #[bench]
diff --git a/benches/mp4.rs b/benches/mp4.rs
index 3c7beace..0e097042 100644
--- a/benches/mp4.rs
+++ b/benches/mp4.rs
@@ -34,17 +34,24 @@ enum MP4Box<'a> {
 
 fn parse_mp4(data: &[u8]) -> Result<(Vec<MP4Box>, &[u8]), ParseError<&[u8]>> {
     let brand_name = || take(4).and_then(from_utf8);
-    let filetype_box = (range(&b"ftyp"[..]), brand_name(), take(4), many(brand_name()))
-        .map(|(_, m, v, c)| {
+    let filetype_box = (
+        range(&b"ftyp"[..]),
+        brand_name(),
+        take(4),
+        many(brand_name()),
+    ).map(|(_, m, v, c)| {
             MP4Box::Ftyp(FileType {
-                             major_brand: m,
-                             major_brand_version: v,
-                             compatible_brands: c,
-                         })
+                major_brand: m,
+                major_brand_version: v,
+                compatible_brands: c,
+            })
         });
 
-    let mp4_box = take(4).map(BigEndian::read_u32).then(|offset| take(offset as usize - 4));
-    let mut box_parser = filetype_box.or(range(&b"moov"[..]).map(|_| MP4Box::Moov))
+    let mp4_box = take(4)
+        .map(BigEndian::read_u32)
+        .then(|offset| take(offset as usize - 4));
+    let mut box_parser = filetype_box
+        .or(range(&b"moov"[..]).map(|_| MP4Box::Moov))
         .or(range(&b"mdat"[..]).map(|_| MP4Box::Mdat))
         .or(range(&b"free"[..]).map(|_| MP4Box::Free))
         .or(range(&b"skip"[..]).map(|_| MP4Box::Skip))
@@ -59,9 +66,9 @@ static MP4_SMALL: &'static [u8] = include_bytes!("small.mp4");
 
 fn run_test(b: &mut Bencher, data: &[u8]) {
     b.iter(|| match parse_mp4(data) {
-               Ok(x) => black_box(x),
-               Err(err) => panic!("{:?}", err),
-           });
+        Ok(x) => black_box(x),
+        Err(err) => panic!("{:?}", err),
+    });
 }
 
 #[bench]
diff --git a/src/byte.rs b/src/byte.rs
index 1b7e0c9b..14e83e20 100644
--- a/src/byte.rs
+++ b/src/byte.rs
@@ -22,7 +22,8 @@ use primitives::{ConsumedResult, Info, Parser, ParseError, Stream};
 /// ```
 #[inline(always)]
 pub fn byte<I>(c: u8) -> Token<I>
-    where I: Stream<Item = u8>
+where
+    I: Stream<Item = u8>,
 {
     token(c)
 }
@@ -41,7 +42,8 @@ macro_rules! byte_parser {
 /// Parses a base-10 digit (0–9).
 #[inline(always)]
 pub fn digit<I>() -> Digit<I>
-    where I: Stream<Item = u8>
+where
+    I: Stream<Item = u8>,
 {
     byte_parser!(digit, Digit, is_digit)
 }
@@ -51,7 +53,8 @@ impl_token_parser! { Space(), u8, Expected<Satisfy<I, fn (u8) -> bool>> }
 /// Parses a `b' '`, `b'\t'`, `b'\n'` or `'b\'r'`.
 #[inline(always)]
 pub fn space<I>() -> Space<I>
-    where I: Stream<Item = u8>
+where
+    I: Stream<Item = u8>,
 {
     byte_parser!(space, Space, is_whitespace)
 }
@@ -62,7 +65,8 @@ impl_token_parser! { Spaces(), u8, Expected<SkipMany<Space<I>>> }
 /// [`space`]: fn.space.html
 #[inline(always)]
 pub fn spaces<I>() -> Spaces<I>
-    where I: Stream<Item = u8>
+where
+    I: Stream<Item = u8>,
 {
     Spaces(skip_many(space()).expected("whitespaces"), PhantomData)
 }
@@ -72,10 +76,13 @@ impl_token_parser! { Newline(), u8, Expected<Satisfy<I, fn (u8) -> bool>> }
 /// Parses a newline character (`b'\n'`).
 #[inline(always)]
 pub fn newline<I>() -> Newline<I>
-    where I: Stream<Item = u8>
+where
+    I: Stream<Item = u8>,
 {
-    Newline(satisfy(static_fn!((ch, u8) -> bool { ch == b'\n' })).expected("lf newline"),
-            PhantomData)
+    Newline(
+        satisfy(static_fn!((ch, u8) -> bool { ch == b'\n' })).expected("lf newline"),
+        PhantomData,
+    )
 }
 
 impl_token_parser! { CrLf(), u8, Expected<With<Satisfy<I, fn (u8) -> bool>, Newline<I>>> }
@@ -83,29 +90,36 @@ impl_token_parser! { CrLf(), u8, Expected<With<Satisfy<I, fn (u8) -> bool>, Newl
 /// Parses carriage return and newline (`b"\r\n"`), returning the newline character.
 #[inline(always)]
 pub fn crlf<I>() -> CrLf<I>
-    where I: Stream<Item = u8>
+where
+    I: Stream<Item = u8>,
 {
-    CrLf(satisfy(static_fn!((ch, u8) -> bool { ch == b'\r' }))
-             .with(newline())
-             .expected("crlf newline"),
-         PhantomData)
+    CrLf(
+        satisfy(static_fn!((ch, u8) -> bool { ch == b'\r' }))
+            .with(newline())
+            .expected("crlf newline"),
+        PhantomData,
+    )
 }
 
 impl_token_parser! { Tab(), u8, Expected<Satisfy<I, fn (u8) -> bool>> }
 /// Parses a tab character (`b'\t'`).
 #[inline(always)]
 pub fn tab<I>() -> Tab<I>
-    where I: Stream<Item = u8>
+where
+    I: Stream<Item = u8>,
 {
-    Tab(satisfy(static_fn!((ch, u8) -> bool { ch == b'\t' })).expected("tab"),
-        PhantomData)
+    Tab(
+        satisfy(static_fn!((ch, u8) -> bool { ch == b'\t' })).expected("tab"),
+        PhantomData,
+    )
 }
 
 impl_token_parser! { Upper(), u8, Expected<Satisfy<I, fn (u8) -> bool>> }
 /// Parses an uppercase ASCII letter (A–Z).
 #[inline(always)]
 pub fn upper<I>() -> Upper<I>
-    where I: Stream<Item = u8>
+where
+    I: Stream<Item = u8>,
 {
     byte_parser!(upper, Upper, is_uppercase)
 }
@@ -114,7 +128,8 @@ impl_token_parser! { Lower(), u8, Expected<Satisfy<I, fn (u8) -> bool>> }
 /// Parses an lowercase ASCII letter (a–z).
 #[inline(always)]
 pub fn lower<I>() -> Lower<I>
-    where I: Stream<Item = u8>
+where
+    I: Stream<Item = u8>,
 {
     byte_parser!(lower, Lower, is_lowercase)
 }
@@ -123,7 +138,8 @@ impl_token_parser! { AlphaNum(), u8, Expected<Satisfy<I, fn (u8) -> bool>> }
 /// Parses either an ASCII alphabet letter or digit (a–z, A–Z, 0–9).
 #[inline(always)]
 pub fn alpha_num<I>() -> AlphaNum<I>
-    where I: Stream<Item = u8>
+where
+    I: Stream<Item = u8>,
 {
     byte_parser!(alpha_num, AlphaNum, is_alphanumeric)
 }
@@ -132,7 +148,8 @@ impl_token_parser! { Letter(), u8, Expected<Satisfy<I, fn (u8) -> bool>> }
 /// Parses an ASCII alphabet letter (a–z, A–Z).
 #[inline(always)]
 pub fn letter<I>() -> Letter<I>
-    where I: Stream<Item = u8>
+where
+    I: Stream<Item = u8>,
 {
     byte_parser!(letter, Letter, is_alphabetic)
 }
@@ -141,16 +158,20 @@ impl_token_parser! { HexDigit(), u8, Expected<Satisfy<I, fn (u8) -> bool>> }
 /// Parses an ASCII hexdecimal digit (accepts both uppercase and lowercase).
 #[inline(always)]
 pub fn hex_digit<I>() -> HexDigit<I>
-    where I: Stream<Item = u8>
+where
+    I: Stream<Item = u8>,
 {
     byte_parser!(hex_digit, HexDigit, is_hex)
 }
 
 #[derive(Clone)]
-pub struct Bytes<I>(&'static [u8], PhantomData<I>) where I: Stream<Item = u8>;
+pub struct Bytes<I>(&'static [u8], PhantomData<I>)
+where
+    I: Stream<Item = u8>;
 
 impl<'a, I> Parser for Bytes<I>
-    where I: Stream<Item = u8, Range = &'a [u8]>
+where
+    I: Stream<Item = u8, Range = &'a [u8]>,
 {
     type Input = I;
     type Output = &'static [u8];
@@ -186,17 +207,21 @@ impl<'a, I> Parser for Bytes<I>
 /// [`range`]: ../range/fn.range.html
 #[inline(always)]
 pub fn bytes<'a, I>(s: &'static [u8]) -> Bytes<I>
-    where I: Stream<Item = u8, Range = &'a [u8]>
+where
+    I: Stream<Item = u8, Range = &'a [u8]>,
 {
     Bytes(s, PhantomData)
 }
 
 #[derive(Clone)]
-pub struct BytesCmp<C, I>(&'static [u8], C, PhantomData<I>) where I: Stream<Item = u8>;
+pub struct BytesCmp<C, I>(&'static [u8], C, PhantomData<I>)
+where
+    I: Stream<Item = u8>;
 
 impl<'a, C, I> Parser for BytesCmp<C, I>
-    where C: FnMut(u8, u8) -> bool,
-          I: Stream<Item = u8, Range = &'a [u8]>
+where
+    C: FnMut(u8, u8) -> bool,
+    I: Stream<Item = u8, Range = &'a [u8]>,
 {
     type Input = I;
     type Output = &'static [u8];
@@ -233,8 +258,9 @@ impl<'a, C, I> Parser for BytesCmp<C, I>
 /// [`range`]: ../range/fn.range.html
 #[inline(always)]
 pub fn bytes_cmp<'a, C, I>(s: &'static [u8], cmp: C) -> BytesCmp<C, I>
-    where C: FnMut(u8, u8) -> bool,
-          I: Stream<Item = u8, Range = &'a [u8]>
+where
+    C: FnMut(u8, u8) -> bool,
+    I: Stream<Item = u8, Range = &'a [u8]>,
 {
     BytesCmp(s, cmp, PhantomData)
 }
diff --git a/src/char.rs b/src/char.rs
index 8b563809..6ec98652 100644
--- a/src/char.rs
+++ b/src/char.rs
@@ -17,7 +17,8 @@ use std::marker::PhantomData;
 /// ```
 #[inline(always)]
 pub fn char<I>(c: char) -> Token<I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
     token(c)
 }
@@ -27,10 +28,13 @@ impl_token_parser! { Digit(), char, Expected<Satisfy<I, fn (char) -> bool>> }
 /// Parses a base-10 digit.
 #[inline(always)]
 pub fn digit<I>() -> Digit<I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
-    Digit(satisfy(static_fn!((c, char) -> bool { c.is_digit(10) })).expected("digit"),
-          PhantomData)
+    Digit(
+        satisfy(static_fn!((c, char) -> bool { c.is_digit(10) })).expected("digit"),
+        PhantomData,
+    )
 }
 
 impl_token_parser! { Space(), char, Expected<Satisfy<I, fn (char) -> bool>> }
@@ -42,7 +46,8 @@ impl_token_parser! { Space(), char, Expected<Satisfy<I, fn (char) -> bool>> }
 /// [`std::char::is_whitespace`]: https://doc.rust-lang.org/std/primitive.char.html#method.is_whitespace
 #[inline(always)]
 pub fn space<I>() -> Space<I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
     let f: fn(char) -> bool = char::is_whitespace;
     Space(satisfy(f).expected("whitespace"), PhantomData)
@@ -57,7 +62,8 @@ impl_token_parser! { Spaces(), char, Expected<SkipMany<Space<I>>> }
 /// [`std::char::is_whitespace`]: https://doc.rust-lang.org/std/primitive.char.html#method.is_whitespace
 #[inline(always)]
 pub fn spaces<I>() -> Spaces<I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
     Spaces(skip_many(space()).expected("whitespaces"), PhantomData)
 }
@@ -67,10 +73,13 @@ impl_token_parser! { Newline(), char, Expected<Satisfy<I, fn (char) -> bool>> }
 /// Parses a newline character.
 #[inline(always)]
 pub fn newline<I>() -> Newline<I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
-    Newline(satisfy(static_fn!((ch, char) -> bool { ch == '\n' })).expected("lf newline"),
-            PhantomData)
+    Newline(
+        satisfy(static_fn!((ch, char) -> bool { ch == '\n' })).expected("lf newline"),
+        PhantomData,
+    )
 }
 
 impl_token_parser! { CrLf(), char, Expected<With<Satisfy<I, fn (char) -> bool>, Newline<I>>> }
@@ -78,12 +87,15 @@ impl_token_parser! { CrLf(), char, Expected<With<Satisfy<I, fn (char) -> bool>,
 /// Parses carriage return and newline, returning the newline character.
 #[inline(always)]
 pub fn crlf<I>() -> CrLf<I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
-    CrLf(satisfy(static_fn!((ch, char) -> bool { ch == '\r' }))
-             .with(newline())
-             .expected("crlf newline"),
-         PhantomData)
+    CrLf(
+        satisfy(static_fn!((ch, char) -> bool { ch == '\r' }))
+            .with(newline())
+            .expected("crlf newline"),
+        PhantomData,
+    )
 }
 
 impl_token_parser! { Tab(), char, Expected<Satisfy<I, fn (char) -> bool>> }
@@ -91,10 +103,13 @@ impl_token_parser! { Tab(), char, Expected<Satisfy<I, fn (char) -> bool>> }
 /// Parses a tab character.
 #[inline(always)]
 pub fn tab<I>() -> Tab<I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
-    Tab(satisfy(static_fn!((ch, char) -> bool { ch == '\t' })).expected("tab"),
-        PhantomData)
+    Tab(
+        satisfy(static_fn!((ch, char) -> bool { ch == '\t' })).expected("tab"),
+        PhantomData,
+    )
 }
 
 impl_token_parser! { Upper(), char, Expected<Satisfy<I, fn (char) -> bool>> }
@@ -104,10 +119,13 @@ impl_token_parser! { Upper(), char, Expected<Satisfy<I, fn (char) -> bool>> }
 /// [`std::char::is_uppercase`]: https://doc.rust-lang.org/std/primitive.char.html#method.is_uppercase
 #[inline(always)]
 pub fn upper<I>() -> Upper<I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
-    Upper(satisfy(static_fn!((ch, char) -> bool { ch.is_uppercase()})).expected("uppercase letter"),
-          PhantomData)
+    Upper(
+        satisfy(static_fn!((ch, char) -> bool { ch.is_uppercase()})).expected("uppercase letter"),
+        PhantomData,
+    )
 }
 
 impl_token_parser! { Lower(), char, Expected<Satisfy<I, fn (char) -> bool>> }
@@ -117,11 +135,13 @@ impl_token_parser! { Lower(), char, Expected<Satisfy<I, fn (char) -> bool>> }
 /// [`std::char::is_lowercase`]: https://doc.rust-lang.org/std/primitive.char.html#method.is_lowercase
 #[inline(always)]
 pub fn lower<I>() -> Lower<I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
-    Lower(satisfy(static_fn!((ch, char) -> bool { ch.is_lowercase() }))
-              .expected("lowercase letter"),
-          PhantomData)
+    Lower(
+        satisfy(static_fn!((ch, char) -> bool { ch.is_lowercase() })).expected("lowercase letter"),
+        PhantomData,
+    )
 }
 
 impl_token_parser! { AlphaNum(), char, Expected<Satisfy<I, fn (char) -> bool>> }
@@ -131,11 +151,14 @@ impl_token_parser! { AlphaNum(), char, Expected<Satisfy<I, fn (char) -> bool>> }
 /// [`std::char::is_alphanumeric`]: https://doc.rust-lang.org/std/primitive.char.html#method.is_alphanumeric
 #[inline(always)]
 pub fn alpha_num<I>() -> AlphaNum<I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
-    AlphaNum(satisfy(static_fn!((ch, char) -> bool { ch.is_alphanumeric() }))
-                 .expected("letter or digit"),
-             PhantomData)
+    AlphaNum(
+        satisfy(static_fn!((ch, char) -> bool { ch.is_alphanumeric() }))
+            .expected("letter or digit"),
+        PhantomData,
+    )
 }
 
 impl_token_parser! { Letter(), char, Expected<Satisfy<I, fn (char) -> bool>> }
@@ -145,10 +168,13 @@ impl_token_parser! { Letter(), char, Expected<Satisfy<I, fn (char) -> bool>> }
 /// [`std::char::is_alphabetic`]: https://doc.rust-lang.org/std/primitive.char.html#method.is_alphabetic
 #[inline(always)]
 pub fn letter<I>() -> Letter<I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
-    Letter(satisfy(static_fn!((ch, char) -> bool { ch.is_alphabetic() })).expected("letter"),
-           PhantomData)
+    Letter(
+        satisfy(static_fn!((ch, char) -> bool { ch.is_alphabetic() })).expected("letter"),
+        PhantomData,
+    )
 }
 
 impl_token_parser! { OctDigit(), char, Expected<Satisfy<I, fn (char) -> bool>> }
@@ -156,10 +182,13 @@ impl_token_parser! { OctDigit(), char, Expected<Satisfy<I, fn (char) -> bool>> }
 /// Parses an octal digit.
 #[inline(always)]
 pub fn oct_digit<I>() -> OctDigit<I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
-    OctDigit(satisfy(static_fn!((ch, char) -> bool { ch.is_digit(8) })).expected("octal digit"),
-             PhantomData)
+    OctDigit(
+        satisfy(static_fn!((ch, char) -> bool { ch.is_digit(8) })).expected("octal digit"),
+        PhantomData,
+    )
 }
 
 impl_token_parser! { HexDigit(), char, Expected<Satisfy<I, fn (char) -> bool>> }
@@ -167,11 +196,13 @@ impl_token_parser! { HexDigit(), char, Expected<Satisfy<I, fn (char) -> bool>> }
 /// Parses a hexdecimal digit with uppercase and lowercase.
 #[inline(always)]
 pub fn hex_digit<I>() -> HexDigit<I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
-    HexDigit(satisfy(static_fn!((ch, char) -> bool { ch.is_digit(0x10) }))
-                 .expected("hexadecimal digit"),
-             PhantomData)
+    HexDigit(
+        satisfy(static_fn!((ch, char) -> bool { ch.is_digit(0x10) })).expected("hexadecimal digit"),
+        PhantomData,
+    )
 }
 
 fn eq(l: char, r: char) -> bool {
@@ -179,9 +210,12 @@ fn eq(l: char, r: char) -> bool {
 }
 
 #[derive(Clone)]
-pub struct Str<I>(&'static str, PhantomData<fn(I) -> I>) where I: Stream<Item = char>;
+pub struct Str<I>(&'static str, PhantomData<fn(I) -> I>)
+where
+    I: Stream<Item = char>;
 impl<I> Parser for Str<I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
     type Input = I;
     type Output = &'static str;
@@ -211,16 +245,20 @@ impl<I> Parser for Str<I>
 /// ```
 #[inline(always)]
 pub fn string<I>(s: &'static str) -> Str<I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
     Str(s, PhantomData)
 }
 
 #[derive(Clone)]
-pub struct StrCmp<C, I>(&'static str, C, PhantomData<fn(I) -> I>) where I: Stream<Item = char>;
+pub struct StrCmp<C, I>(&'static str, C, PhantomData<fn(I) -> I>)
+where
+    I: Stream<Item = char>;
 impl<C, I> Parser for StrCmp<C, I>
-    where C: FnMut(char, char) -> bool,
-          I: Stream<Item = char>
+where
+    C: FnMut(char, char) -> bool,
+    I: Stream<Item = char>,
 {
     type Input = I;
     type Output = &'static str;
@@ -251,8 +289,9 @@ impl<C, I> Parser for StrCmp<C, I>
 /// ```
 #[inline(always)]
 pub fn string_cmp<C, I>(s: &'static str, cmp: C) -> StrCmp<C, I>
-    where C: FnMut(char, char) -> bool,
-          I: Stream<Item = char>
+where
+    C: FnMut(char, char) -> bool,
+    I: Stream<Item = char>,
 {
     StrCmp(s, cmp, PhantomData)
 }
@@ -266,8 +305,10 @@ mod tests {
     fn space_error() {
         let result = space().parse("");
         assert!(result.is_err());
-        assert_eq!(result.unwrap_err().errors,
-                   vec![Error::end_of_input(), Error::Expected("whitespace".into())]);
+        assert_eq!(
+            result.unwrap_err().errors,
+            vec![Error::end_of_input(), Error::Expected("whitespace".into())]
+        );
 
     }
 
@@ -275,18 +316,21 @@ mod tests {
     fn string_consumed() {
         let result = string("a").parse(State::new("b"));
         assert!(result.is_err());
-        assert_eq!(result.unwrap_err().position,
-                   SourcePosition { line: 1, column: 1 });
+        assert_eq!(
+            result.unwrap_err().position,
+            SourcePosition { line: 1, column: 1 }
+        );
     }
 
     #[test]
     fn string_error() {
         let result = string("abc").parse(State::new("bc"));
-        assert_eq!(result,
-                   Err(ParseError {
-                           position: SourcePosition { line: 1, column: 1 },
-                           errors: vec![Error::Unexpected('b'.into()),
-                                        Error::Expected("abc".into())],
-                       }));
+        assert_eq!(
+            result,
+            Err(ParseError {
+                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 3aa5c10b..91e3fa97 100644
--- a/src/combinator.rs
+++ b/src/combinator.rs
@@ -36,7 +36,8 @@ macro_rules! impl_parser {
 pub struct Any<I>(PhantomData<fn(I) -> I>);
 
 impl<I> Parser for Any<I>
-    where I: Stream
+where
+    I: Stream,
 {
     type Input = I;
     type Output = I::Item;
@@ -66,7 +67,8 @@ impl<I> Parser for Any<I>
 /// ```
 #[inline(always)]
 pub fn any<I>() -> Any<I>
-    where I: Stream
+where
+    I: Stream,
 {
     Any(PhantomData)
 }
@@ -80,8 +82,9 @@ pub struct Satisfy<I, P> {
 }
 
 fn satisfy_impl<I, P, R>(mut input: I, mut predicate: P) -> ConsumedResult<R, I>
-    where I: Stream,
-          P: FnMut(I::Item) -> Option<R>
+where
+    I: Stream,
+    P: FnMut(I::Item) -> Option<R>,
 {
     let position = input.position();
     match input.uncons() {
@@ -96,8 +99,9 @@ fn satisfy_impl<I, P, R>(mut input: I, mut predicate: P) -> ConsumedResult<R, I>
 }
 
 impl<I, P> Parser for Satisfy<I, P>
-    where I: Stream,
-          P: FnMut(I::Item) -> bool
+where
+    I: Stream,
+    P: FnMut(I::Item) -> bool,
 {
     type Input = I;
     type Output = I::Item;
@@ -124,8 +128,9 @@ impl<I, P> Parser for Satisfy<I, P>
 /// ```
 #[inline(always)]
 pub fn satisfy<I, P>(predicate: P) -> Satisfy<I, P>
-    where I: Stream,
-          P: FnMut(I::Item) -> bool
+where
+    I: Stream,
+    P: FnMut(I::Item) -> bool,
 {
     Satisfy {
         predicate: predicate,
@@ -140,8 +145,9 @@ pub struct SatisfyMap<I, P> {
 }
 
 impl<I, P, R> Parser for SatisfyMap<I, P>
-    where I: Stream,
-          P: FnMut(I::Item) -> Option<R>
+where
+    I: Stream,
+    P: FnMut(I::Item) -> Option<R>,
 {
     type Input = I;
     type Output = R;
@@ -177,8 +183,9 @@ impl<I, P, R> Parser for SatisfyMap<I, P>
 /// ```
 #[inline(always)]
 pub fn satisfy_map<I, P, R>(predicate: P) -> SatisfyMap<I, P>
-    where I: Stream,
-          P: FnMut(I::Item) -> Option<R>
+where
+    I: Stream,
+    P: FnMut(I::Item) -> Option<R>,
 {
     SatisfyMap {
         predicate: predicate,
@@ -188,16 +195,18 @@ pub fn satisfy_map<I, P, R>(predicate: P) -> SatisfyMap<I, P>
 
 #[derive(Clone)]
 pub struct Token<I>
-    where I: Stream,
-          I::Item: PartialEq
+where
+    I: Stream,
+    I::Item: PartialEq,
 {
     c: I::Item,
     _marker: PhantomData<I>,
 }
 
 impl<I> Parser for Token<I>
-    where I: Stream,
-          I::Item: PartialEq + Clone
+where
+    I: Stream,
+    I::Item: PartialEq + Clone,
 {
     type Input = I;
     type Output = I::Item;
@@ -226,8 +235,9 @@ impl<I> Parser for Token<I>
 /// ```
 #[inline(always)]
 pub fn token<I>(c: I::Item) -> Token<I>
-    where I: Stream,
-          I::Item: PartialEq
+where
+    I: Stream,
+    I::Item: PartialEq,
 {
     Token {
         c: c,
@@ -237,7 +247,8 @@ pub fn token<I>(c: I::Item) -> Token<I>
 
 #[derive(Clone)]
 pub struct Tokens<C, T, I>
-    where I: Stream
+where
+    I: Stream,
 {
     cmp: C,
     expected: Info<I::Item, I::Range>,
@@ -246,9 +257,10 @@ pub struct Tokens<C, T, I>
 }
 
 impl<C, T, I> Parser for Tokens<C, T, I>
-    where C: FnMut(T::Item, I::Item) -> bool,
-          T: Clone + IntoIterator,
-          I: Stream
+where
+    C: FnMut(T::Item, I::Item) -> bool,
+    T: Clone + IntoIterator,
+    I: Stream,
 {
     type Input = I;
     type Output = T;
@@ -261,26 +273,28 @@ impl<C, T, I> Parser for Tokens<C, T, I>
                 Ok((other, rest)) => {
                     if !(self.cmp)(c, other.clone()) {
                         return if consumed {
-                                   let errors = vec![Error::Unexpected(Info::Token(other)),
-                                                     Error::Expected(self.expected.clone())];
-                                   let error = ParseError::from_errors(start, errors);
-                                   ConsumedErr(error)
-                               } else {
-                                   EmptyErr(ParseError::empty(start))
-                               };
+                            let errors = vec![
+                                Error::Unexpected(Info::Token(other)),
+                                Error::Expected(self.expected.clone()),
+                            ];
+                            let error = ParseError::from_errors(start, errors);
+                            ConsumedErr(error)
+                        } else {
+                            EmptyErr(ParseError::empty(start))
+                        };
                     }
                     consumed = true;
                     input = rest.into_inner();
                 }
                 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)
+                        }
+                    })
                 }
             }
         }
@@ -319,9 +333,10 @@ impl<C, T, I> Parser for Tokens<C, T, I>
 /// ```
 #[inline(always)]
 pub fn tokens<C, T, I>(cmp: C, expected: Info<I::Item, I::Range>, tokens: T) -> Tokens<C, T, I>
-    where C: FnMut(T::Item, I::Item) -> bool,
-          T: Clone + IntoIterator,
-          I: Stream
+where
+    C: FnMut(T::Item, I::Item) -> bool,
+    T: Clone + IntoIterator,
+    I: Stream,
 {
     Tokens {
         cmp: cmp,
@@ -334,13 +349,15 @@ pub fn tokens<C, T, I>(cmp: C, expected: Info<I::Item, I::Range>, tokens: T) ->
 
 #[derive(Clone)]
 pub struct Position<I>
-    where I: Stream
+where
+    I: Stream,
 {
     _marker: PhantomData<I>,
 }
 
 impl<I> Parser for Position<I>
-    where I: Stream
+where
+    I: Stream,
 {
     type Input = I;
     type Output = I::Position;
@@ -368,18 +385,22 @@ impl<I> Parser for Position<I>
 /// ```
 #[inline(always)]
 pub fn position<I>() -> Position<I>
-    where I: Stream
+where
+    I: Stream,
 {
-    Position { _marker: PhantomData }
+    Position {
+        _marker: PhantomData,
+    }
 }
 
 #[derive(Clone)]
 pub struct Choice<S, P>(S, PhantomData<P>);
 
 impl<I, O, S, P> Parser for Choice<S, P>
-    where I: Stream,
-          S: AsMut<[P]>,
-          P: Parser<Input = I, Output = O>
+where
+    I: Stream,
+    S: AsMut<[P]>,
+    P: Parser<Input = I, Output = O>,
 {
     type Input = I;
     type Output = O;
@@ -395,17 +416,18 @@ impl<I, O, S, P> Parser for Choice<S, P>
                         Some(prev_err) => Some(prev_err.merge(err)),
                     };
                 }
-                ok @ ConsumedOk(_) |
-                ok @ EmptyOk(_) => return ok,
+                ok @ ConsumedOk(_) | ok @ EmptyOk(_) => return ok,
             }
         }
         EmptyErr(match empty_err {
-                     None => {
-                         ParseError::new(input.position(),
-                                         Error::Message("parser choice is empty".into()))
-                     }
-                     Some(err) => err,
-                 })
+            None => {
+                ParseError::new(
+                    input.position(),
+                    Error::Message("parser choice is empty".into()),
+                )
+            }
+            Some(err) => err,
+        })
     }
     fn add_error(&mut self, error: &mut ParseError<Self::Input>) {
         for p in self.0.as_mut() {
@@ -416,16 +438,18 @@ impl<I, O, S, P> Parser for Choice<S, P>
 
 #[derive(Clone)]
 pub struct OneOf<T, I>
-    where I: Stream
+where
+    I: Stream,
 {
     tokens: T,
     _marker: PhantomData<I>,
 }
 
 impl<T, I> Parser for OneOf<T, I>
-    where T: Clone + IntoIterator<Item = I::Item>,
-          I: Stream,
-          I::Item: PartialEq
+where
+    T: Clone + IntoIterator<Item = I::Item>,
+    I: Stream,
+    I::Item: PartialEq,
 {
     type Input = I;
     type Output = I::Item;
@@ -456,9 +480,10 @@ impl<T, I> Parser for OneOf<T, I>
 /// ```
 #[inline(always)]
 pub fn one_of<T, I>(tokens: T) -> OneOf<T, I>
-    where T: Clone + IntoIterator,
-          I: Stream,
-          I::Item: PartialEq<T::Item>
+where
+    T: Clone + IntoIterator,
+    I: Stream,
+    I::Item: PartialEq<T::Item>,
 {
     OneOf {
         tokens: tokens,
@@ -468,16 +493,18 @@ pub fn one_of<T, I>(tokens: T) -> OneOf<T, I>
 
 #[derive(Clone)]
 pub struct NoneOf<T, I>
-    where I: Stream
+where
+    I: Stream,
 {
     tokens: T,
     _marker: PhantomData<I>,
 }
 
 impl<T, I> Parser for NoneOf<T, I>
-    where T: Clone + IntoIterator<Item = I::Item>,
-          I: Stream,
-          I::Item: PartialEq
+where
+    T: Clone + IntoIterator<Item = I::Item>,
+    I: Stream,
+    I::Item: PartialEq,
 {
     type Input = I;
     type Output = I::Item;
@@ -511,9 +538,10 @@ impl<T, I> Parser for NoneOf<T, I>
 /// ```
 #[inline(always)]
 pub fn none_of<T, I>(tokens: T) -> NoneOf<T, I>
-    where T: Clone + IntoIterator,
-          I: Stream,
-          I::Item: PartialEq<T::Item>
+where
+    T: Clone + IntoIterator,
+    I: Stream,
+    I::Item: PartialEq<T::Item>,
 {
     NoneOf {
         tokens: tokens,
@@ -529,8 +557,9 @@ pub struct Count<F, P> {
 }
 
 impl<P, F> Parser for Count<F, P>
-    where P: Parser,
-          F: FromIterator<P::Output>
+where
+    P: Parser,
+    F: FromIterator<P::Output>,
 {
     type Input = P::Input;
     type Output = F;
@@ -562,8 +591,9 @@ impl<P, F> Parser for Count<F, P>
 /// ```
 #[inline(always)]
 pub fn count<F, P>(count: usize, parser: P) -> Count<F, P>
-    where P: Parser,
-          F: FromIterator<P::Output>
+where
+    P: Parser,
+    F: FromIterator<P::Output>,
 {
     Count {
         parser: parser,
@@ -598,8 +628,9 @@ pub fn count<F, P>(count: usize, parser: P) -> Count<F, P>
 /// ```
 #[inline(always)]
 pub fn choice<S, P>(ps: S) -> Choice<S, P>
-    where S: AsMut<[P]>,
-          P: Parser
+where
+    S: AsMut<[P]>,
+    P: Parser,
 {
     Choice(ps, PhantomData)
 }
@@ -634,9 +665,12 @@ macro_rules! choice {
 }
 
 #[derive(Clone)]
-pub struct Unexpected<I>(Info<I::Item, I::Range>, PhantomData<fn(I) -> I>) where I: Stream;
+pub struct Unexpected<I>(Info<I::Item, I::Range>, PhantomData<fn(I) -> I>)
+where
+    I: Stream;
 impl<I> Parser for Unexpected<I>
-    where I: Stream
+where
+    I: Stream,
 {
     type Input = I;
     type Output = ();
@@ -664,8 +698,9 @@ impl<I> Parser for Unexpected<I>
 /// ```
 #[inline(always)]
 pub fn unexpected<I, S>(message: S) -> Unexpected<I>
-    where I: Stream,
-          S: Into<Info<I::Item, I::Range>>
+where
+    I: Stream,
+    S: Into<Info<I::Item, I::Range>>,
 {
     Unexpected(message.into(), PhantomData)
 }
@@ -673,8 +708,9 @@ pub fn unexpected<I, S>(message: S) -> Unexpected<I>
 #[derive(Clone)]
 pub struct Value<I, T>(T, PhantomData<fn(I) -> I>);
 impl<I, T> Parser for Value<I, T>
-    where I: Stream,
-          T: Clone
+where
+    I: Stream,
+    T: Clone,
 {
     type Input = I;
     type Output = T;
@@ -698,8 +734,9 @@ impl<I, T> Parser for Value<I, T>
 /// ```
 #[inline(always)]
 pub fn value<I, T>(v: T) -> Value<I, T>
-    where I: Stream,
-          T: Clone
+where
+    I: Stream,
+    T: Clone,
 {
     Value(v, PhantomData)
 }
@@ -725,8 +762,9 @@ impl_parser! { NotFollowedBy(P,),
 /// ```
 #[inline(always)]
 pub fn not_followed_by<P>(parser: P) -> NotFollowedBy<P>
-    where P: Parser,
-          P::Output: ::std::fmt::Display
+where
+    P: Parser,
+    P::Output: ::std::fmt::Display,
 {
     fn f<T: ::std::fmt::Display, I: Stream>(t: T) -> Unexpected<I> {
         unexpected(format!("{}", t))
@@ -738,7 +776,8 @@ pub fn not_followed_by<P>(parser: P) -> NotFollowedBy<P>
 #[derive(Clone)]
 pub struct Eof<I>(PhantomData<I>);
 impl<I> Parser for Eof<I>
-    where I: Stream
+where
+    I: Stream,
 {
     type Input = I;
     type Output = ();
@@ -776,7 +815,8 @@ impl<I> Parser for Eof<I>
 /// ```
 #[inline(always)]
 pub fn eof<I>() -> Eof<I>
-    where I: Stream
+where
+    I: Stream,
 {
     Eof(PhantomData)
 }
@@ -848,17 +888,19 @@ impl<P: Parser> Iterator for Iter<P> {
                     }
                 }
             }
-            State::ConsumedErr(_) |
-            State::EmptyErr => None,
+            State::ConsumedErr(_) | State::EmptyErr => None,
         }
     }
 }
 
 #[derive(Clone)]
-pub struct Many<F, P>(P, PhantomData<F>) where P: Parser;
+pub struct Many<F, P>(P, PhantomData<F>)
+where
+    P: Parser;
 impl<F, P> Parser for Many<F, P>
-    where P: Parser,
-          F: FromIterator<P::Output>
+where
+    P: Parser,
+    F: FromIterator<P::Output>,
 {
     type Input = P::Input;
     type Output = F;
@@ -888,8 +930,9 @@ impl<F, P> Parser for Many<F, P>
 /// ```
 #[inline(always)]
 pub fn many<F, P>(p: P) -> Many<F, P>
-    where P: Parser,
-          F: FromIterator<P::Output>
+where
+    P: Parser,
+    F: FromIterator<P::Output>,
 {
     Many(p, PhantomData)
 }
@@ -898,8 +941,9 @@ pub fn many<F, P>(p: P) -> Many<F, P>
 #[derive(Clone)]
 pub struct Many1<F, P>(P, PhantomData<fn() -> F>);
 impl<F, P> Parser for Many1<F, P>
-    where F: FromIterator<P::Output>,
-          P: Parser
+where
+    F: FromIterator<P::Output>,
+    P: Parser,
 {
     type Input = P::Input;
     type Output = F;
@@ -936,7 +980,8 @@ impl_parser!{ SkipMany(P,), Map<Many<Vec<()>, Map<P, fn (P::Output)>>, fn (Vec<(
 /// ```
 #[inline(always)]
 pub fn skip_many<P>(p: P) -> SkipMany<P>
-    where P: Parser
+where
+    P: Parser,
 {
     fn ignore<T>(_: T) {}
     let ignore1: fn(P::Output) = ignore;
@@ -960,7 +1005,8 @@ impl_parser!{ SkipMany1(P,), Map<Many1<Vec<()>, Map<P, fn (P::Output)>>, fn (Vec
 /// ```
 #[inline(always)]
 pub fn skip_many1<P>(p: P) -> SkipMany1<P>
-    where P: Parser
+where
+    P: Parser,
 {
     fn ignore<T>(_: T) {}
     let ignore1: fn(P::Output) = ignore;
@@ -987,8 +1033,9 @@ pub fn skip_many1<P>(p: P) -> SkipMany1<P>
 /// ```
 #[inline(always)]
 pub fn many1<F, P>(p: P) -> Many1<F, P>
-    where F: FromIterator<P::Output>,
-          P: Parser
+where
+    F: FromIterator<P::Output>,
+    P: Parser,
 {
     Many1(p, PhantomData)
 }
@@ -1000,9 +1047,10 @@ pub struct SepBy<F, P, S> {
     _marker: PhantomData<fn() -> F>,
 }
 impl<F, P, S> Parser for SepBy<F, P, S>
-    where F: FromIterator<P::Output>,
-          P: Parser,
-          S: Parser<Input = P::Input>
+where
+    F: FromIterator<P::Output>,
+    P: Parser,
+    S: Parser<Input = P::Input>,
 {
     type Input = P::Input;
     type Output = F;
@@ -1010,7 +1058,9 @@ impl<F, P, S> Parser for SepBy<F, P, S>
     #[inline]
     fn parse_lazy(&mut self, input: P::Input) -> ConsumedResult<F, P::Input> {
         sep_by1(&mut self.parser, &mut self.separator)
-            .or(parser(|input| Ok((None.into_iter().collect(), Consumed::Empty(input)))))
+            .or(parser(|input| {
+                Ok((None.into_iter().collect(), Consumed::Empty(input)))
+            }))
             .parse_lazy(input)
     }
 
@@ -1040,9 +1090,10 @@ impl<F, P, S> Parser for SepBy<F, P, S>
 /// ```
 #[inline(always)]
 pub fn sep_by<F, P, S>(parser: P, separator: S) -> SepBy<F, P, S>
-    where F: FromIterator<P::Output>,
-          P: Parser,
-          S: Parser<Input = P::Input>
+where
+    F: FromIterator<P::Output>,
+    P: Parser,
+    S: Parser<Input = P::Input>,
 {
     SepBy {
         parser: parser,
@@ -1058,9 +1109,10 @@ pub struct SepBy1<F, P, S> {
     _marker: PhantomData<fn() -> F>,
 }
 impl<F, P, S> Parser for SepBy1<F, P, S>
-    where F: FromIterator<P::Output>,
-          P: Parser,
-          S: Parser<Input = P::Input>
+where
+    F: FromIterator<P::Output>,
+    P: Parser,
+    S: Parser<Input = P::Input>,
 {
     type Input = P::Input;
     type Output = F;
@@ -1070,12 +1122,11 @@ 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>) {
@@ -1112,9 +1163,10 @@ impl<F, P, S> Parser for SepBy1<F, P, S>
 /// ```
 #[inline(always)]
 pub fn sep_by1<F, P, S>(parser: P, separator: S) -> SepBy1<F, P, S>
-    where F: FromIterator<P::Output>,
-          P: Parser,
-          S: Parser<Input = P::Input>
+where
+    F: FromIterator<P::Output>,
+    P: Parser,
+    S: Parser<Input = P::Input>,
 {
     SepBy1 {
         parser: parser,
@@ -1131,9 +1183,10 @@ pub struct SepEndBy<F, P, S> {
 }
 
 impl<F, P, S> Parser for SepEndBy<F, P, S>
-    where F: FromIterator<P::Output>,
-          P: Parser,
-          S: Parser<Input = P::Input>
+where
+    F: FromIterator<P::Output>,
+    P: Parser,
+    S: Parser<Input = P::Input>,
 {
     type Input = P::Input;
     type Output = F;
@@ -1141,7 +1194,9 @@ impl<F, P, S> Parser for SepEndBy<F, P, S>
     #[inline]
     fn parse_lazy(&mut self, input: P::Input) -> ConsumedResult<F, P::Input> {
         sep_end_by1(&mut self.parser, &mut self.separator)
-            .or(parser(|input| Ok((None.into_iter().collect(), Consumed::Empty(input)))))
+            .or(parser(|input| {
+                Ok((None.into_iter().collect(), Consumed::Empty(input)))
+            }))
             .parse_lazy(input)
     }
 
@@ -1171,9 +1226,10 @@ impl<F, P, S> Parser for SepEndBy<F, P, S>
 /// ```
 #[inline(always)]
 pub fn sep_end_by<F, P, S>(parser: P, separator: S) -> SepEndBy<F, P, S>
-    where F: FromIterator<P::Output>,
-          P: Parser,
-          S: Parser<Input = P::Input>
+where
+    F: FromIterator<P::Output>,
+    P: Parser,
+    S: Parser<Input = P::Input>,
 {
     SepEndBy {
         parser: parser,
@@ -1190,9 +1246,10 @@ pub struct SepEndBy1<F, P, S> {
 }
 
 impl<F, P, S> Parser for SepEndBy1<F, P, S>
-    where F: FromIterator<P::Output>,
-          P: Parser,
-          S: Parser<Input = P::Input>
+where
+    F: FromIterator<P::Output>,
+    P: Parser,
+    S: Parser<Input = P::Input>,
 {
     type Input = P::Input;
     type Output = F;
@@ -1249,9 +1306,10 @@ impl<F, P, S> Parser for SepEndBy1<F, P, S>
 /// ```
 #[inline(always)]
 pub fn sep_end_by1<F, P, S>(parser: P, separator: S) -> SepEndBy1<F, P, S>
-    where F: FromIterator<P::Output>,
-          P: Parser,
-          S: Parser<Input = P::Input>
+where
+    F: FromIterator<P::Output>,
+    P: Parser,
+    S: Parser<Input = P::Input>,
 {
     SepEndBy1 {
         parser: parser,
@@ -1304,15 +1362,17 @@ pub struct FnParser<I, F>(F, PhantomData<fn(I) -> I>);
 /// ```
 #[inline(always)]
 pub fn parser<I, O, F>(f: F) -> FnParser<I, F>
-    where I: Stream,
-          F: FnMut(I) -> ParseResult<O, I>
+where
+    I: Stream,
+    F: FnMut(I) -> ParseResult<O, I>,
 {
     FnParser(f, PhantomData)
 }
 
 impl<I, O, F> Parser for FnParser<I, F>
-    where I: Stream,
-          F: FnMut(I) -> ParseResult<O, I>
+where
+    I: Stream,
+    F: FnMut(I) -> ParseResult<O, I>,
 {
     type Input = I;
     type Output = O;
@@ -1322,7 +1382,8 @@ impl<I, O, F> Parser for FnParser<I, F>
 }
 
 impl<I, O> Parser for fn(I) -> ParseResult<O, I>
-    where I: Stream
+where
+    I: Stream,
 {
     type Input = I;
     type Output = O;
@@ -1334,7 +1395,8 @@ impl<I, O> Parser for fn(I) -> ParseResult<O, I>
 #[derive(Clone)]
 pub struct Optional<P>(P);
 impl<P> Parser for Optional<P>
-    where P: Parser
+where
+    P: Parser,
 {
     type Input = P::Input;
     type Output = Option<P::Output>;
@@ -1365,7 +1427,8 @@ impl<P> Parser for Optional<P>
 /// ```
 #[inline(always)]
 pub fn optional<P>(parser: P) -> Optional<P>
-    where P: Parser
+where
+    P: Parser,
 {
     Optional(parser)
 }
@@ -1387,10 +1450,11 @@ impl_parser! { Between(L, R, P), Skip<With<L, P>, R> }
 /// ```
 #[inline(always)]
 pub fn between<I, L, R, P>(open: L, close: R, parser: P) -> Between<L, R, P>
-    where I: Stream,
-          L: Parser<Input = I>,
-          R: Parser<Input = I>,
-          P: Parser<Input = I>
+where
+    I: Stream,
+    L: Parser<Input = I>,
+    R: Parser<Input = I>,
+    P: Parser<Input = I>,
 {
     Between(open.with(parser).skip(close))
 }
@@ -1398,10 +1462,11 @@ pub fn between<I, L, R, P>(open: L, close: R, parser: P) -> Between<L, R, P>
 #[derive(Clone)]
 pub struct Chainl1<P, Op>(P, Op);
 impl<I, P, Op> Parser for Chainl1<P, Op>
-    where I: Stream,
-          P: Parser<Input = I>,
-          Op: Parser<Input = I>,
-          Op::Output: FnOnce(P::Output, P::Output) -> P::Output
+where
+    I: Stream,
+    P: Parser<Input = I>,
+    Op: Parser<Input = I>,
+    Op::Output: FnOnce(P::Output, P::Output) -> P::Output,
 {
     type Input = I;
     type Output = P::Output;
@@ -1411,8 +1476,8 @@ impl<I, P, Op> Parser for Chainl1<P, Op>
         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() {
+                .parse_lazy(input.clone().into_inner())
+                .into() {
                 Ok(((op, r), rest)) => {
                     l = op(l, r);
                     input = input.merge(rest);
@@ -1445,9 +1510,10 @@ impl<I, P, Op> Parser for Chainl1<P, Op>
 /// ```
 #[inline(always)]
 pub fn chainl1<P, Op>(parser: P, op: Op) -> Chainl1<P, Op>
-    where P: Parser,
-          Op: Parser<Input = P::Input>,
-          Op::Output: FnOnce(P::Output, P::Output) -> P::Output
+where
+    P: Parser,
+    Op: Parser<Input = P::Input>,
+    Op::Output: FnOnce(P::Output, P::Output) -> P::Output,
 {
     Chainl1(parser, op)
 }
@@ -1455,10 +1521,11 @@ pub fn chainl1<P, Op>(parser: P, op: Op) -> Chainl1<P, Op>
 #[derive(Clone)]
 pub struct Chainr1<P, Op>(P, Op);
 impl<I, P, Op> Parser for Chainr1<P, Op>
-    where I: Stream,
-          P: Parser<Input = I>,
-          Op: Parser<Input = I>,
-          Op::Output: FnOnce(P::Output, P::Output) -> P::Output
+where
+    I: Stream,
+    P: Parser<Input = I>,
+    Op: Parser<Input = I>,
+    Op::Output: FnOnce(P::Output, P::Output) -> P::Output,
 {
     type Input = I;
     type Output = P::Output;
@@ -1507,9 +1574,10 @@ impl<I, P, Op> Parser for Chainr1<P, Op>
 /// ```
 #[inline(always)]
 pub fn chainr1<P, Op>(parser: P, op: Op) -> Chainr1<P, Op>
-    where P: Parser,
-          Op: Parser<Input = P::Input>,
-          Op::Output: FnOnce(P::Output, P::Output) -> P::Output
+where
+    P: Parser,
+    Op: Parser<Input = P::Input>,
+    Op::Output: FnOnce(P::Output, P::Output) -> P::Output,
 {
     Chainr1(parser, op)
 }
@@ -1517,20 +1585,15 @@ pub fn chainr1<P, Op>(parser: P, op: Op) -> Chainr1<P, Op>
 #[derive(Clone)]
 pub struct Try<P>(P);
 impl<I, O, P> Parser for Try<P>
-    where I: Stream,
-          P: Parser<Input = I, Output = O>
+where
+    I: Stream,
+    P: Parser<Input = I, Output = O>,
 {
     type Input = I;
     type Output = O;
     #[inline]
-    fn parse_lazy(&mut self, input: I) -> ConsumedResult<O, I> {
-        self.0
-            .parse_stream(input)
-            .map_err(Consumed::into_empty)
-            .into()
-    }
-    fn add_error(&mut self, errors: &mut ParseError<Self::Input>) {
-        self.0.add_error(errors)
+    fn parse_stream(&mut self, input: I) -> ParseResult<O, I> {
+        self.0.parse_stream(input).map_err(Consumed::into_empty)
     }
 }
 
@@ -1552,7 +1615,8 @@ impl<I, O, P> Parser for Try<P>
 /// ```
 #[inline(always)]
 pub fn try<P>(p: P) -> Try<P>
-    where P: Parser
+where
+    P: Parser,
 {
     Try(p)
 }
@@ -1561,8 +1625,9 @@ pub fn try<P>(p: P) -> Try<P>
 pub struct LookAhead<P>(P);
 
 impl<I, O, P> Parser for LookAhead<P>
-    where I: Stream,
-          P: Parser<Input = I, Output = O>
+where
+    I: Stream,
+    P: Parser<Input = I, Output = O>,
 {
     type Input = I;
     type Output = O;
@@ -1596,19 +1661,22 @@ impl<I, O, P> Parser for LookAhead<P>
 /// ```
 #[inline(always)]
 pub fn look_ahead<P>(p: P) -> LookAhead<P>
-    where P: Parser
+where
+    P: Parser,
 {
     LookAhead(p)
 }
 
 #[derive(Clone)]
 pub struct With<P1, P2>((P1, P2))
-    where P1: Parser,
-          P2: Parser;
+where
+    P1: Parser,
+    P2: Parser;
 impl<I, P1, P2> Parser for With<P1, P2>
-    where I: Stream,
-          P1: Parser<Input = I>,
-          P2: Parser<Input = I>
+where
+    I: Stream,
+    P1: Parser<Input = I>,
+    P2: Parser<Input = I>,
 {
     type Input = I;
     type Output = P2::Output;
@@ -1626,20 +1694,23 @@ impl<I, P1, P2> Parser for With<P1, P2>
 /// [`p1.with(p2)`]: ../primitives/trait.Parser.html#method.with
 #[inline(always)]
 pub fn with<P1, P2>(p1: P1, p2: P2) -> With<P1, P2>
-    where P1: Parser,
-          P2: Parser<Input = P1::Input>
+where
+    P1: Parser,
+    P2: Parser<Input = P1::Input>,
 {
     With((p1, p2))
 }
 
 #[derive(Clone)]
 pub struct Skip<P1, P2>((P1, P2))
-    where P1: Parser,
-          P2: Parser;
+where
+    P1: Parser,
+    P2: Parser;
 impl<I, P1, P2> Parser for Skip<P1, P2>
-    where I: Stream,
-          P1: Parser<Input = I>,
-          P2: Parser<Input = I>
+where
+    I: Stream,
+    P1: Parser<Input = I>,
+    P2: Parser<Input = I>,
 {
     type Input = I;
     type Output = P1::Output;
@@ -1654,18 +1725,24 @@ impl<I, P1, P2> Parser for Skip<P1, P2>
 
 #[inline(always)]
 pub fn skip<P1, P2>(p1: P1, p2: P2) -> Skip<P1, P2>
-    where P1: Parser,
-          P2: Parser<Input = P1::Input>
+where
+    P1: Parser,
+    P2: Parser<Input = P1::Input>,
 {
     Skip((p1, p2))
 }
 
 #[derive(Clone)]
-pub struct Message<P>(P, Info<<P::Input as StreamOnce>::Item, <P::Input as StreamOnce>::Range>)
-    where P: Parser;
+pub struct Message<P>(
+    P,
+    Info<<P::Input as StreamOnce>::Item, <P::Input as StreamOnce>::Range>,
+)
+where
+    P: Parser;
 impl<I, P> Parser for Message<P>
-    where I: Stream,
-          P: Parser<Input = I>
+where
+    I: Stream,
+    P: Parser<Input = I>,
 {
     type Input = I;
     type Output = P::Output;
@@ -1697,22 +1774,26 @@ impl<I, P> Parser for Message<P>
 ///
 /// [`p1.message(msg)`]: ../primitives/trait.Parser.html#method.message
 #[inline(always)]
-pub fn message<P>(p: P,
-                  msg: Info<<P::Input as StreamOnce>::Item, <P::Input as StreamOnce>::Range>)
-                  -> Message<P>
-    where P: Parser
+pub fn message<P>(
+    p: P,
+    msg: Info<<P::Input as StreamOnce>::Item, <P::Input as StreamOnce>::Range>,
+) -> Message<P>
+where
+    P: Parser,
 {
     Message(p, msg)
 }
 
 #[derive(Clone)]
 pub struct Or<P1, P2>(P1, P2)
-    where P1: Parser,
-          P2: Parser;
+where
+    P1: Parser,
+    P2: Parser;
 impl<I, O, P1, P2> Parser for Or<P1, P2>
-    where I: Stream,
-          P1: Parser<Input = I, Output = O>,
-          P2: Parser<Input = I, Output = O>
+where
+    I: Stream,
+    P1: Parser<Input = I, Output = O>,
+    P2: Parser<Input = I, Output = O>,
 {
     type Input = I;
     type Output = O;
@@ -1746,8 +1827,9 @@ impl<I, O, P1, P2> Parser for Or<P1, P2>
 /// [`p1.or(p2)`]: ../primitives/trait.Parser.html#method.or
 #[inline(always)]
 pub fn or<P1, P2>(p1: P1, p2: P2) -> Or<P1, P2>
-    where P1: Parser,
-          P2: Parser<Input = P1::Input, Output = P1::Output>
+where
+    P1: Parser,
+    P2: Parser<Input = P1::Input, Output = P1::Output>,
 {
     Or(p1, p2)
 }
@@ -1755,9 +1837,10 @@ pub fn or<P1, P2>(p1: P1, p2: P2) -> Or<P1, P2>
 #[derive(Clone)]
 pub struct Map<P, F>(P, F);
 impl<I, A, B, P, F> Parser for Map<P, F>
-    where I: Stream,
-          P: Parser<Input = I, Output = A>,
-          F: FnMut(A) -> B
+where
+    I: Stream,
+    P: Parser<Input = I, Output = A>,
+    F: FnMut(A) -> B,
 {
     type Input = I;
     type Output = B;
@@ -1780,8 +1863,9 @@ impl<I, A, B, P, F> Parser for Map<P, F>
 /// [`p.map(f)`]: ../primitives/trait.Parser.html#method.map
 #[inline(always)]
 pub fn map<P, F, B>(p: P, f: F) -> Map<P, F>
-    where P: Parser,
-          F: FnMut(P::Output) -> B
+where
+    P: Parser,
+    F: FnMut(P::Output) -> B,
 {
     Map(p, f)
 }
@@ -1789,9 +1873,10 @@ pub fn map<P, F, B>(p: P, f: F) -> Map<P, F>
 #[derive(Clone)]
 pub struct FlatMap<P, F>(P, F);
 impl<I, A, B, P, F> Parser for FlatMap<P, F>
-    where I: Stream,
-          P: Parser<Input = I, Output = A>,
-          F: FnMut(A) -> Result<B, ParseError<I>>
+where
+    I: Stream,
+    P: Parser<Input = I, Output = A>,
+    F: FnMut(A) -> Result<B, ParseError<I>>,
 {
     type Input = I;
     type Output = B;
@@ -1824,8 +1909,9 @@ impl<I, A, B, P, F> Parser for FlatMap<P, F>
 /// [`p.flat_map(f)`]: ../primitives/trait.Parser.html#method.flat_map
 #[inline(always)]
 pub fn flat_map<P, F, B>(p: P, f: F) -> FlatMap<P, F>
-    where P: Parser,
-          F: FnMut(P::Output) -> Result<B, ParseError<P::Input>>
+where
+    P: Parser,
+    F: FnMut(P::Output) -> Result<B, ParseError<P::Input>>,
 {
     FlatMap(p, f)
 }
@@ -1833,9 +1919,10 @@ pub fn flat_map<P, F, B>(p: P, f: F) -> FlatMap<P, F>
 #[derive(Clone)]
 pub struct Then<P, F>(P, F);
 impl<P, N, F> Parser for Then<P, F>
-    where F: FnMut(P::Output) -> N,
-          P: Parser,
-          N: Parser<Input = P::Input>
+where
+    F: FnMut(P::Output) -> N,
+    P: Parser,
+    N: Parser<Input = P::Input>,
 {
     type Input = N::Input;
     type Output = N::Output;
@@ -1867,35 +1954,28 @@ impl<P, N, F> Parser for Then<P, F>
 /// [`p.then(f)`]: ../primitives/trait.Parser.html#method.then
 #[inline(always)]
 pub fn then<P, F, N>(p: P, f: F) -> Then<P, F>
-    where F: FnMut(P::Output) -> N,
-          P: Parser,
-          N: Parser<Input = P::Input>
+where
+    F: FnMut(P::Output) -> N,
+    P: Parser,
+    N: Parser<Input = P::Input>,
 {
     Then(p, f)
 }
 
 #[derive(Clone)]
-pub struct Expected<P>(P, Info<<P::Input as StreamOnce>::Item, <P::Input as StreamOnce>::Range>)
-    where P: Parser;
+pub struct Expected<P>(
+    P,
+    Info<<P::Input as StreamOnce>::Item, <P::Input as StreamOnce>::Range>,
+)
+where
+    P: Parser;
 impl<P> Parser for Expected<P>
-    where P: Parser
+where
+    P: Parser,
 {
     type Input = P::Input;
     type Output = P::Output;
 
-    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
-                                    })
-                     })
-    }
-
     #[inline]
     fn parse_lazy(&mut self, input: Self::Input) -> ConsumedResult<Self::Output, Self::Input> {
         self.0.parse_lazy(input)
@@ -1904,20 +1984,18 @@ impl<P> Parser for Expected<P>
     fn add_error(&mut self, errors: &mut ParseError<Self::Input>) {
         let start = errors.errors.len();
         self.0.add_error(errors);
-        // Replace all expected errors that where added from the previous add_error
+        // Replace all expected errors that were 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()));
     }
 }
@@ -1926,10 +2004,12 @@ impl<P> Parser for Expected<P>
 ///
 /// [`p.expected(info)`]: ../primitives/trait.Parser.html#method.expected
 #[inline(always)]
-pub fn expected<P>(p: P,
-                   info: Info<<P::Input as StreamOnce>::Item, <P::Input as StreamOnce>::Range>)
-                   -> Expected<P>
-    where P: Parser
+pub fn expected<P>(
+    p: P,
+    info: Info<<P::Input as StreamOnce>::Item, <P::Input as StreamOnce>::Range>,
+) -> Expected<P>
+where
+    P: Parser,
 {
     Expected(p, info)
 }
@@ -1937,9 +2017,10 @@ pub fn expected<P>(p: P,
 #[derive(Clone)]
 pub struct AndThen<P, F>(P, F);
 impl<P, F, O, E> Parser for AndThen<P, F>
-    where P: Parser,
-          F: FnMut(P::Output) -> Result<O, E>,
-          E: Into<Error<<P::Input as StreamOnce>::Item, <P::Input as StreamOnce>::Range>>
+where
+    P: Parser,
+    F: FnMut(P::Output) -> Result<O, E>,
+    E: Into<Error<<P::Input as StreamOnce>::Item, <P::Input as StreamOnce>::Range>>,
 {
     type Input = P::Input;
     type Output = O;
@@ -1972,9 +2053,10 @@ impl<P, F, O, E> Parser for AndThen<P, F>
 /// [`p.and_then(f)`]: ../primitives/trait.Parser.html#method.and_then
 #[inline(always)]
 pub fn and_then<P, F, O, E>(p: P, f: F) -> AndThen<P, F>
-    where P: Parser,
-          F: FnMut(P::Output) -> Result<O, E>,
-          E: Into<Error<<P::Input as StreamOnce>::Item, <P::Input as StreamOnce>::Range>>
+where
+    P: Parser,
+    F: FnMut(P::Output) -> Result<O, E>,
+    E: Into<Error<<P::Input as StreamOnce>::Item, <P::Input as StreamOnce>::Range>>,
 {
     AndThen(p, f)
 }
@@ -2059,15 +2141,17 @@ tuple_parser!(A, B, C, D, E, F, G, H, I, J, K, L);
 
 #[derive(Copy, Clone)]
 pub struct EnvParser<E, I, T>
-    where I: Stream
+where
+    I: Stream,
 {
     env: E,
     parser: fn(E, I) -> ParseResult<T, I>,
 }
 
 impl<E, I, O> Parser for EnvParser<E, I, O>
-    where E: Clone,
-          I: Stream
+where
+    E: Clone,
+    I: Stream,
 {
     type Input = I;
     type Output = O;
@@ -2115,8 +2199,9 @@ impl<E, I, O> Parser for EnvParser<E, I, O>
 /// ```
 #[inline(always)]
 pub fn env_parser<E, I, O>(env: E, parser: fn(E, I) -> ParseResult<O, I>) -> EnvParser<E, I, O>
-    where E: Clone,
-          I: Stream
+where
+    E: Clone,
+    I: Stream,
 {
     EnvParser {
         env: env,
@@ -2156,25 +2241,33 @@ mod tests {
             .message("message")
             .expected("N/A")
             .expected("my expected digit");
-        assert_eq!(parser.parse(State::new("a")),
-                   Err(ParseError {
-                           position: <char as Positioner>::start(),
-                           errors: vec![Error::Unexpected('a'.into()),
-                                        Error::Message("message".into()),
-                                        Error::Expected("my expected digit".into())],
-                       }));
+        assert_eq!(
+            parser.parse(State::new("a")),
+            Err(ParseError {
+                position: <char as Positioner>::start(),
+                errors: vec![
+                    Error::Unexpected('a'.into()),
+                    Error::Message("message".into()),
+                    Error::Expected("my expected digit".into()),
+                ],
+            })
+        );
     }
 
     #[test]
     fn tuple_parse_error() {
         let mut parser = (digit(), digit());
         let result = parser.parse(State::new("a"));
-        assert_eq!(result,
-                   Err(ParseError {
-                           position: <char as Positioner>::start(),
-                           errors: vec![Error::Unexpected('a'.into()),
-                                        Error::Expected("digit".into())],
-                       }));
+        assert_eq!(
+            result,
+            Err(ParseError {
+                position: <char as Positioner>::start(),
+                errors: vec![
+                    Error::Unexpected('a'.into()),
+                    Error::Expected("digit".into()),
+                ],
+            })
+        );
     }
 
     #[derive(Clone, PartialEq, Debug)]
@@ -2186,12 +2279,19 @@ 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() }][..])));
+        assert_eq!(
+            result,
+            Ok((
+                CloneOnly { s: "x".to_string() },
+                &[CloneOnly { s: "y".to_string() }][..]
+            ))
+        );
     }
 
     #[test]
@@ -2217,18 +2317,22 @@ mod tests {
         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())],
-                                 });
+            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())],
-                                    });
+            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);
@@ -2243,4 +2347,73 @@ mod tests {
     fn issue_99() {
         assert!(any().map(|_| ()).or(eof()).parse("").is_ok());
     }
+
+    #[test]
+    fn expected_tests() {
+        // Ensure `expected` replaces only empty errors, interacting with parse_lazy and
+        // parse_stream correctly on either side
+        let input = "hi";
+
+        let mut ok = char('h').expected("not expected");
+        let mut empty0 = char('o').expected("expected message");
+        let mut empty1 = char('o').expected("expected message").map(|x| x);
+        let mut empty2 = char('o').map(|x| x).expected("expected message");
+        let mut consumed0 = char('h').with(char('o')).expected("expected message");
+        let mut consumed1 = char('h')
+            .with(char('o'))
+            .expected("expected message")
+            .map(|x| x);
+        let mut consumed2 = char('h')
+            .with(char('o'))
+            .map(|x| x)
+            .expected("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("expected message".into()),
+            ],
+        });
+
+        let consumed_expected = Err(ParseError {
+            position: SourcePosition { line: 1, column: 2 },
+            errors: vec![Error::Unexpected('i'.into()), Error::Expected('o'.into())],
+        });
+
+        assert_eq!(empty0.parse(State::new(input)), empty_expected);
+        assert_eq!(empty1.parse(State::new(input)), empty_expected);
+        assert_eq!(empty2.parse(State::new(input)), empty_expected);
+
+        assert_eq!(consumed0.parse(State::new(input)), consumed_expected);
+        assert_eq!(consumed1.parse(State::new(input)), consumed_expected);
+        assert_eq!(consumed2.parse(State::new(input)), consumed_expected);
+    }
+
+    #[test]
+    fn try_tests() {
+        // Ensure try adds error messages exactly once
+        assert_eq!(
+            try(unexpected("test")).parse(State::new("hi")),
+            Err(ParseError {
+                position: SourcePosition { line: 1, column: 1 },
+                errors: vec![
+                    Error::Unexpected('h'.into()),
+                    Error::Unexpected("test".into()),
+                ],
+            })
+        );
+        assert_eq!(
+            try(char('h').with(unexpected("test"))).parse(State::new("hi")),
+            Err(ParseError {
+                position: SourcePosition { line: 1, column: 2 },
+                errors: vec![
+                    Error::Unexpected('i'.into()),
+                    Error::Unexpected("test".into()),
+                ],
+            })
+        );
+    }
 }
diff --git a/src/lib.rs b/src/lib.rs
index a5e3f39e..780203b4 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -221,11 +221,14 @@ mod tests {
 
 
     fn integer<'a, I>(input: I) -> ParseResult<i64, I>
-        where I: Stream<Item = char>
+    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);
@@ -270,9 +273,9 @@ mod tests {
             .map(|t| t.1)
             .parse_stream(State::new(source));
         let state = Consumed::Consumed(State {
-                                           position: SourcePosition { line: 3, column: 1 },
-                                           input: "",
-                                       });
+            position: SourcePosition { line: 3, column: 1 },
+            input: "",
+        });
         assert_eq!(result, Ok((123i64, state)));
     }
 
@@ -287,7 +290,8 @@ mod tests {
 
     #[allow(unconditional_recursion)]
     fn expr<I>(input: I) -> ParseResult<Expr, I>
-        where I: Stream<Item = char>
+    where
+        I: Stream<Item = char>,
     {
         let word = many1(letter()).expected("identifier");
         let integer = parser(integer);
@@ -296,10 +300,12 @@ mod tests {
         let spaces = spaces();
         spaces
             .clone()
-            .with(word.map(Expr::Id)
-                      .or(integer.map(Expr::Int))
-                      .or(array.map(Expr::Array))
-                      .or(paren_expr))
+            .with(
+                word.map(Expr::Id)
+                    .or(integer.map(Expr::Int))
+                    .or(array.map(Expr::Array))
+                    .or(paren_expr),
+            )
             .skip(spaces)
             .parse_stream(input)
     }
@@ -307,9 +313,11 @@ mod tests {
     #[test]
     fn expression() {
         let result = sep_by(parser(expr), char(',')).parse("int, 100, [[], 123]");
-        let exprs = vec![Expr::Id("int".to_string()),
-                         Expr::Int(100),
-                         Expr::Array(vec![Expr::Array(vec![]), Expr::Int(123)])];
+        let exprs = vec![
+            Expr::Id("int".to_string()),
+            Expr::Int(100),
+            Expr::Array(vec![Expr::Array(vec![]), Expr::Int(123)]),
+        ];
         assert_eq!(result, Ok((exprs, "")));
     }
 
@@ -321,17 +329,20 @@ mod tests {
         let result = parser(expr).parse(State::new(input));
         let err = ParseError {
             position: SourcePosition { line: 2, column: 1 },
-            errors: vec![Error::Unexpected(','.into()),
-                         Error::Expected("integer".into()),
-                         Error::Expected("identifier".into()),
-                         Error::Expected("[".into()),
-                         Error::Expected("(".into())],
+            errors: vec![
+                Error::Unexpected(','.into()),
+                Error::Expected("integer".into()),
+                Error::Expected("identifier".into()),
+                Error::Expected("[".into()),
+                Error::Expected("(".into()),
+            ],
         };
         assert_eq!(result, Err(err));
     }
 
     fn term<I>(input: I) -> ParseResult<Expr, I>
-        where I: Stream<Item = char>
+    where
+        I: Stream<Item = char>,
     {
         fn times(l: Expr, r: Expr) -> Expr {
             Expr::Times(Box::new(l), Box::new(r))
@@ -353,8 +364,10 @@ mod tests {
         let (result, _) = parser(term).parse(State::new(input)).unwrap();
 
         let e1 = Expr::Times(Box::new(Expr::Int(1)), Box::new(Expr::Int(2)));
-        let e2 = Expr::Times(Box::new(Expr::Int(3)),
-                             Box::new(Expr::Id("test".to_string())));
+        let e2 = Expr::Times(
+            Box::new(Expr::Int(3)),
+            Box::new(Expr::Id("test".to_string())),
+        );
         assert_eq!(result, Expr::Plus(Box::new(e1), Box::new(e2)));
     }
 
@@ -437,12 +450,14 @@ mod tests {
 
     #[test]
     fn choice_strings() {
-        let mut fruits = [try(string("Apple")),
-                          try(string("Banana")),
-                          try(string("Cherry")),
-                          try(string("Date")),
-                          try(string("Fig")),
-                          try(string("Grape"))];
+        let mut fruits = [
+            try(string("Apple")),
+            try(string("Banana")),
+            try(string("Cherry")),
+            try(string("Date")),
+            try(string("Fig")),
+            try(string("Grape")),
+        ];
         let mut parser = choice(&mut fruits);
         assert_eq!(parser.parse("Apple"), Ok(("Apple", "")));
         assert_eq!(parser.parse("Banana"), Ok(("Banana", "")));
@@ -473,9 +488,9 @@ mod tests {
         assert!(result.is_err());
         // Test that ParseError can be coerced to a StdError
         let _ = result.map_err(|err| {
-                                   let err: Box<StdError> = Box::new(err);
-                                   err
-                               });
+            let err: Box<StdError> = Box::new(err);
+            err
+        });
     }
 
     #[test]
@@ -528,24 +543,26 @@ mod tests {
             .parse(input)
             .map_err(|e| e.translate_position(input))
             .map_err(|e| {
-                ExtractedError(e.position,
-                               DisplayVec(e.errors
-                                              .into_iter()
-                                              .map(|e| {
-                                                       e.map_range(|r| DisplayVec(r.to_owned()))
-                                                   })
-                                              .collect()))
+                ExtractedError(
+                    e.position,
+                    DisplayVec(
+                        e.errors
+                            .into_iter()
+                            .map(|e| e.map_range(|r| DisplayVec(r.to_owned())))
+                            .collect(),
+                    ),
+                )
             });
 
         assert!(result.is_err());
         // 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 be805645..31b75b83 100644
--- a/src/primitives.rs
+++ b/src/primitives.rs
@@ -60,7 +60,8 @@ pub enum Info<T, R> {
 
 impl<T, R> Info<T, R> {
     pub fn map_token<F, U>(self, f: F) -> Info<U, R>
-        where F: FnOnce(T) -> U
+    where
+        F: FnOnce(T) -> U,
     {
         use self::Info::*;
         match self {
@@ -72,7 +73,8 @@ impl<T, R> Info<T, R> {
     }
 
     pub fn map_range<F, S>(self, f: F) -> Info<T, S>
-        where F: FnOnce(R) -> S
+    where
+        F: FnOnce(R) -> S,
     {
         use self::Info::*;
         match self {
@@ -140,7 +142,8 @@ pub enum Error<T, R> {
 
 impl<T, R> Error<T, R> {
     pub fn map_token<F, U>(self, f: F) -> Error<U, R>
-        where F: FnOnce(T) -> U
+    where
+        F: FnOnce(T) -> U,
     {
         use self::Error::*;
         match self {
@@ -152,7 +155,8 @@ impl<T, R> Error<T, R> {
     }
 
     pub fn map_range<F, S>(self, f: F) -> Error<T, S>
-        where F: FnOnce(R) -> S
+    where
+        F: FnOnce(R) -> S,
     {
         use self::Error::*;
         match self {
@@ -176,7 +180,8 @@ impl<T: PartialEq, R: PartialEq> PartialEq for Error<T, R> {
 }
 
 impl<E, T, R> From<E> for Error<T, R>
-    where E: StdError + 'static + Send + Sync
+where
+    E: StdError + 'static + Send + Sync,
 {
     fn from(e: E) -> Error<T, R> {
         Error::Other(Box::new(e))
@@ -211,18 +216,17 @@ impl<T, R> Error<T, R> {
     /// # }
     /// ```
     pub fn fmt_errors(errors: &[Error<T, R>], f: &mut fmt::Formatter) -> fmt::Result
-        where T: fmt::Display,
-              R: fmt::Display
+    where
+        T: fmt::Display,
+        R: fmt::Display,
     {
         // 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));
         }
@@ -230,12 +234,10 @@ 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() {
@@ -251,13 +253,10 @@ 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));
         }
@@ -281,8 +280,7 @@ pub enum Consumed<T> {
 impl<T> AsMut<T> for Consumed<T> {
     fn as_mut(&mut self) -> &mut T {
         match *self {
-            Consumed::Empty(ref mut t) |
-            Consumed::Consumed(ref mut t) => t,
+            Consumed::Empty(ref mut t) | Consumed::Consumed(ref mut t) => t,
         }
     }
 }
@@ -290,8 +288,7 @@ impl<T> AsMut<T> for Consumed<T> {
 impl<T> AsRef<T> for Consumed<T> {
     fn as_ref(&self) -> &T {
         match *self {
-            Consumed::Empty(ref t) |
-            Consumed::Consumed(ref t) => t,
+            Consumed::Empty(ref t) | Consumed::Consumed(ref t) => t,
         }
     }
 }
@@ -308,8 +305,7 @@ impl<T> Consumed<T> {
     /// Extracts the contained value.
     pub fn into_inner(self) -> T {
         match self {
-            Consumed::Empty(x) |
-            Consumed::Consumed(x) => x,
+            Consumed::Empty(x) | Consumed::Consumed(x) => x,
         }
     }
 
@@ -337,7 +333,8 @@ impl<T> Consumed<T> {
 
     /// Maps over the contained value without changing the consumed state.
     pub fn map<F, U>(self, f: F) -> Consumed<U>
-        where F: FnOnce(T) -> U
+    where
+        F: FnOnce(T) -> U,
     {
         match self {
             Consumed::Empty(x) => Consumed::Empty(f(x)),
@@ -392,8 +389,9 @@ impl<T> Consumed<T> {
     /// }
     /// ```
     pub fn combine<F, U, I>(self, f: F) -> ParseResult<U, I>
-        where F: FnOnce(T) -> ParseResult<U, I>,
-              I: StreamOnce
+    where
+        F: FnOnce(T) -> ParseResult<U, I>,
+        I: StreamOnce,
     {
         match self {
             Consumed::Consumed(x) => {
@@ -407,8 +405,9 @@ impl<T> Consumed<T> {
         }
     }
     pub fn combine_consumed<F, U, I>(self, f: F) -> ConsumedResult<U, I>
-        where F: FnOnce(T) -> ConsumedResult<U, I>,
-              I: StreamOnce
+    where
+        F: FnOnce(T) -> ConsumedResult<U, I>,
+        I: StreamOnce,
     {
         use self::FastResult::*;
         match self {
@@ -447,9 +446,10 @@ impl<S: StreamOnce> ParseError<S> {
     }
 
     /// Constructs a `ParseError` with multiple causes.
-    pub fn from_errors(position: S::Position,
-                       errors: Vec<Error<S::Item, S::Range>>)
-                       -> ParseError<S> {
+    pub fn from_errors(
+        position: S::Position,
+        errors: Vec<Error<S::Item, S::Range>>,
+    ) -> ParseError<S> {
         ParseError {
             position: position,
             errors: errors,
@@ -465,7 +465,8 @@ impl<S: StreamOnce> ParseError<S> {
     /// Adds a `Message` error, taking care not to add duplicated errors.
     #[deprecated(since = "2.3.0", note = "Use `add_error(Error::Message())` instead")]
     pub fn add_message<M>(&mut self, message: M)
-        where M: Into<Info<S::Item, S::Range>>
+    where
+        M: Into<Info<S::Item, S::Range>>,
     {
         self.add_error(Error::Message(message.into()));
     }
@@ -482,11 +483,10 @@ 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));
     }
 
@@ -529,7 +529,8 @@ impl<'s> ParseError<&'s str> {
 }
 
 impl<'s, T: 's> ParseError<&'s [T]>
-    where T: Clone + PartialEq
+where
+    T: Clone + PartialEq,
 {
     /// Converts the pointer-based position into an indexed position.
     ///
@@ -550,10 +551,11 @@ impl<'s, T: 's> ParseError<&'s [T]>
 }
 
 impl<S> StdError for ParseError<S>
-    where S: Stream,
-          S::Range: fmt::Display + fmt::Debug + Any,
-          S::Item: fmt::Display + fmt::Debug + Any,
-          S::Position: fmt::Display + fmt::Debug + Any
+where
+    S: Stream,
+    S::Range: fmt::Display + fmt::Debug + Any,
+    S::Item: fmt::Display + fmt::Debug + Any,
+    S::Position: fmt::Display + fmt::Debug + Any,
 {
     fn description(&self) -> &str {
         "parse error"
@@ -561,8 +563,9 @@ impl<S> StdError for ParseError<S>
 }
 
 impl<S> PartialEq for ParseError<S>
-    where S: Stream,
-          S::Position: PartialEq
+where
+    S: Stream,
+    S::Position: PartialEq,
 {
     fn eq(&self, other: &ParseError<S>) -> bool {
         self.position == other.position && self.errors == other.errors
@@ -570,24 +573,28 @@ impl<S> PartialEq for ParseError<S>
 }
 
 impl<S> fmt::Debug for ParseError<S>
-    where S: Stream,
-          S::Range: fmt::Debug,
-          S::Item: fmt::Debug,
-          S::Position: fmt::Debug
+where
+    S: Stream,
+    S::Range: fmt::Debug,
+    S::Item: fmt::Debug,
+    S::Position: fmt::Debug,
 {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        write!(f,
-               "ParseError {{ position: {:?}, errors: {:?} }}",
-               self.position,
-               self.errors)
+        write!(
+            f,
+            "ParseError {{ position: {:?}, errors: {:?} }}",
+            self.position,
+            self.errors
+        )
     }
 }
 
 impl<S> fmt::Display for ParseError<S>
-    where S: Stream,
-          S::Item: fmt::Display,
-          S::Range: fmt::Display,
-          S::Position: fmt::Display
+where
+    S: Stream,
+    S::Item: fmt::Display,
+    S::Range: fmt::Display,
+    S::Position: fmt::Display,
 {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         try!(writeln!(f, "Parse error at {}", self.position));
@@ -615,8 +622,9 @@ impl<T: fmt::Display, R: fmt::Display> fmt::Display for Error<T, R> {
 /// `Positioner` trait to update the position.
 #[derive(Clone, PartialEq)]
 pub struct State<I>
-    where I: Stream,
-          I::Item: Positioner
+where
+    I: Stream,
+    I::Item: Positioner,
 {
     /// The current position
     pub position: <I::Item as Positioner>::Position,
@@ -625,21 +633,25 @@ pub struct State<I>
 }
 
 impl<I> fmt::Debug for State<I>
-    where I: Stream + fmt::Debug,
-          I::Item: Positioner,
-          <I::Item as Positioner>::Position: fmt::Debug
+where
+    I: Stream + fmt::Debug,
+    I::Item: Positioner,
+    <I::Item as Positioner>::Position: fmt::Debug,
 {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        write!(f,
-               "State {{ position: {:?}, input: {:?} }}",
-               self.position,
-               self.input)
+        write!(
+            f,
+            "State {{ position: {:?}, input: {:?} }}",
+            self.position,
+            self.input
+        )
     }
 }
 
 impl<I> State<I>
-    where I: Stream,
-          I::Item: Positioner
+where
+    I: Stream,
+    I::Item: Positioner,
 {
     /// Creates a new `State<I>` from an input stream. Initializes the position to
     /// `Positioner::start()`.
@@ -652,8 +664,9 @@ impl<I> State<I>
 }
 
 impl<I> StreamOnce for State<I>
-    where I: Stream,
-          I::Item: Positioner
+where
+    I: Stream,
+    I::Item: Positioner,
 {
     type Item = I::Item;
     type Range = I::Range;
@@ -677,33 +690,32 @@ impl<I> StreamOnce for State<I>
 }
 
 impl<I, E> RangeStream for State<I>
-    where I: RangeStream<Item = E>,
-          I::Range: Range + Positioner<Position = E::Position>,
-          E: Positioner + Clone
+where
+    I: RangeStream<Item = E>,
+    I::Range: Range + Positioner<Position = E::Position>,
+    E: Positioner + Clone,
 {
     #[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]
     fn uncons_while<F>(&mut self, mut predicate: F) -> Result<I::Range, Error<I::Item, I::Range>>
-        where F: FnMut(I::Item) -> bool
+    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
+        })
     }
 }
 
@@ -738,16 +750,23 @@ pub trait StreamOnce {
 /// A stream of tokens which can be duplicated
 pub trait Stream: StreamOnce + Clone {}
 
-impl<I> Stream for I where I: StreamOnce + Clone {}
+impl<I> Stream for I
+where
+    I: StreamOnce + Clone,
+{
+}
 
 #[inline]
 pub fn uncons<I>(mut input: I) -> ParseResult<I::Item, I>
-    where I: Stream
+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)))
 }
 
@@ -760,15 +779,17 @@ pub trait RangeStream: Stream {
     /// Takes items from stream, testing each one with `predicate`.
     /// returns the range of items which passed `predicate`.
     fn uncons_while<F>(&mut self, f: F) -> Result<Self::Range, Error<Self::Item, Self::Range>>
-        where F: FnMut(Self::Item) -> bool;
+    where
+        F: FnMut(Self::Item) -> bool;
 }
 
 /// Removes items from the input while `predicate` returns `true`.
 #[inline]
 pub fn uncons_while<I, F>(mut input: I, predicate: F) -> ConsumedResult<I::Range, I>
-    where F: FnMut(I::Item) -> bool,
-          I: RangeStream,
-          I::Range: Range
+where
+    F: FnMut(I::Item) -> bool,
+    I: RangeStream,
+    I::Range: Range,
 {
     match input.uncons_while(predicate) {
         Err(err) => EmptyErr(ParseError::new(input.position(), err)),
@@ -796,7 +817,8 @@ pub trait Range {
 impl<'a> RangeStream for &'a str {
     #[inline]
     fn uncons_while<F>(&mut self, mut f: F) -> Result<&'a str, Error<char, &'a str>>
-        where F: FnMut(Self::Item) -> bool
+    where
+        F: FnMut(Self::Item) -> bool,
     {
         let mut chars = self.chars();
         while let Some(c) = chars.next() {
@@ -829,7 +851,9 @@ impl<'a> RangeStream for &'a str {
                 *self = remaining;
                 Ok(result)
             } else {
-                Err(Error::Message("uncons_range on non character boundary".into()))
+                Err(Error::Message(
+                    "uncons_range on non character boundary".into(),
+                ))
             }
         } else {
             Err(Error::end_of_input())
@@ -852,7 +876,8 @@ impl<'a, T> Range for &'a [T] {
 }
 
 impl<'a, T> RangeStream for &'a [T]
-    where T: Clone + PartialEq
+where
+    T: Clone + PartialEq,
 {
     #[inline]
     fn uncons_range(&mut self, size: usize) -> Result<&'a [T], Error<T, &'a [T]>> {
@@ -866,7 +891,8 @@ impl<'a, T> RangeStream for &'a [T]
     }
     #[inline]
     fn uncons_while<F>(&mut self, mut f: F) -> Result<&'a [T], Error<T, &'a [T]>>
-        where F: FnMut(Self::Item) -> bool
+    where
+        F: FnMut(Self::Item) -> bool,
     {
         let len = self.iter().take_while(|c| f((**c).clone())).count();
         let (result, remaining) = self.split_at(len);
@@ -899,7 +925,8 @@ impl<'a> StreamOnce for &'a str {
 }
 
 impl<'a, T> StreamOnce for &'a [T]
-    where T: Clone + PartialEq
+where
+    T: Clone + PartialEq,
 {
     type Item = T;
     type Range = &'a [T];
@@ -933,7 +960,8 @@ impl<'a, T> Clone for SliceStream<'a, T> {
 }
 
 impl<'a, T> StreamOnce for SliceStream<'a, T>
-    where T: Clone + PartialEq + 'a
+where
+    T: Clone + PartialEq + 'a,
 {
     type Item = &'a T;
     type Range = &'a [T];
@@ -957,7 +985,8 @@ impl<'a, T> StreamOnce for SliceStream<'a, T>
 }
 
 impl<'a, T> RangeStream for SliceStream<'a, T>
-    where T: Clone + PartialEq + 'a
+where
+    T: Clone + PartialEq + 'a,
 {
     #[inline]
     fn uncons_range(&mut self, size: usize) -> Result<&'a [T], Error<&'a T, &'a [T]>> {
@@ -972,7 +1001,8 @@ impl<'a, T> RangeStream for SliceStream<'a, T>
 
     #[inline]
     fn uncons_while<F>(&mut self, mut f: F) -> Result<&'a [T], Error<&'a T, &'a [T]>>
-        where F: FnMut(Self::Item) -> bool
+    where
+        F: FnMut(Self::Item) -> bool,
     {
         let len = self.0.iter().take_while(|c| f(*c)).count();
         let (range, rest) = self.0.split_at(len);
@@ -986,28 +1016,32 @@ impl<'a, T> RangeStream for SliceStream<'a, T>
 ///
 /// [`from_iter`]: fn.from_iter.html
 #[derive(Clone, Debug)]
-pub struct IteratorStream<I>(I, usize) where I: Iterator;
+pub struct IteratorStream<I>(I, usize)
+where
+    I: Iterator;
 
 
 impl<I> IteratorStream<I>
-    where I: Iterator
+where
+    I: Iterator,
 {
     /// Converts an `Iterator` into a stream.
-    pub fn new(iter: I) -> IteratorStream<I>
-    {
+    pub fn new(iter: I) -> IteratorStream<I> {
         IteratorStream(iter, 0)
     }
 }
 
-#[deprecated(since="2.4.0", note="please use `IteratorStream::new` instead")]
+#[deprecated(since = "2.4.0", note = "please use `IteratorStream::new` instead")]
 pub fn from_iter<I>(iter: I) -> IteratorStream<I>
-    where I: Iterator
+where
+    I: Iterator,
 {
     IteratorStream::new(iter)
 }
 
 impl<I> Iterator for IteratorStream<I>
-    where I: Iterator
+where
+    I: Iterator,
 {
     type Item = I::Item;
     fn next(&mut self) -> Option<I::Item> {
@@ -1022,7 +1056,8 @@ impl<I> Iterator for IteratorStream<I>
 }
 
 impl<I: Iterator> StreamOnce for IteratorStream<I>
-    where I::Item: Clone + PartialEq
+where
+    I::Item: Clone + PartialEq,
 {
     type Item = I::Item;
     type Range = I::Item;
@@ -1071,7 +1106,8 @@ impl<R: Read> StreamOnce for ReadStream<R> {
 }
 
 impl<R> ReadStream<R>
-    where R: Read
+where
+    R: Read,
 {
     /// Creates a `StreamOnce` instance from a value implementing `std::io::Read`.
     ///
@@ -1099,9 +1135,10 @@ impl<R> ReadStream<R>
     }
 }
 
-#[deprecated(since="2.4.0", note="please use `ReadStream::new` instead")]
+#[deprecated(since = "2.4.0", note = "please use `ReadStream::new` instead")]
 pub fn from_read<R>(read: R) -> ReadStream<R>
-    where R: Read
+where
+    R: Read,
 {
     ReadStream::new(read)
 }
@@ -1117,7 +1154,8 @@ pub trait Positioner: PartialEq {
 }
 
 impl<'a, T: ?Sized> Positioner for &'a T
-    where T: Positioner
+where
+    T: Positioner,
 {
     type Position = T::Position;
     fn start() -> T::Position {
@@ -1129,7 +1167,8 @@ impl<'a, T: ?Sized> Positioner for &'a T
 }
 
 impl<T> Positioner for [T]
-    where T: Positioner
+where
+    T: Positioner,
 {
     type Position = T::Position;
     fn start() -> T::Position {
@@ -1143,7 +1182,8 @@ impl<T> Positioner for [T]
 }
 
 impl<'a, T> Positioner for SliceStream<'a, T>
-    where T: Positioner + 'a
+where
+    T: Positioner + 'a,
 {
     type Position = T::Position;
     fn start() -> T::Position {
@@ -1213,7 +1253,8 @@ impl<T, E> FastResult<T, E> {
     }
 
     pub fn and_then<F, T2>(self, f: F) -> F::Output
-        where F: FnOnce(T) -> FastResult<T2, E>
+    where
+        F: FnOnce(T) -> FastResult<T2, E>,
     {
         match self {
             ConsumedOk(t) => {
@@ -1230,10 +1271,12 @@ impl<T, E> FastResult<T, E> {
 }
 
 impl<T, E> ConsumedResult<T, E>
-    where E: StreamOnce
+where
+    E: StreamOnce,
 {
     pub fn map<F, T2>(self, f: F) -> ConsumedResult<F::Output, E>
-        where F: FnOnce(T) -> T2
+    where
+        F: FnOnce(T) -> T2,
     {
         match self {
             ConsumedOk((t, i)) => ConsumedOk((f(t), i)),
@@ -1262,7 +1305,8 @@ impl<T, E> Into<Result<Consumed<T>, Consumed<E>>> for FastResult<T, E> {
 }
 
 impl<O, I> Into<ParseResult<O, I>> for ConsumedResult<O, I>
-    where I: StreamOnce
+where
+    I: StreamOnce,
 {
     fn into(self) -> ParseResult<O, I> {
         use self::FastResult::*;
@@ -1276,7 +1320,8 @@ impl<O, I> Into<ParseResult<O, I>> for ConsumedResult<O, I>
 }
 
 impl<O, I> From<ParseResult<O, I>> for ConsumedResult<O, I>
-    where I: StreamOnce
+where
+    I: StreamOnce,
 {
     fn from(result: ParseResult<O, I>) -> ConsumedResult<O, I> {
         use self::FastResult::*;
@@ -1314,9 +1359,10 @@ pub trait Parser {
     /// [`ParseError`] otherwise.
     ///
     /// [`ParseError`]: primitives/struct.ParseError.html
-    fn parse(&mut self,
-             input: Self::Input)
-             -> Result<(Self::Output, Self::Input), ParseError<Self::Input>> {
+    fn parse(
+        &mut self,
+        input: Self::Input,
+    ) -> Result<(Self::Output, Self::Input), ParseError<Self::Input>> {
         match self.parse_stream(input) {
             Ok((v, state)) => Ok((v, state.into_inner())),
             Err(error) => Err(error.into_inner()),
@@ -1346,9 +1392,10 @@ pub trait Parser {
     /// [`Consumed`]: primitives/enum.Consumed.html
     /// [`FastResult`]: primitives/enum.FastResult.html
     #[inline]
-    fn parse_stream_consumed(&mut self,
-                             mut input: Self::Input)
-                             -> ConsumedResult<Self::Output, Self::Input> {
+    fn parse_stream_consumed(
+        &mut self,
+        mut input: Self::Input,
+    ) -> ConsumedResult<Self::Output, Self::Input> {
         let mut result = self.parse_lazy(input.clone());
         if let FastResult::EmptyErr(ref mut error) = result {
             if let Ok(t) = input.uncons() {
@@ -1413,7 +1460,8 @@ pub trait Parser {
     /// }
     /// ```
     fn by_ref(&mut self) -> &mut Self
-        where Self: Sized
+    where
+        Self: Sized,
     {
         self
     }
@@ -1434,8 +1482,9 @@ pub trait Parser {
     /// # }
     /// ```
     fn with<P2>(self, p: P2) -> With<Self, P2>
-        where Self: Sized,
-              P2: Parser<Input = Self::Input>
+    where
+        Self: Sized,
+        P2: Parser<Input = Self::Input>,
     {
         with(self, p)
     }
@@ -1456,8 +1505,9 @@ pub trait Parser {
     /// # }
     /// ```
     fn skip<P2>(self, p: P2) -> Skip<Self, P2>
-        where Self: Sized,
-              P2: Parser<Input = Self::Input>
+    where
+        Self: Sized,
+        P2: Parser<Input = Self::Input>,
     {
         skip(self, p)
     }
@@ -1479,8 +1529,9 @@ pub trait Parser {
     /// # }
     /// ```
     fn and<P2>(self, p: P2) -> (Self, P2)
-        where Self: Sized,
-              P2: Parser<Input = Self::Input>
+    where
+        Self: Sized,
+        P2: Parser<Input = Self::Input>,
     {
         (self, p)
     }
@@ -1515,8 +1566,9 @@ pub trait Parser {
     ///
     /// [`choice!`]: ../macro.choice.html
     fn or<P2>(self, p: P2) -> Or<Self, P2>
-        where Self: Sized,
-              P2: Parser<Input = Self::Input, Output = Self::Output>
+    where
+        Self: Sized,
+        P2: Parser<Input = Self::Input, Output = Self::Output>,
     {
         or(self, p)
     }
@@ -1548,9 +1600,10 @@ pub trait Parser {
     /// # }
     /// ```
     fn then<N, F>(self, f: F) -> Then<Self, F>
-        where Self: Sized,
-              F: FnMut(Self::Output) -> N,
-              N: Parser<Input = Self::Input>
+    where
+        Self: Sized,
+        F: FnMut(Self::Output) -> N,
+        N: Parser<Input = Self::Input>,
     {
         then(self, f)
     }
@@ -1570,8 +1623,9 @@ pub trait Parser {
     /// # }
     /// ```
     fn map<F, B>(self, f: F) -> Map<Self, F>
-        where Self: Sized,
-              F: FnMut(Self::Output) -> B
+    where
+        Self: Sized,
+        F: FnMut(Self::Output) -> B,
     {
         map(self, f)
     }
@@ -1591,8 +1645,9 @@ pub trait Parser {
     /// # }
     /// ```
     fn flat_map<F, B>(self, f: F) -> FlatMap<Self, F>
-        where Self: Sized,
-              F: FnMut(Self::Output) -> Result<B, ParseError<Self::Input>>
+    where
+        Self: Sized,
+        F: FnMut(Self::Output) -> Result<B, ParseError<Self::Input>>,
     {
         flat_map(self, f)
     }
@@ -1618,8 +1673,9 @@ pub trait Parser {
     /// # }
     /// ```
     fn message<S>(self, msg: S) -> Message<Self>
-        where Self: Sized,
-              S: Into<Info<<Self::Input as StreamOnce>::Item, <Self::Input as StreamOnce>::Range>>
+    where
+        Self: Sized,
+        S: Into<Info<<Self::Input as StreamOnce>::Item, <Self::Input as StreamOnce>::Range>>,
     {
         message(self, msg.into())
     }
@@ -1642,8 +1698,9 @@ pub trait Parser {
     /// # }
     /// ```
     fn expected<S>(self, msg: S) -> Expected<Self>
-        where Self: Sized,
-              S: Into<Info<<Self::Input as StreamOnce>::Item, <Self::Input as StreamOnce>::Range>>
+    where
+        Self: Sized,
+        S: Into<Info<<Self::Input as StreamOnce>::Item, <Self::Input as StreamOnce>::Range>>,
     {
         expected(self, msg.into())
     }
@@ -1665,9 +1722,10 @@ pub trait Parser {
     /// # }
     /// ```
     fn and_then<F, O, E>(self, f: F) -> AndThen<Self, F>
-        where Self: Sized,
-              F: FnMut(Self::Output) -> Result<O, E>,
-              E: Into<Error<<Self::Input as StreamOnce>::Item, <Self::Input as StreamOnce>::Range>>
+    where
+        Self: Sized,
+        F: FnMut(Self::Output) -> Result<O, E>,
+        E: Into<Error<<Self::Input as StreamOnce>::Item, <Self::Input as StreamOnce>::Range>>,
     {
         and_then(self, f)
     }
@@ -1696,7 +1754,8 @@ pub trait Parser {
     ///
     /// [`many`]: ../combinator/fn.many.html
     fn iter(self, input: Self::Input) -> Iter<Self>
-        where Self: Sized
+    where
+        Self: Sized,
     {
         Iter::new(self, input)
     }
@@ -1719,14 +1778,16 @@ pub trait Parser {
     /// # }
     /// ```
     fn boxed<'a>(self) -> Box<Parser<Input = Self::Input, Output = Self::Output> + 'a>
-        where Self: Sized + 'a
+    where
+        Self: Sized + 'a,
     {
         Box::new(self)
     }
 }
 impl<'a, I, O, P: ?Sized> Parser for &'a mut P
-    where I: Stream,
-          P: Parser<Input = I, Output = O>
+where
+    I: Stream,
+    P: Parser<Input = I, Output = O>,
 {
     type Input = I;
     type Output = O;
@@ -1752,8 +1813,9 @@ impl<'a, I, O, P: ?Sized> Parser for &'a mut P
     }
 }
 impl<I, O, P: ?Sized> Parser for Box<P>
-    where I: Stream,
-          P: Parser<Input = I, Output = O>
+where
+    I: Stream,
+    P: Parser<Input = I, Output = O>,
 {
     type Input = I;
     type Output = O;
@@ -1781,30 +1843,35 @@ impl<I, O, P: ?Sized> Parser for Box<P>
 
 /// A `BufferedStream` wraps an instance `StreamOnce`, allowing it to be used as a `Stream`.
 pub struct BufferedStream<'a, I>
-    where I: StreamOnce + 'a,
-          I::Item: 'a
+where
+    I: StreamOnce + 'a,
+    I::Item: 'a,
 {
     offset: usize,
     buffer: &'a SharedBufferedStream<I>,
 }
 
 impl<'a, I> fmt::Debug for BufferedStream<'a, I>
-    where I: StreamOnce + 'a,
-          I::Item: 'a
+where
+    I: StreamOnce + 'a,
+    I::Item: 'a,
 {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         let buffer_offset = unsafe { (*self.buffer.buffer.get()).offset };
-        write!(f,
-               "BufferedStream {{ offset: {:?} buffer_offset: {:?} }}",
-               self.offset,
-               buffer_offset)
+        write!(
+            f,
+            "BufferedStream {{ offset: {:?} buffer_offset: {:?} }}",
+            self.offset,
+            buffer_offset
+        )
     }
 }
 
 impl<'a, I> Clone for BufferedStream<'a, I>
-    where I: StreamOnce + 'a,
-          I::Position: Clone,
-          I::Item: 'a
+where
+    I: StreamOnce + 'a,
+    I::Position: Clone,
+    I::Item: 'a,
 {
     fn clone(&self) -> BufferedStream<'a, I> {
         BufferedStream {
@@ -1815,13 +1882,15 @@ impl<'a, I> Clone for BufferedStream<'a, I>
 }
 
 pub struct SharedBufferedStream<I>
-    where I: StreamOnce
+where
+    I: StreamOnce,
 {
     buffer: UnsafeCell<BufferedStreamInner<I>>,
 }
 
 struct BufferedStreamInner<I>
-    where I: StreamOnce
+where
+    I: StreamOnce,
 {
     offset: usize,
     iter: I,
@@ -1829,9 +1898,10 @@ struct BufferedStreamInner<I>
 }
 
 impl<I> BufferedStreamInner<I>
-    where I: StreamOnce,
-          I::Position: Clone,
-          I::Item: Clone
+where
+    I: StreamOnce,
+    I::Position: Clone,
+    I::Item: Clone,
 {
     #[inline]
     fn uncons(&mut self, offset: usize) -> Result<I::Item, Error<I::Item, I::Range>> {
@@ -1850,9 +1920,11 @@ 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(),
+            )
         }
     }
 
@@ -1875,9 +1947,10 @@ impl<I> BufferedStreamInner<I>
 }
 
 impl<I> SharedBufferedStream<I>
-    where I: StreamOnce,
-          I::Position: Clone,
-          I::Item: Clone
+where
+    I: StreamOnce,
+    I::Position: Clone,
+    I::Item: Clone,
 {
     pub fn as_stream(&self) -> BufferedStream<I> {
         BufferedStream {
@@ -1896,7 +1969,8 @@ impl<I> SharedBufferedStream<I>
 }
 
 impl<'a, I> BufferedStream<'a, I>
-    where I: StreamOnce
+where
+    I: StreamOnce,
 {
     /// Constructs a new `BufferedStream` froma a `StreamOnce` instance with a `lookahead` number
     /// of elements stored in the buffer.
@@ -1906,18 +1980,19 @@ impl<'a, I> BufferedStream<'a, I>
     pub fn new(iter: I, lookahead: usize) -> SharedBufferedStream<I> {
         SharedBufferedStream {
             buffer: UnsafeCell::new(BufferedStreamInner {
-                                        offset: 0,
-                                        iter: iter,
-                                        buffer: VecDeque::with_capacity(lookahead),
-                                    }),
+                offset: 0,
+                iter: iter,
+                buffer: VecDeque::with_capacity(lookahead),
+            }),
         }
     }
 }
 
 impl<'a, I> StreamOnce for BufferedStream<'a, I>
-    where I: StreamOnce + 'a,
-          I::Position: Clone,
-          I::Item: Clone + PartialEq + 'a
+where
+    I: StreamOnce + 'a,
+    I::Position: Clone,
+    I::Item: Clone + PartialEq + 'a,
 {
     type Item = I::Item;
     type Range = I::Range;
@@ -1957,12 +2032,18 @@ 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() }][..],
-                       &[CloneOnly { s: "y".to_string() }][..])));
+        assert_eq!(
+            result,
+            Ok((
+                &[CloneOnly { s: "x".to_string() }][..],
+                &[CloneOnly { s: "y".to_string() }][..]
+            ))
+        );
     }
 }
diff --git a/src/range.rs b/src/range.rs
index a5876d9e..2e00616a 100644
--- a/src/range.rs
+++ b/src/range.rs
@@ -3,11 +3,14 @@ use std::marker::PhantomData;
 use primitives::{ConsumedResult, Error, Info, ParseError, Parser, RangeStream};
 use primitives::FastResult::*;
 
-pub struct Range<I>(I::Range) where I: RangeStream;
+pub struct Range<I>(I::Range)
+where
+    I: RangeStream;
 
 impl<I> Parser for Range<I>
-    where I: RangeStream,
-          I::Range: PartialEq + ::primitives::Range
+where
+    I: RangeStream,
+    I::Range: PartialEq + ::primitives::Range,
 {
     type Input = I;
     type Output = I::Range;
@@ -50,16 +53,18 @@ impl<I> Parser for Range<I>
 /// ```
 #[inline(always)]
 pub fn range<I>(i: I::Range) -> Range<I>
-    where I: RangeStream,
-          I::Range: PartialEq + ::primitives::Range
+where
+    I: RangeStream,
+    I::Range: PartialEq + ::primitives::Range,
 {
     Range(i)
 }
 
 pub struct Take<I>(usize, PhantomData<fn(I) -> I>);
 impl<I> Parser for Take<I>
-    where I: RangeStream,
-          I::Range: ::primitives::Range
+where
+    I: RangeStream,
+    I::Range: ::primitives::Range,
 {
     type Input = I;
     type Output = I::Range;
@@ -93,17 +98,19 @@ impl<I> Parser for Take<I>
 /// ```
 #[inline(always)]
 pub fn take<I>(n: usize) -> Take<I>
-    where I: RangeStream,
-          I::Range: ::primitives::Range
+where
+    I: RangeStream,
+    I::Range: ::primitives::Range,
 {
     Take(n, PhantomData)
 }
 
 pub struct TakeWhile<I, F>(F, PhantomData<fn(I) -> I>);
 impl<I, F> Parser for TakeWhile<I, F>
-    where I: RangeStream,
-          I::Range: ::primitives::Range,
-          F: FnMut(I::Item) -> bool
+where
+    I: RangeStream,
+    I::Range: ::primitives::Range,
+    F: FnMut(I::Item) -> bool,
 {
     type Input = I;
     type Output = I::Range;
@@ -130,17 +137,19 @@ impl<I, F> Parser for TakeWhile<I, F>
 /// ```
 #[inline(always)]
 pub fn take_while<I, F>(f: F) -> TakeWhile<I, F>
-    where I: RangeStream,
-          F: FnMut(I::Item) -> bool
+where
+    I: RangeStream,
+    F: FnMut(I::Item) -> bool,
 {
     TakeWhile(f, PhantomData)
 }
 
 pub struct TakeWhile1<I, F>(F, PhantomData<fn(I) -> I>);
 impl<I, F> Parser for TakeWhile1<I, F>
-    where I: RangeStream,
-          I::Range: ::primitives::Range,
-          F: FnMut(I::Item) -> bool
+where
+    I: RangeStream,
+    I::Range: ::primitives::Range,
+    F: FnMut(I::Item) -> bool,
 {
     type Input = I;
     type Output = I::Range;
@@ -175,24 +184,28 @@ impl<I, F> Parser for TakeWhile1<I, F>
 /// ```
 #[inline(always)]
 pub fn take_while1<I, F>(f: F) -> TakeWhile1<I, F>
-    where I: RangeStream,
-          I::Range: ::primitives::Range,
-          F: FnMut(I::Item) -> bool
+where
+    I: RangeStream,
+    I::Range: ::primitives::Range,
+    F: FnMut(I::Item) -> bool,
 {
     TakeWhile1(f, PhantomData)
 }
 
-pub struct TakeUntilRange<I>(I::Range) where I: RangeStream;
+pub struct TakeUntilRange<I>(I::Range)
+where
+    I: RangeStream;
 impl<I> Parser for TakeUntilRange<I>
-    where I: RangeStream,
-          I::Range: PartialEq + ::primitives::Range
+where
+    I: RangeStream,
+    I::Range: PartialEq + ::primitives::Range,
 {
     type Input = I;
     type Output = I::Range;
 
     #[inline]
     fn parse_lazy(&mut self, mut input: Self::Input) -> ConsumedResult<Self::Output, Self::Input> {
-        use ::primitives::Range;
+        use primitives::Range;
 
         let len = self.0.len();
         let mut to_consume = 0;
@@ -209,7 +222,7 @@ impl<I> Parser for TakeUntilRange<I>
                                 return ConsumedOk((consumed, input));
                             }
                         }
-                        
+
                         // We are guaranteed able to uncons to_consume characters here
                         // because we've already done it on look_ahead_input.
                         unreachable!();
@@ -245,7 +258,9 @@ impl<I> Parser for TakeUntilRange<I>
 /// # }
 /// ```
 #[inline(always)]
-pub fn take_until_range<I>(r: I::Range) -> TakeUntilRange<I> where I: RangeStream
+pub fn take_until_range<I>(r: I::Range) -> TakeUntilRange<I>
+where
+    I: RangeStream,
 {
     TakeUntilRange(r)
 }


Test patch:
diff --git a/tests/buffered_stream.rs b/tests/buffered_stream.rs
index bbbe0a9d..bb00161e 100644
--- a/tests/buffered_stream.rs
+++ b/tests/buffered_stream.rs
@@ -11,13 +11,11 @@ use combine::from_iter;
 #[allow(deprecated)]
 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());
@@ -36,9 +34,11 @@ 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"]));
@@ -53,17 +53,21 @@ 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()
-                .errors
-                .iter()
-                .any(|err| *err == Error::Message("Backtracked to far".into())));
+    assert!(
+        result
+            .unwrap_err()
+            .errors
+            .iter()
+            .any(|err| *err == Error::Message("Backtracked to far".into()))
+    );
 }
 
 /// Test which checks that a stream which has ended does not repeat the last token in some cases in
diff --git a/tests/date.rs b/tests/date.rs
index 8ba12ead..7e120ec8 100644
--- a/tests/date.rs
+++ b/tests/date.rs
@@ -40,10 +40,12 @@ fn two_digits_to_int((x, y): (char, char)) -> i32 {
 // Parsers which are used frequntly can be wrapped like this to avoid writing parser(fn_name) in
 // several places.
 fn two_digits<I>() -> FnPtrParser<i32, I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
     fn two_digits_<I>(input: I) -> ParseResult<i32, I>
-        where I: Stream<Item = char>
+    where
+        I: Stream<Item = char>,
     {
         (digit(), digit())
             .map(two_digits_to_int)
@@ -58,16 +60,22 @@ fn two_digits<I>() -> FnPtrParser<i32, I>
 /// -01
 /// Z
 fn time_zone<I>(input: I) -> ParseResult<i32, I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
     let utc = char('Z').map(|_| 0);
-    let offset = (choice([char('-'), char('+')]),
-                  two_digits(),
-                  optional(optional(char(':')).with(two_digits())))
-            .map(|(sign, hour, minute)| {
-                     let offset = hour * 60 + minute.unwrap_or(0);
-                     if sign == '-' { -offset } else { offset }
-                 });
+    let offset = (
+        choice([char('-'), char('+')]),
+        two_digits(),
+        optional(optional(char(':')).with(two_digits())),
+    ).map(|(sign, hour, minute)| {
+            let offset = hour * 60 + minute.unwrap_or(0);
+            if sign == '-' {
+                -offset
+            } else {
+                offset
+            }
+        });
 
     utc.or(offset).parse_stream(input)
 }
@@ -75,27 +83,40 @@ fn time_zone<I>(input: I) -> ParseResult<i32, I>
 /// Parses a date
 /// 2010-01-30
 fn date<I>(input: I) -> ParseResult<Date, I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
-    (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,
-                 }
-             })
+    (
+        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,
+            }
+        })
         .parse_stream(input)
 }
 
 /// Parses a time
 /// 12:30:02
 fn time<I>(input: I) -> ParseResult<Time, I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
-    (two_digits(), char(':'), two_digits(), char(':'), two_digits(), parser(time_zone))
-        .map(|(hour, _, minute, _, second, time_zone)| {
+    (
+        two_digits(),
+        char(':'),
+        two_digits(),
+        char(':'),
+        two_digits(),
+        parser(time_zone),
+    ).map(|(hour, _, minute, _, second, time_zone)| {
             // Its ok to just unwrap since we only parsed digits
             Time {
                 hour: hour,
@@ -110,15 +131,16 @@ fn time<I>(input: I) -> ParseResult<Time, I>
 /// Parses a date time according to ISO8601
 /// 2015-08-02T18:54:42+02
 fn date_time<I>(input: I) -> ParseResult<DateTime, I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
     (parser(date), char('T'), parser(time))
         .map(|(date, _, time)| {
-                 DateTime {
-                     date: date,
-                     time: time,
-                 }
-             })
+            DateTime {
+                date: date,
+                time: time,
+            }
+        })
         .parse_stream(input)
 }
 
diff --git a/tests/ini.rs b/tests/ini.rs
index e73688b5..712d3c7a 100644
--- a/tests/ini.rs
+++ b/tests/ini.rs
@@ -14,18 +14,21 @@ pub struct Ini {
 }
 
 fn property<I>(input: I) -> ParseResult<(String, String), I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
-    (many1(satisfy(|c| c != '=' && c != '[' && c != ';')),
-     token('='),
-     many1(satisfy(|c| c != '\n' && c != ';')))
-            .map(|(key, _, value)| (key, value))
-            .expected("property")
-            .parse_stream(input)
+    (
+        many1(satisfy(|c| c != '=' && c != '[' && c != ';')),
+        token('='),
+        many1(satisfy(|c| c != '\n' && c != ';')),
+    ).map(|(key, _, value)| (key, value))
+        .message("while parsing property")
+        .parse_stream(input)
 }
 
 fn whitespace<I>(input: I) -> ParseResult<(), I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
     let comment = (token(';'), skip_many(satisfy(|c| c != '\n'))).map(|_| ());
     // Wrap the `spaces().or(comment)` in `skip_many` so that it skips alternating whitespace and
@@ -34,33 +37,40 @@ fn whitespace<I>(input: I) -> ParseResult<(), I>
 }
 
 fn properties<I>(input: I) -> ParseResult<HashMap<String, String>, I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
     // After each property we skip any whitespace that followed it
     many(parser(property).skip(parser(whitespace))).parse_stream(input)
 }
 
 fn section<I>(input: I) -> ParseResult<(String, HashMap<String, String>), I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
-    (between(token('['), token(']'), many(satisfy(|c| c != ']'))),
-     parser(whitespace),
-     parser(properties))
-            .map(|(name, _, properties)| (name, properties))
-            .expected("section")
-            .parse_stream(input)
+    (
+        between(token('['), token(']'), many(satisfy(|c| c != ']'))),
+        parser(whitespace),
+        parser(properties),
+    ).map(|(name, _, properties)| (name, properties))
+        .message("while parsing section")
+        .parse_stream(input)
 }
 
 fn ini<I>(input: I) -> ParseResult<Ini, I>
-    where I: Stream<Item = char>
+where
+    I: Stream<Item = char>,
 {
-    (parser(whitespace), parser(properties), many(parser(section)))
-        .map(|(_, global, sections)| {
-                 Ini {
-                     global: global,
-                     sections: sections,
-                 }
-             })
+    (
+        parser(whitespace),
+        parser(properties),
+        many(parser(section)),
+    ).map(|(_, global, sections)| {
+            Ini {
+                global: global,
+                sections: sections,
+            }
+        })
         .parse_stream(input)
 }
 
@@ -85,9 +95,7 @@ type=LL(1)
     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));
@@ -97,9 +105,15 @@ type=LL(1)
 fn ini_error() {
     let text = "[error";
     let result = parser(ini).parse(State::new(text)).map(|t| t.0);
-    assert_eq!(result,
-               Err(ParseError {
-                       position: SourcePosition { line: 1, column: 7 },
-                       errors: vec![Error::end_of_input(), Error::Expected("section".into())],
-                   }));
+    assert_eq!(
+        result,
+        Err(ParseError {
+            position: SourcePosition { line: 1, column: 7 },
+            errors: vec![
+                Error::end_of_input(),
+                Error::Expected(']'.into()),
+                Error::Message("while parsing section".into()),
+            ],
+        })
+    );
 }