]> git.lizzy.rs Git - rust.git/commitdiff
Transition libserialize to 2018 edition
authorHirokazu Hata <h.hata.ai.t@gmail.com>
Thu, 7 Feb 2019 02:42:43 +0000 (11:42 +0900)
committerHirokazu Hata <h.hata.ai.t@gmail.com>
Thu, 7 Feb 2019 05:15:07 +0000 (14:15 +0900)
src/libserialize/Cargo.toml
src/libserialize/collection_impls.rs
src/libserialize/hex.rs
src/libserialize/json.rs
src/libserialize/lib.rs
src/libserialize/opaque.rs
src/libserialize/serialize.rs

index 3e040818d377707588d3561568c99df463259d96..949af0e2b97464a9c030c054cb9fca16b004569e 100644 (file)
@@ -2,6 +2,7 @@
 authors = ["The Rust Project Developers"]
 name = "serialize"
 version = "0.0.0"
+edition = "2018"
 
 [lib]
 name = "serialize"
index f3afc3b53417c747ff825d29bc5e496e00e09d7e..c0a8fa9d0016dba395a62aa036d90b78f6b54e9c 100644 (file)
@@ -2,7 +2,7 @@
 
 use std::hash::{Hash, BuildHasher};
 
-use {Decodable, Encodable, Decoder, Encoder};
+use crate::{Decodable, Encodable, Decoder, Encoder};
 use std::collections::{LinkedList, VecDeque, BTreeMap, BTreeSet, HashMap, HashSet};
 use std::rc::Rc;
 use std::sync::Arc;
index 6127440a6d7d082acde9d909e5427e32428a2478..c5217b962ce7975b03d500c530a3c770ee52f51e 100644 (file)
@@ -60,7 +60,7 @@ pub enum FromHexError {
 }
 
 impl fmt::Display for FromHexError {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         match *self {
             InvalidHexCharacter(ch, idx) =>
                 write!(f, "Invalid character '{}' at position {}", ch, idx),
@@ -146,7 +146,7 @@ fn from_hex(&self) -> Result<Vec<u8>, FromHexError> {
 mod tests {
     extern crate test;
     use self::test::Bencher;
-    use hex::{FromHex, ToHex};
+    use crate::hex::{FromHex, ToHex};
 
     #[test]
     pub fn test_to_hex() {
index 362b4574ee24ed4559c179ed73b3cc6111fc196b..dc089218a9fac521bb7f4b82fd690eb7310e13d8 100644 (file)
 use std::{char, f64, fmt, str};
 use std;
 
-use Encodable;
+use crate::Encodable;
 
 /// Represents a json value
 #[derive(Clone, PartialEq, PartialOrd, Debug)]
@@ -221,8 +221,8 @@ pub enum Json {
 
 pub struct PrettyJson<'a> { inner: &'a Json }
 
-pub struct AsJson<'a, T: 'a> { inner: &'a T }
-pub struct AsPrettyJson<'a, T: 'a> { inner: &'a T, indent: Option<usize> }
+pub struct AsJson<'a, T> { inner: &'a T }
+pub struct AsPrettyJson<'a, T> { inner: &'a T, indent: Option<usize> }
 
 /// The errors that can arise while parsing a JSON stream.
 #[derive(Clone, Copy, PartialEq, Debug)]
@@ -295,18 +295,18 @@ pub fn error_str(error: ErrorCode) -> &'static str {
 }
 
 /// Shortcut function to decode a JSON `&str` into an object
-pub fn decode<T: ::Decodable>(s: &str) -> DecodeResult<T> {
+pub fn decode<T: crate::Decodable>(s: &str) -> DecodeResult<T> {
     let json = match from_str(s) {
         Ok(x) => x,
         Err(e) => return Err(ParseError(e))
     };
 
     let mut decoder = Decoder::new(json);
-    ::Decodable::decode(&mut decoder)
+    crate::Decodable::decode(&mut decoder)
 }
 
 /// Shortcut function to encode a `T` into a JSON `String`
-pub fn encode<T: ::Encodable>(object: &T) -> Result<string::String, EncoderError> {
+pub fn encode<T: crate::Encodable>(object: &T) -> Result<string::String, EncoderError> {
     let mut s = String::new();
     {
         let mut encoder = Encoder::new(&mut s);
@@ -316,7 +316,7 @@ pub fn encode<T: ::Encodable>(object: &T) -> Result<string::String, EncoderError
 }
 
 impl fmt::Display for ErrorCode {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         error_str(*self).fmt(f)
     }
 }
@@ -326,14 +326,14 @@ fn io_error_to_error(io: io::Error) -> ParserError {
 }
 
 impl fmt::Display for ParserError {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         // FIXME this should be a nicer error
         fmt::Debug::fmt(self, f)
     }
 }
 
 impl fmt::Display for DecoderError {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         // FIXME this should be a nicer error
         fmt::Debug::fmt(self, f)
     }
@@ -344,7 +344,7 @@ fn description(&self) -> &str { "decoder error" }
 }
 
 impl fmt::Display for EncoderError {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         // FIXME this should be a nicer error
         fmt::Debug::fmt(self, f)
     }
@@ -477,7 +477,7 @@ macro_rules! emit_enquoted_if_mapkey {
     })
 }
 
-impl<'a> ::Encoder for Encoder<'a> {
+impl<'a> crate::Encoder for Encoder<'a> {
     type Error = EncoderError;
 
     fn emit_unit(&mut self) -> EncodeResult {
@@ -727,7 +727,7 @@ pub fn set_indent(&mut self, indent: usize) {
     }
 }
 
-impl<'a> ::Encoder for PrettyEncoder<'a> {
+impl<'a> crate::Encoder for PrettyEncoder<'a> {
     type Error = EncoderError;
 
     fn emit_unit(&mut self) -> EncodeResult {
@@ -997,7 +997,7 @@ fn emit_map_elt_val<F>(&mut self, _idx: usize, f: F) -> EncodeResult where
 }
 
 impl Encodable for Json {
-    fn encode<E: ::Encoder>(&self, e: &mut E) -> Result<(), E::Error> {
+    fn encode<E: crate::Encoder>(&self, e: &mut E) -> Result<(), E::Error> {
         match *self {
             Json::I64(v) => v.encode(e),
             Json::U64(v) => v.encode(e),
@@ -1013,20 +1013,20 @@ fn encode<E: ::Encoder>(&self, e: &mut E) -> Result<(), E::Error> {
 
 /// Create an `AsJson` wrapper which can be used to print a value as JSON
 /// on-the-fly via `write!`
-pub fn as_json<T>(t: &T) -> AsJson<T> {
+pub fn as_json<T>(t: &T) -> AsJson<'_, T> {
     AsJson { inner: t }
 }
 
 /// Create an `AsPrettyJson` wrapper which can be used to print a value as JSON
 /// on-the-fly via `write!`
-pub fn as_pretty_json<T>(t: &T) -> AsPrettyJson<T> {
+pub fn as_pretty_json<T>(t: &T) -> AsPrettyJson<'_, T> {
     AsPrettyJson { inner: t, indent: None }
 }
 
 impl Json {
     /// Borrow this json object as a pretty object to generate a pretty
     /// representation for it via `Display`.
-    pub fn pretty(&self) -> PrettyJson {
+    pub fn pretty(&self) -> PrettyJson<'_> {
         PrettyJson { inner: self }
     }
 
@@ -1300,7 +1300,7 @@ pub fn is_empty(&self) -> bool { self.stack.is_empty() }
     /// Provides access to the StackElement at a given index.
     /// lower indices are at the bottom of the stack while higher indices are
     /// at the top.
-    pub fn get(&self, idx: usize) -> StackElement {
+    pub fn get(&self, idx: usize) -> StackElement<'_> {
         match self.stack[idx] {
             InternalIndex(i) => StackElement::Index(i),
             InternalKey(start, size) => {
@@ -1311,8 +1311,8 @@ pub fn get(&self, idx: usize) -> StackElement {
         }
     }
 
-    /// Compares this stack with an array of StackElements.
-    pub fn is_equal_to(&self, rhs: &[StackElement]) -> bool {
+    /// Compares this stack with an array of StackElement<'_>s.
+    pub fn is_equal_to(&self, rhs: &[StackElement<'_>]) -> bool {
         if self.stack.len() != rhs.len() { return false; }
         for (i, r) in rhs.iter().enumerate() {
             if self.get(i) != *r { return false; }
@@ -1322,7 +1322,7 @@ pub fn is_equal_to(&self, rhs: &[StackElement]) -> bool {
 
     /// Returns true if the bottom-most elements of this stack are the same as
     /// the ones passed as parameter.
-    pub fn starts_with(&self, rhs: &[StackElement]) -> bool {
+    pub fn starts_with(&self, rhs: &[StackElement<'_>]) -> bool {
         if self.stack.len() < rhs.len() { return false; }
         for (i, r) in rhs.iter().enumerate() {
             if self.get(i) != *r { return false; }
@@ -1332,7 +1332,7 @@ pub fn starts_with(&self, rhs: &[StackElement]) -> bool {
 
     /// Returns true if the top-most elements of this stack are the same as
     /// the ones passed as parameter.
-    pub fn ends_with(&self, rhs: &[StackElement]) -> bool {
+    pub fn ends_with(&self, rhs: &[StackElement<'_>]) -> bool {
         if self.stack.len() < rhs.len() { return false; }
         let offset = self.stack.len() - rhs.len();
         for (i, r) in rhs.iter().enumerate() {
@@ -1342,7 +1342,7 @@ pub fn ends_with(&self, rhs: &[StackElement]) -> bool {
     }
 
     /// Returns the top-most element (if any).
-    pub fn top(&self) -> Option<StackElement> {
+    pub fn top(&self) -> Option<StackElement<'_>> {
         match self.stack.last() {
             None => None,
             Some(&InternalIndex(i)) => Some(StackElement::Index(i)),
@@ -2115,7 +2115,7 @@ fn $name(&mut self) -> DecodeResult<$ty> {
     }
 }
 
-impl ::Decoder for Decoder {
+impl crate::Decoder for Decoder {
     type Error = DecoderError;
 
     fn read_nil(&mut self) -> DecodeResult<()> {
@@ -2172,7 +2172,7 @@ fn read_char(&mut self) -> DecodeResult<char> {
         Err(ExpectedError("single character string".to_owned(), s.to_string()))
     }
 
-    fn read_str(&mut self) -> DecodeResult<Cow<str>> {
+    fn read_str(&mut self) -> DecodeResult<Cow<'_, str>> {
         expect!(self.pop(), String).map(Cow::Owned)
     }
 
@@ -2518,7 +2518,7 @@ fn write_str(&mut self, s: &str) -> fmt::Result {
 
 impl fmt::Display for Json {
     /// Encodes a json value into a string
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         let mut shim = FormatShim { inner: f };
         let mut encoder = Encoder::new(&mut shim);
         match self.encode(&mut encoder) {
@@ -2530,7 +2530,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
 
 impl<'a> fmt::Display for PrettyJson<'a> {
     /// Encodes a json value into a string
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         let mut shim = FormatShim { inner: f };
         let mut encoder = PrettyEncoder::new(&mut shim);
         match self.inner.encode(&mut encoder) {
@@ -2542,7 +2542,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
 
 impl<'a, T: Encodable> fmt::Display for AsJson<'a, T> {
     /// Encodes a json value into a string
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         let mut shim = FormatShim { inner: f };
         let mut encoder = Encoder::new(&mut shim);
         match self.inner.encode(&mut encoder) {
@@ -2562,7 +2562,7 @@ pub fn indent(mut self, indent: usize) -> AsPrettyJson<'a, T> {
 
 impl<'a, T: Encodable> fmt::Display for AsPrettyJson<'a, T> {
     /// Encodes a json value into a string
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         let mut shim = FormatShim { inner: f };
         let mut encoder = PrettyEncoder::new(&mut shim);
         if let Some(n) = self.indent {
@@ -2587,7 +2587,7 @@ mod tests {
     extern crate test;
     use self::Animal::*;
     use self::test::Bencher;
-    use {Encodable, Decodable};
+    use crate::{Encodable, Decodable};
     use super::Json::*;
     use super::ErrorCode::*;
     use super::ParserError::*;
@@ -3515,7 +3515,7 @@ fn indents(source: &str) -> usize {
     #[test]
     fn test_hashmap_with_enum_key() {
         use std::collections::HashMap;
-        use json;
+        use crate::json;
         #[derive(RustcEncodable, Eq, Hash, PartialEq, RustcDecodable, Debug)]
         enum Enum {
             Foo,
index e8d185a9cc0267df96e487b543284415d381ee5f..9b73a5e686ead544450bbde73070a226e70b570c 100644 (file)
@@ -10,6 +10,8 @@
        html_playground_url = "https://play.rust-lang.org/",
        test(attr(allow(unused_variables), deny(warnings))))]
 
+#![deny(rust_2018_idioms)]
+
 #![feature(box_syntax)]
 #![feature(core_intrinsics)]
 #![feature(specialization)]
@@ -22,8 +24,6 @@
 pub use self::serialize::{SpecializationError, SpecializedEncoder, SpecializedDecoder};
 pub use self::serialize::{UseSpecializedEncodable, UseSpecializedDecodable};
 
-extern crate smallvec;
-
 mod serialize;
 mod collection_impls;
 
@@ -34,5 +34,5 @@
 pub mod leb128;
 
 mod rustc_serialize {
-    pub use serialize::*;
+    pub use crate::serialize::*;
 }
index b8d4f8a79f34b49c16edaa8967a8a165f7d3cf27..8636c202d66ef11d244dd117e0a7daf8f75b2a71 100644 (file)
@@ -1,6 +1,6 @@
-use leb128::{self, read_signed_leb128, write_signed_leb128};
+use crate::leb128::{self, read_signed_leb128, write_signed_leb128};
 use std::borrow::Cow;
-use serialize;
+use crate::serialize;
 
 // -----------------------------------------------------------------------------
 // Encoder
@@ -312,7 +312,7 @@ fn read_char(&mut self) -> Result<char, Self::Error> {
     }
 
     #[inline]
-    fn read_str(&mut self) -> Result<Cow<str>, Self::Error> {
+    fn read_str(&mut self) -> Result<Cow<'_, str>, Self::Error> {
         let len = self.read_usize()?;
         let s = ::std::str::from_utf8(&self.data[self.position..self.position + len]).unwrap();
         self.position += len;
@@ -328,7 +328,7 @@ fn error(&mut self, err: &str) -> Self::Error {
 
 #[cfg(test)]
 mod tests {
-    use serialize::{Encodable, Decodable};
+    use crate::serialize::{Encodable, Decodable};
     use std::fmt::Debug;
     use super::{Encoder, Decoder};
 
index 03844b387ac81e0f8f01fda2682b1ffaf8ef7ade..977a36a220fdd9d22293d18910a6652bddd3581b 100644 (file)
@@ -175,7 +175,7 @@ pub trait Decoder {
     fn read_f64(&mut self) -> Result<f64, Self::Error>;
     fn read_f32(&mut self) -> Result<f32, Self::Error>;
     fn read_char(&mut self) -> Result<char, Self::Error>;
-    fn read_str(&mut self) -> Result<Cow<str>, Self::Error>;
+    fn read_str(&mut self) -> Result<Cow<'_, str>, Self::Error>;
 
     // Compound types:
     fn read_enum<T, F>(&mut self, _name: &str, f: F) -> Result<T, Self::Error>