Repository: Geal/nom
Pull request #770 (2018-05-18 00:17:36)

Remove deprecated duplicate macro exports
See https://github.com/rust-lang/rust/pull/50143 for more details.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/17045673/badge)](https://coveralls.io/builds/17045673)

Coverage remained the same at 87.587% when pulling **499fae986a3ac918d6113d9f7b005e4c99d94db1 on petrochenkov:master** into **ba1d6e0589458bc46aef05b1ebd13ce2b3b1b816 on Geal:master**.


Patch:
diff --git a/README.md b/README.md
index cf6bad7..6dd661a 100644
--- a/README.md
+++ b/README.md
@@ -32,8 +32,10 @@ fn from_hex(input: &str) -> Result<u8, std::num::ParseIntError> {
 }
 
 fn is_hex_digit(c: char) -> bool {
-  let c = c as u8;
-  (c >= 0x30 && c <= 0x39) || (c >= 0x41 && c <= 0x46) || (c >= 0x61 && c <= 0x66)
+  match c {
+    '0'..='9' | 'a'..='f' | 'A'..='F' => true,
+    _ => false,
+  }
 }
 
 named!(hex_primary<&str, u8>,
@@ -139,7 +141,7 @@ It allows you to build powerful, deterministic state machines for your protocols
 Example projects:
 
 - [HTTP proxy](https://github.com/sozu-proxy/sozu/blob/master/lib/src/parser/http11.rs)
-- [using nom with generators](https://github.com/geal/generator_nom)
+- [using nom with generators](https://github.com/Geal/generator_nom)
 
 ## Parser combinators
 
diff --git a/src/branch.rs b/src/branch.rs
index e444357..c7589ed 100644
--- a/src/branch.rs
+++ b/src/branch.rs
@@ -198,6 +198,7 @@ macro_rules! alt (
 
           // Compile-time hack to ensure that res's E type is not under-specified.
           // This all has no effect at runtime.
+          #[allow(dead_code)]
           fn unify_types<T>(_: &T, _: &T) {}
           if let Err(Err::Error(ref e2)) = out {
             unify_types(&e, e2);
diff --git a/src/bytes.rs b/src/bytes.rs
index 111a54b..ea37ffd 100644
--- a/src/bytes.rs
+++ b/src/bytes.rs
@@ -596,7 +596,7 @@ macro_rules! take_till (
 macro_rules! take_till1 (
   ($input:expr, $submac:ident!( $($args:tt)* )) => (
     {
-      use $crate::InputTakeAtPosition;
+      use $crate::{ErrorKind, InputTakeAtPosition};
       let input = $input;
       input.split_at_position1(|c| $submac!(c, $($args)*), ErrorKind::TakeTill1)
     }
@@ -1108,34 +1108,6 @@ mod tests {
     );
   );
 
-  #[macro_export]
-  macro_rules! char (
-    ($i:expr, $c: expr) => (
-      {
-        use $crate::lib::std::result::Result::*;
-        use $crate::lib::std::option::Option::*;
-        use $crate::{Err,Needed};
-
-        use $crate::Slice;
-        use $crate::AsChar;
-        use $crate::InputIter;
-
-        match ($i).iter_elements().next().map(|c| {
-          let b = c.clone().as_char() == $c;
-          (c, b)
-        }) {
-          None             => $crate::need_more($i, Needed::Size(1)),
-          Some((_, false)) => {
-            let e: $crate::ErrorKind<u32> = $crate::ErrorKind::Char;
-            Err(Err::Error($crate::Context::Code($i, e)))
-          },
-          //the unwrap should be safe here
-          Some((c, true))  => Ok(( $i.slice(c.len()..), $i.iter_elements().next().unwrap().as_char() ))
-        }
-      }
-    );
-  );
-
   #[test]
   fn is_a() {
     named!(a_or_b, is_a!(&b"ab"[..]));
diff --git a/src/lib.rs b/src/lib.rs
index ea49ba1..8d391be 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -21,8 +21,10 @@
 //! }
 //!
 //! fn is_hex_digit(c: char) -> bool {
-//!   let c = c as u8;
-//!   (c >= 0x30 && c <= 0x39) || (c >= 0x41 && c <= 0x46) || (c >= 0x61 && c <= 0x66)
+//!   match c {
+//!     '0'..='9' | 'a'..='f' | 'A'..='F' => true,
+//!     _ => false,
+//!   }
 //! }
 //!
 //! named!(hex_primary<&str, u8>,
diff --git a/src/macros.rs b/src/macros.rs
index 49d737d..4107d5b 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -757,7 +757,8 @@ macro_rules! value (
   );
   ($i:expr, $res:expr) => (
     {
-      Ok(($i, $res))
+      let res: IResult<_,_> = Ok(($i, $res));
+      res
     }
   );
 );
diff --git a/src/multi.rs b/src/multi.rs
index c7b7ce2..c6aed73 100644
--- a/src/multi.rs
+++ b/src/multi.rs
@@ -571,7 +571,7 @@ macro_rules! count(
   ($i:expr, $submac:ident!( $($args:tt)* ), $count: expr) => (
     {
       use $crate::lib::std::result::Result::*;
-      use $crate::{Err};
+      use $crate::Err;
 
       let ret;
       let mut input = $i.clone();
@@ -639,7 +639,7 @@ macro_rules! count_fixed (
   ($i:expr, $typ:ty, $submac:ident!( $($args:tt)* ), $count: expr) => (
     {
       use $crate::lib::std::result::Result::*;
-      use $crate::{Err};
+      use $crate::Err;
 
       let ret;
       let mut input = $i.clone();
diff --git a/src/nom.rs b/src/nom.rs
index da2f608..3f28dbe 100644
--- a/src/nom.rs
+++ b/src/nom.rs
@@ -584,28 +584,28 @@ pub enum Endianness {
 /// if the parameter is nom::Endianness::Big, parse a big endian u16 integer,
 /// otherwise a little endian u16 integer
 #[macro_export]
-macro_rules! u16 ( ($i:expr, $e:expr) => ( {if Endianness::Big == $e { be_u16($i) } else { le_u16($i) } } ););
+macro_rules! u16 ( ($i:expr, $e:expr) => ( {if $crate::Endianness::Big == $e { be_u16($i) } else { le_u16($i) } } ););
 /// if the parameter is nom::Endianness::Big, parse a big endian u32 integer,
 /// otherwise a little endian u32 integer
 #[macro_export]
-macro_rules! u32 ( ($i:expr, $e:expr) => ( {if Endianness::Big == $e { be_u32($i) } else { le_u32($i) } } ););
+macro_rules! u32 ( ($i:expr, $e:expr) => ( {if $crate::Endianness::Big == $e { be_u32($i) } else { le_u32($i) } } ););
 /// if the parameter is nom::Endianness::Big, parse a big endian u64 integer,
 /// otherwise a little endian u64 integer
 #[macro_export]
-macro_rules! u64 ( ($i:expr, $e:expr) => ( {if Endianness::Big == $e { be_u64($i) } else { le_u64($i) } } ););
+macro_rules! u64 ( ($i:expr, $e:expr) => ( {if $crate::Endianness::Big == $e { be_u64($i) } else { le_u64($i) } } ););
 
 /// if the parameter is nom::Endianness::Big, parse a big endian i16 integer,
 /// otherwise a little endian i16 integer
 #[macro_export]
-macro_rules! i16 ( ($i:expr, $e:expr) => ( {if Endianness::Big == $e { be_i16($i) } else { le_i16($i) } } ););
+macro_rules! i16 ( ($i:expr, $e:expr) => ( {if $crate::Endianness::Big == $e { be_i16($i) } else { le_i16($i) } } ););
 /// if the parameter is nom::Endianness::Big, parse a big endian i32 integer,
 /// otherwise a little endian i32 integer
 #[macro_export]
-macro_rules! i32 ( ($i:expr, $e:expr) => ( {if Endianness::Big == $e { be_i32($i) } else { le_i32($i) } } ););
+macro_rules! i32 ( ($i:expr, $e:expr) => ( {if $crate::Endianness::Big == $e { be_i32($i) } else { le_i32($i) } } ););
 /// if the parameter is nom::Endianness::Big, parse a big endian i64 integer,
 /// otherwise a little endian i64 integer
 #[macro_export]
-macro_rules! i64 ( ($i:expr, $e:expr) => ( {if Endianness::Big == $e { be_i64($i) } else { le_i64($i) } } ););
+macro_rules! i64 ( ($i:expr, $e:expr) => ( {if $crate::Endianness::Big == $e { be_i64($i) } else { le_i64($i) } } ););
 
 /// Recognizes big endian 4 bytes floating point number
 #[inline]
diff --git a/src/whitespace.rs b/src/whitespace.rs
index d1e3abc..1b2e9f7 100644
--- a/src/whitespace.rs
+++ b/src/whitespace.rs
@@ -489,7 +489,7 @@ macro_rules! alt_sep (
   (__impl $i:expr, $separator:path, $subrule:ident!( $($args:tt)*) | $($rest:tt)*) => (
     {
       use $crate::lib::std::result::Result::*;
-      use $crate::{Err};
+      use $crate::Err;
 
       let res = sep!($i, $separator, $subrule!($($args)*));
       match res {
@@ -503,7 +503,7 @@ macro_rules! alt_sep (
   (__impl $i:expr, $separator:path, $subrule:ident!( $($args:tt)* ) => { $gen:expr } | $($rest:tt)+) => (
     {
       use $crate::lib::std::result::Result::*;
-      use $crate::{Err};
+      use $crate::Err;
 
       match sep!($i, $separator, $subrule!( $($args)* )) {
         Ok((i,o))               => Ok((i,$gen(o))),
@@ -526,7 +526,7 @@ macro_rules! alt_sep (
   (__impl $i:expr, $separator:path, $subrule:ident!( $($args:tt)* ) => { $gen:expr }) => (
     {
       use $crate::lib::std::result::Result::*;
-      use $crate::{Err};
+      use $crate::Err;
 
       match sep!($i, $separator, $subrule!( $($args)* )) {
         Ok((i,o))     => Ok((i,$gen(o))),
@@ -548,7 +548,7 @@ macro_rules! alt_sep (
   (__impl $i:expr, $separator:path, $subrule:ident!( $($args:tt)*)) => (
     {
       use $crate::lib::std::result::Result::*;
-      use $crate::{Err};
+      use $crate::Err;
 
       match sep!($i, $separator, $subrule!( $($args)* )) {
         Ok((i,o))     => Ok((i,o)),
@@ -644,7 +644,7 @@ macro_rules! switch_sep (
   (__impl $i:expr, $separator:path, $submac:ident!( $($args:tt)* ), $($p:pat => $subrule:ident!( $($args2:tt)* ))|* ) => (
     {
       use $crate::lib::std::result::Result::*;
-      use $crate::{Err};
+      use $crate::Err;
 
       match sep!($i, $separator, $submac!($($args)*)) {
         Err(Err::Error(e))      => Err(Err::Error(error_node_position!(


Test patch:
diff --git a/tests/css.rs b/tests/css.rs
index 044ea07..31b58e4 100644
--- a/tests/css.rs
+++ b/tests/css.rs
@@ -13,8 +13,10 @@ fn from_hex(input: &str) -> Result<u8, std::num::ParseIntError> {
 }
 
 fn is_hex_digit(c: char) -> bool {
-  let c = c as u8;
-  (c >= 0x30 && c <= 0x39) || (c >= 0x41 && c <= 0x46) || (c >= 0x61 && c <= 0x66)
+  match c {
+    '0'..='9' | 'a'..='f' | 'A'..='F' => true,
+    _ => false,
+  }
 }
 
 named!(hex_primary<&str, u8>,
diff --git a/tests/issues.rs b/tests/issues.rs
index 53b1459..66d3753 100644
--- a/tests/issues.rs
+++ b/tests/issues.rs
@@ -253,3 +253,22 @@ named!(issue_724<&str, i32>,
 
 named!(issue_741_str<CompleteStr, CompleteStr>, re_match!(r"^_?[A-Za-z][0-9A-Z_a-z-]*"));
 named!(issue_741_bytes<CompleteByteSlice, CompleteByteSlice>, re_bytes_match!(r"^_?[A-Za-z][0-9A-Z_a-z-]*"));
+
+
+fn atom_specials(c: u8) -> bool {
+    c == b'q'
+}
+
+named!(
+    capability<&str>,
+    do_parse!(tag_s!(" ") >> _atom: map_res!(take_till1!(atom_specials), std::str::from_utf8) >> ("a"))
+);
+
+#[test]
+fn issue_759() {
+    assert_eq!(capability(b" abcqd"), Ok((&b"qd"[..], "a")));
+}
+
+named_args!(issue_771(count: usize)<Vec<u32>>,
+  length_count!(value!(count), call!(nom::be_u32))
+);