From 1b016589133e48d34dd5ae1b440581ded4cb4cdb Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 8 May 2019 12:12:14 -0700 Subject: Migrate to 2018 edition. --- Cargo.toml | 1 + src/de.rs | 6 +- src/lib.rs | 8 +-- src/macros.rs | 2 +- src/map.rs | 10 +-- src/ser.rs | 2 +- src/value.rs | 150 ++++++++++++++++++++++----------------------- test-suite/Cargo.toml | 1 + test-suite/tests/macros.rs | 4 ++ test-suite/tests/serde.rs | 2 +- 10 files changed, 96 insertions(+), 90 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 408337d..29289ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ implementations of the standard Serialize/Deserialize traits for TOML data to facilitate deserializing and serializing Rust structures. """ categories = ["config", "encoding", "parser-implementations"] +edition = "2018" [workspace] members = ['test-suite'] diff --git a/src/de.rs b/src/de.rs index b23f03f..291da3b 100644 --- a/src/de.rs +++ b/src/de.rs @@ -15,9 +15,9 @@ use serde::de; use serde::de::value::BorrowedStrDeserializer; use serde::de::IntoDeserializer; -use datetime; -use spanned; -use tokens::{Error as TokenError, Span, Token, Tokenizer}; +use crate::datetime; +use crate::spanned; +use crate::tokens::{Error as TokenError, Span, Token, Tokenizer}; /// Deserializes a byte slice into a type. /// diff --git a/src/lib.rs b/src/lib.rs index e71f9f2..7e8dbbe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -159,15 +159,15 @@ extern crate linked_hash_map; pub mod map; pub mod value; #[doc(no_inline)] -pub use value::Value; +pub use crate::value::Value; mod datetime; pub mod ser; #[doc(no_inline)] -pub use ser::{to_string, to_string_pretty, to_vec, Serializer}; +pub use crate::ser::{to_string, to_string_pretty, to_vec, Serializer}; pub mod de; #[doc(no_inline)] -pub use de::{from_slice, from_str, Deserializer}; +pub use crate::de::{from_slice, from_str, Deserializer}; mod tokens; #[doc(hidden)] @@ -175,4 +175,4 @@ pub mod macros; mod spanned; #[doc(no_inline)] -pub use spanned::Spanned; +pub use crate::spanned::Spanned; diff --git a/src/macros.rs b/src/macros.rs index 57fdabb..9f11733 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,6 +1,6 @@ pub use serde::de::{Deserialize, IntoDeserializer}; -use value::{Array, Table, Value}; +use crate::value::{Array, Table, Value}; /// Construct a [`toml::Value`] from TOML syntax. /// diff --git a/src/map.rs b/src/map.rs index 59ae24e..3a2473a 100644 --- a/src/map.rs +++ b/src/map.rs @@ -16,7 +16,7 @@ use serde::{de, ser}; use std::fmt::{self, Debug}; -use value::Value; +use crate::value::Value; use std::hash::Hash; use std::iter::FromIterator; use std::borrow::Borrow; @@ -265,10 +265,10 @@ impl ser::Serialize for Map { S: ser::Serializer, { use serde::ser::SerializeMap; - let mut map = try!(serializer.serialize_map(Some(self.len()))); + let mut map = serializer.serialize_map(Some(self.len()))?; for (k, v) in self { - try!(map.serialize_key(k)); - try!(map.serialize_value(v)); + map.serialize_key(k)?; + map.serialize_value(v)?; } map.end() } @@ -304,7 +304,7 @@ impl<'de> de::Deserialize<'de> for Map { { let mut values = Map::new(); - while let Some((key, value)) = try!(visitor.next_entry()) { + while let Some((key, value)) = visitor.next_entry()? { values.insert(key, value); } diff --git a/src/ser.rs b/src/ser.rs index 60e5b50..2dcd962 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -32,7 +32,7 @@ use std::fmt::{self, Write}; use std::marker; use std::rc::Rc; -use datetime; +use crate::datetime; use serde::ser; /// Serialize the given data structure as a TOML byte vector. diff --git a/src/value.rs b/src/value.rs index dd849e5..0e463ec 100644 --- a/src/value.rs +++ b/src/value.rs @@ -11,10 +11,10 @@ use serde::de; use serde::de::IntoDeserializer; use serde::ser; -use datetime::{self, DatetimeFromString}; -pub use datetime::{Datetime, DatetimeParseError}; +use crate::datetime::{self, DatetimeFromString}; +pub use crate::datetime::{Datetime, DatetimeParseError}; -pub use map::Map; +pub use crate::map::Map; /// Representation of a TOML value. @@ -50,7 +50,7 @@ impl Value { /// /// This conversion can fail if `T`'s implementation of `Serialize` decides to /// fail, or if `T` contains a map with non-string keys. - pub fn try_from(value: T) -> Result + pub fn try_from(value: T) -> Result where T: ser::Serialize, { @@ -66,7 +66,7 @@ impl Value { /// something is wrong with the data, for example required struct fields are /// missing from the TOML map or some number is too big to fit in the expected /// primitive type. - pub fn try_into<'de, T>(self) -> Result + pub fn try_into<'de, T>(self) -> Result where T: de::Deserialize<'de>, { @@ -392,16 +392,16 @@ where impl fmt::Display for Value { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - ::ser::to_string(self) + crate::ser::to_string(self) .expect("Unable to represent value as string") .fmt(f) } } impl FromStr for Value { - type Err = ::de::Error; + type Err = crate::de::Error; fn from_str(s: &str) -> Result { - ::from_str(s) + crate::from_str(s) } } @@ -552,9 +552,9 @@ impl<'de> de::Deserialize<'de> for Value { } impl<'de> de::Deserializer<'de> for Value { - type Error = ::de::Error; + type Error = crate::de::Error; - fn deserialize_any(self, visitor: V) -> Result + fn deserialize_any(self, visitor: V) -> Result where V: de::Visitor<'de>, { @@ -595,7 +595,7 @@ impl<'de> de::Deserializer<'de> for Value { _name: &str, _variants: &'static [&'static str], visitor: V, - ) -> Result + ) -> Result where V: de::Visitor<'de>, { @@ -610,7 +610,7 @@ impl<'de> de::Deserializer<'de> for Value { // `None` is interpreted as a missing field so be sure to implement `Some` // as a present field. - fn deserialize_option(self, visitor: V) -> Result + fn deserialize_option(self, visitor: V) -> Result where V: de::Visitor<'de>, { @@ -621,7 +621,7 @@ impl<'de> de::Deserializer<'de> for Value { self, _name: &'static str, visitor: V, - ) -> Result + ) -> Result where V: de::Visitor<'de>, { @@ -648,9 +648,9 @@ impl SeqDeserializer { } impl<'de> de::SeqAccess<'de> for SeqDeserializer { - type Error = ::de::Error; + type Error = crate::de::Error; - fn next_element_seed(&mut self, seed: T) -> Result, ::de::Error> + fn next_element_seed(&mut self, seed: T) -> Result, crate::de::Error> where T: de::DeserializeSeed<'de>, { @@ -683,9 +683,9 @@ impl MapDeserializer { } impl<'de> de::MapAccess<'de> for MapDeserializer { - type Error = ::de::Error; + type Error = crate::de::Error; - fn next_key_seed(&mut self, seed: T) -> Result, ::de::Error> + fn next_key_seed(&mut self, seed: T) -> Result, crate::de::Error> where T: de::DeserializeSeed<'de>, { @@ -698,7 +698,7 @@ impl<'de> de::MapAccess<'de> for MapDeserializer { } } - fn next_value_seed(&mut self, seed: T) -> Result + fn next_value_seed(&mut self, seed: T) -> Result where T: de::DeserializeSeed<'de>, { @@ -720,7 +720,7 @@ impl<'de> de::MapAccess<'de> for MapDeserializer { } } -impl<'de> de::IntoDeserializer<'de, ::de::Error> for Value { +impl<'de> de::IntoDeserializer<'de, crate::de::Error> for Value { type Deserializer = Self; fn into_deserializer(self) -> Self { @@ -732,7 +732,7 @@ struct Serializer; impl ser::Serializer for Serializer { type Ok = Value; - type Error = ::ser::Error; + type Error = crate::ser::Error; type SerializeSeq = SerializeVec; type SerializeTuple = SerializeVec; @@ -740,41 +740,41 @@ impl ser::Serializer for Serializer { type SerializeTupleVariant = SerializeVec; type SerializeMap = SerializeMap; type SerializeStruct = SerializeMap; - type SerializeStructVariant = ser::Impossible; + type SerializeStructVariant = ser::Impossible; - fn serialize_bool(self, value: bool) -> Result { + fn serialize_bool(self, value: bool) -> Result { Ok(Value::Boolean(value)) } - fn serialize_i8(self, value: i8) -> Result { + fn serialize_i8(self, value: i8) -> Result { self.serialize_i64(value.into()) } - fn serialize_i16(self, value: i16) -> Result { + fn serialize_i16(self, value: i16) -> Result { self.serialize_i64(value.into()) } - fn serialize_i32(self, value: i32) -> Result { + fn serialize_i32(self, value: i32) -> Result { self.serialize_i64(value.into()) } - fn serialize_i64(self, value: i64) -> Result { + fn serialize_i64(self, value: i64) -> Result { Ok(Value::Integer(value.into())) } - fn serialize_u8(self, value: u8) -> Result { + fn serialize_u8(self, value: u8) -> Result { self.serialize_i64(value.into()) } - fn serialize_u16(self, value: u16) -> Result { + fn serialize_u16(self, value: u16) -> Result { self.serialize_i64(value.into()) } - fn serialize_u32(self, value: u32) -> Result { + fn serialize_u32(self, value: u32) -> Result { self.serialize_i64(value.into()) } - fn serialize_u64(self, value: u64) -> Result { + fn serialize_u64(self, value: u64) -> Result { if value <= i64::max_value() as u64 { self.serialize_i64(value as i64) } else { @@ -782,35 +782,35 @@ impl ser::Serializer for Serializer { } } - fn serialize_f32(self, value: f32) -> Result { + fn serialize_f32(self, value: f32) -> Result { self.serialize_f64(value.into()) } - fn serialize_f64(self, value: f64) -> Result { + fn serialize_f64(self, value: f64) -> Result { Ok(Value::Float(value)) } - fn serialize_char(self, value: char) -> Result { + fn serialize_char(self, value: char) -> Result { let mut s = String::new(); s.push(value); self.serialize_str(&s) } - fn serialize_str(self, value: &str) -> Result { + fn serialize_str(self, value: &str) -> Result { Ok(Value::String(value.to_owned())) } - fn serialize_bytes(self, value: &[u8]) -> Result { + fn serialize_bytes(self, value: &[u8]) -> Result { let vec = value.iter().map(|&b| Value::Integer(b.into())).collect(); Ok(Value::Array(vec)) } - fn serialize_unit(self) -> Result { - Err(::ser::Error::UnsupportedType) + fn serialize_unit(self) -> Result { + Err(crate::ser::Error::UnsupportedType) } - fn serialize_unit_struct(self, _name: &'static str) -> Result { - Err(::ser::Error::UnsupportedType) + fn serialize_unit_struct(self, _name: &'static str) -> Result { + Err(crate::ser::Error::UnsupportedType) } fn serialize_unit_variant( @@ -818,7 +818,7 @@ impl ser::Serializer for Serializer { _name: &'static str, _variant_index: u32, _variant: &'static str, - ) -> Result { + ) -> Result { self.serialize_str(_variant) } @@ -826,7 +826,7 @@ impl ser::Serializer for Serializer { self, _name: &'static str, value: &T, - ) -> Result + ) -> Result where T: ser::Serialize, { @@ -839,31 +839,31 @@ impl ser::Serializer for Serializer { _variant_index: u32, _variant: &'static str, _value: &T, - ) -> Result + ) -> Result where T: ser::Serialize, { - Err(::ser::Error::UnsupportedType) + Err(crate::ser::Error::UnsupportedType) } - fn serialize_none(self) -> Result { - Err(::ser::Error::UnsupportedNone) + fn serialize_none(self) -> Result { + Err(crate::ser::Error::UnsupportedNone) } - fn serialize_some(self, value: &T) -> Result + fn serialize_some(self, value: &T) -> Result where T: ser::Serialize, { value.serialize(self) } - fn serialize_seq(self, len: Option) -> Result { + fn serialize_seq(self, len: Option) -> Result { Ok(SerializeVec { vec: Vec::with_capacity(len.unwrap_or(0)), }) } - fn serialize_tuple(self, len: usize) -> Result { + fn serialize_tuple(self, len: usize) -> Result { self.serialize_seq(Some(len)) } @@ -871,7 +871,7 @@ impl ser::Serializer for Serializer { self, _name: &'static str, len: usize, - ) -> Result { + ) -> Result { self.serialize_seq(Some(len)) } @@ -881,11 +881,11 @@ impl ser::Serializer for Serializer { _variant_index: u32, _variant: &'static str, len: usize, - ) -> Result { + ) -> Result { self.serialize_seq(Some(len)) } - fn serialize_map(self, _len: Option) -> Result { + fn serialize_map(self, _len: Option) -> Result { Ok(SerializeMap { map: Map::new(), next_key: None, @@ -896,7 +896,7 @@ impl ser::Serializer for Serializer { self, _name: &'static str, len: usize, - ) -> Result { + ) -> Result { self.serialize_map(Some(len)) } @@ -906,8 +906,8 @@ impl ser::Serializer for Serializer { _variant_index: u32, _variant: &'static str, _len: usize, - ) -> Result { - Err(::ser::Error::UnsupportedType) + ) -> Result { + Err(crate::ser::Error::UnsupportedType) } } @@ -922,9 +922,9 @@ struct SerializeMap { impl ser::SerializeSeq for SerializeVec { type Ok = Value; - type Error = ::ser::Error; + type Error = crate::ser::Error; - fn serialize_element(&mut self, value: &T) -> Result<(), ::ser::Error> + fn serialize_element(&mut self, value: &T) -> Result<(), crate::ser::Error> where T: ser::Serialize, { @@ -932,75 +932,75 @@ impl ser::SerializeSeq for SerializeVec { Ok(()) } - fn end(self) -> Result { + fn end(self) -> Result { Ok(Value::Array(self.vec)) } } impl ser::SerializeTuple for SerializeVec { type Ok = Value; - type Error = ::ser::Error; + type Error = crate::ser::Error; - fn serialize_element(&mut self, value: &T) -> Result<(), ::ser::Error> + fn serialize_element(&mut self, value: &T) -> Result<(), crate::ser::Error> where T: ser::Serialize, { ser::SerializeSeq::serialize_element(self, value) } - fn end(self) -> Result { + fn end(self) -> Result { ser::SerializeSeq::end(self) } } impl ser::SerializeTupleStruct for SerializeVec { type Ok = Value; - type Error = ::ser::Error; + type Error = crate::ser::Error; - fn serialize_field(&mut self, value: &T) -> Result<(), ::ser::Error> + fn serialize_field(&mut self, value: &T) -> Result<(), crate::ser::Error> where T: ser::Serialize, { ser::SerializeSeq::serialize_element(self, value) } - fn end(self) -> Result { + fn end(self) -> Result { ser::SerializeSeq::end(self) } } impl ser::SerializeTupleVariant for SerializeVec { type Ok = Value; - type Error = ::ser::Error; + type Error = crate::ser::Error; - fn serialize_field(&mut self, value: &T) -> Result<(), ::ser::Error> + fn serialize_field(&mut self, value: &T) -> Result<(), crate::ser::Error> where T: ser::Serialize, { ser::SerializeSeq::serialize_element(self, value) } - fn end(self) -> Result { + fn end(self) -> Result { ser::SerializeSeq::end(self) } } impl ser::SerializeMap for SerializeMap { type Ok = Value; - type Error = ::ser::Error; + type Error = crate::ser::Error; - fn serialize_key(&mut self, key: &T) -> Result<(), ::ser::Error> + fn serialize_key(&mut self, key: &T) -> Result<(), crate::ser::Error> where T: ser::Serialize, { match Value::try_from(key)? { Value::String(s) => self.next_key = Some(s), - _ => return Err(::ser::Error::KeyNotString), + _ => return Err(crate::ser::Error::KeyNotString), }; Ok(()) } - fn serialize_value(&mut self, value: &T) -> Result<(), ::ser::Error> + fn serialize_value(&mut self, value: &T) -> Result<(), crate::ser::Error> where T: ser::Serialize, { @@ -1010,26 +1010,26 @@ impl ser::SerializeMap for SerializeMap { Ok(value) => { self.map.insert(key, value); } - Err(::ser::Error::UnsupportedNone) => {} + Err(crate::ser::Error::UnsupportedNone) => {} Err(e) => return Err(e), } Ok(()) } - fn end(self) -> Result { + fn end(self) -> Result { Ok(Value::Table(self.map)) } } impl ser::SerializeStruct for SerializeMap { type Ok = Value; - type Error = ::ser::Error; + type Error = crate::ser::Error; fn serialize_field( &mut self, key: &'static str, value: &T, - ) -> Result<(), ::ser::Error> + ) -> Result<(), crate::ser::Error> where T: ser::Serialize, { @@ -1037,7 +1037,7 @@ impl ser::SerializeStruct for SerializeMap { ser::SerializeMap::serialize_value(self, value) } - fn end(self) -> Result { + fn end(self) -> Result { ser::SerializeMap::end(self) } } diff --git a/test-suite/Cargo.toml b/test-suite/Cargo.toml index 10ffbcb..fa81741 100644 --- a/test-suite/Cargo.toml +++ b/test-suite/Cargo.toml @@ -4,6 +4,7 @@ version = "0.0.0" authors = ["Alex Crichton "] build = "build.rs" publish = false +edition = "2018" [build-dependencies] rustc_version = "0.2" diff --git a/test-suite/tests/macros.rs b/test-suite/tests/macros.rs index 6b77c81..db94549 100644 --- a/test-suite/tests/macros.rs +++ b/test-suite/tests/macros.rs @@ -7,6 +7,8 @@ use std::f64; macro_rules! table { ($($key:expr => $value:expr,)*) => {{ + // https://github.com/rust-lang/rust/issues/60643 + #[allow(unused_mut)] let mut table = toml::value::Table::new(); $( table.insert($key.to_string(), $value.into()); @@ -17,6 +19,8 @@ macro_rules! table { macro_rules! array { ($($element:expr,)*) => {{ + // https://github.com/rust-lang/rust/issues/60643 + #[allow(unused_mut)] let mut array = toml::value::Array::new(); $( array.push($element.into()); diff --git a/test-suite/tests/serde.rs b/test-suite/tests/serde.rs index 9bbf7e0..c72bfc6 100644 --- a/test-suite/tests/serde.rs +++ b/test-suite/tests/serde.rs @@ -130,7 +130,7 @@ fn application_decode_error() { struct Range10(usize); impl<'de> Deserialize<'de> for Range10 { fn deserialize>(d: D) -> Result { - let x: usize = try!(Deserialize::deserialize(d)); + let x: usize = Deserialize::deserialize(d)?; if x > 10 { Err(serde::de::Error::custom("more than 10")) } else { -- cgit v1.2.3