diff --git a/xdr-codec/Cargo.toml b/xdr-codec/Cargo.toml index 1d62c78..59c33bf 100644 --- a/xdr-codec/Cargo.toml +++ b/xdr-codec/Cargo.toml @@ -19,7 +19,7 @@ unstable = [] [dependencies] byteorder = "1.0" -error-chain = "0.10" +error-chain = "0.12" [dev-dependencies] quickcheck = "0.4" diff --git a/xdrgen/Cargo.toml b/xdrgen/Cargo.toml index 8db2d60..008768b 100644 --- a/xdrgen/Cargo.toml +++ b/xdrgen/Cargo.toml @@ -26,8 +26,8 @@ env_logger = "0.4" nom = { version="3.1", features=["verbose-errors"] } quote = "0.3" clap = "2.24" -lazy_static = "0.2" -bitflags = "0.9" +lazy_static = "1.4" +bitflags = "1.2" [dependencies.xdr-codec] path = "../xdr-codec" diff --git a/xdrgen/src/spec/mod.rs b/xdrgen/src/spec/mod.rs index 24b4e8e..fff406e 100644 --- a/xdrgen/src/spec/mod.rs +++ b/xdrgen/src/spec/mod.rs @@ -36,19 +36,19 @@ impl ToTokens for Derives { let mut der = Vec::new(); - if self.contains(COPY) { + if self.contains(Derives::COPY) { der.push(quote!(Copy)) } - if self.contains(CLONE) { + if self.contains(Derives::CLONE) { der.push(quote!(Clone)) } - if self.contains(DEBUG) { + if self.contains(Derives::DEBUG) { der.push(quote!(Debug)) } - if self.contains(EQ) { + if self.contains(Derives::EQ) { der.push(quote!(Eq)) } - if self.contains(PARTIALEQ) { + if self.contains(Derives::PARTIALEQ) { der.push(quote!(PartialEq)) } @@ -73,7 +73,7 @@ lazy_static! { "while", "yield", ]; - kws.into_iter().map(|x| *x).collect() + kws.iter().map(|x| *x).collect() }; } @@ -222,7 +222,7 @@ impl Type { use self::Type::*; let mut memoset = HashMap::new(); - let mut memo = match memo { + let memo = match memo { None => &mut memoset, Some(m) => m, }; @@ -238,7 +238,7 @@ impl Type { &Array(ref ty, ref len) => { let ty = ty.as_ref(); let set = match ty { - &Opaque | &String => EQ | PARTIALEQ | COPY | CLONE | DEBUG, + &Opaque | &String => Derives::EQ | Derives::PARTIALEQ | Derives::COPY | Derives::CLONE | Derives::DEBUG, ref ty => ty.derivable(symtab, Some(memo)), }; match len.as_i64(symtab) { @@ -248,10 +248,10 @@ impl Type { } &Flex(ref ty, ..) => { let set = ty.derivable(symtab, Some(memo)); - set & !COPY // no Copy, everything else OK + set & !Derives::COPY // no Copy, everything else OK } - &Enum(_) => EQ | PARTIALEQ | COPY | CLONE | DEBUG, - &Option(ref ty) => ty.derivable(symtab, Some(memo)), + &Enum(_) => Derives::EQ | Derives::PARTIALEQ | Derives::COPY | Derives::CLONE | Derives::DEBUG, + &Option(ref ty) => ty.derivable(symtab, Some(memo)) & !Derives::COPY, &Struct(ref fields) => { fields.iter().fold(Derives::all(), |a, f| { a & f.derivable(symtab, memo) @@ -277,10 +277,10 @@ impl Type { } } - &Float | &Double => PARTIALEQ | COPY | CLONE | DEBUG, + &Float | &Double => Derives::PARTIALEQ | Derives::COPY | Derives::CLONE | Derives::DEBUG, ty if ty.is_prim(symtab) => Derives::all(), - _ => Derives::all() & !COPY, + _ => Derives::all() & !Derives::COPY, }; memo.insert(self.clone(), set); @@ -348,7 +348,7 @@ impl Type { match ty { &Opaque | &String => { quote!({ - let mut buf: [u8; #value as usize] = unsafe { ::std::mem::uninitialized() }; + let mut buf: [u8; #value as usize] = unsafe { ::std::mem::MaybeUninit::uninit().assume_init() }; let sz = xdr_codec::unpack_opaque_array(input, &mut buf[..], #value as usize)?; (buf, sz) }) @@ -383,7 +383,7 @@ impl Type { fn uninit_ptr_dropper(p: &mut T) { unsafe { ::std::ptr::drop_in_place(p) } } - let mut buf: [#ty; #value as usize] = unsafe { ::std::mem::uninitialized() }; + let mut buf: [#ty; #value as usize] = unsafe { ::std::mem::MaybeUninit::uninit().assume_init() }; let res = ::std::panic::catch_unwind( ::std::panic::AssertUnwindSafe(|| xdr_codec::unpack_array_with( diff --git a/xdrgen/src/spec/xdr_nom.rs b/xdrgen/src/spec/xdr_nom.rs index 79cf95d..33f7b00 100644 --- a/xdrgen/src/spec/xdr_nom.rs +++ b/xdrgen/src/spec/xdr_nom.rs @@ -5,7 +5,7 @@ use nom::IResult::*; use std::str; use super::{Decl, Defn, EnumDefn, Type, UnionCase, Value}; -use super::{CLONE, COPY, DEBUG, EQ, PARTIALEQ}; +use super::{Derives}; #[inline] fn ignore(_: T) -> () { @@ -87,14 +87,14 @@ named!(definition, fn is_hexdigit(ch: u8) -> bool { match ch as char { - '0'...'9' | 'A'...'F' | 'a'...'f' => true, + '0'..='9' | 'A'..='F' | 'a'..='f' => true, _ => false, } } fn is_octdigit(ch: u8) -> bool { match ch as char { - '0'...'7' => true, + '0'..='7' => true, _ => false, } } @@ -188,8 +188,8 @@ fn token(input: &[u8]) -> IResult<&[u8], &[u8]> { for (idx, item) in input.iter().enumerate() { match *item as char { - 'a'...'z' | 'A'...'Z' | '_' => continue, - '0'...'9' if idx > 0 => continue, + 'a'..='z' | 'A'..='Z' | '_' => continue, + '0'..='9' if idx > 0 => continue, _ => { if idx > 0 { return Done(&input[idx..], &input[0..idx]); @@ -569,13 +569,13 @@ named!(type_spec, do_parse!(kw_unsigned >> kw_int >> (Type::UInt)) | do_parse!(kw_unsigned >> kw_long >> (Type::UInt)) | // backwards compat with rpcgen do_parse!(kw_unsigned >> kw_char >> // backwards compat with rpcgen - (Type::ident_with_derives("u8", COPY | CLONE | EQ | PARTIALEQ | DEBUG))) | + (Type::ident_with_derives("u8", Derives::COPY | Derives::CLONE | Derives::EQ | Derives::PARTIALEQ | Derives::DEBUG))) | do_parse!(kw_unsigned >> kw_short >> (Type::UInt)) | // backwards compat with rpcgen do_parse!(kw_unsigned >> kw_hyper >> (Type::UHyper)) | kw_unsigned => { |_| Type::UInt } | // backwards compat with rpcgen kw_long => { |_| Type::Int } | // backwards compat with rpcgen kw_char => { // backwards compat with rpcgen - |_| Type::ident_with_derives("i8", COPY | CLONE | EQ | PARTIALEQ | DEBUG) + |_| Type::ident_with_derives("i8", Derives::COPY | Derives::CLONE | Derives::EQ | Derives::PARTIALEQ | Derives::DEBUG) } | kw_short => { |_| Type::Int } | // backwards compat with rpcgen kw_int => { |_| Type::Int } | @@ -604,7 +604,7 @@ fn test_type() { assert_eq!(type_spec(&b"unsigned hyper "[..]), Done(&b" "[..], Type::UHyper)); assert_eq!(type_spec(&b"unsigned char "[..]), Done(&b" "[..], - Type::Ident("u8".into(), Some(COPY | CLONE | EQ | PARTIALEQ | DEBUG)))); + Type::Ident("u8".into(), Some(Derives::COPY | Derives::CLONE | Derives::EQ | Derives::PARTIALEQ | Derives::DEBUG)))); assert_eq!(type_spec(&b"unsigned short "[..]), Done(&b" "[..], Type::UInt)); assert_eq!(type_spec(&b" hyper "[..]), Done(&b" "[..], Type::Hyper)); @@ -613,7 +613,7 @@ fn test_type() { assert_eq!(type_spec(&b"// thing\n bool "[..]), Done(&b" "[..], Type::Bool)); assert_eq!(type_spec(&b"char "[..]), Done(&b" "[..], - Type::Ident("i8".into(), Some(COPY | CLONE | EQ | PARTIALEQ | DEBUG)))); + Type::Ident("i8".into(), Some(Derives::COPY | Derives::CLONE | Derives::EQ | Derives::PARTIALEQ | Derives::DEBUG)))); assert_eq!(type_spec(&b"short "[..]), Done(&b" "[..], Type::Int));