diff --git a/serde/build.rs b/serde/build.rs index 453514c7..82129bc7 100644 --- a/serde/build.rs +++ b/serde/build.rs @@ -51,12 +51,6 @@ fn main() { println!("cargo:rustc-cfg=integer128"); } - // RangeToInclusive was stabilized in Rust 1.26: - // https://doc.rust-lang.org/std/ops/struct.RangeToInclusive.html - if minor >= 26 { - println!("cargo:rustc-cfg=range_to_inclusive"); - } - // Inclusive ranges methods stabilized in Rust 1.27: // https://github.com/rust-lang/rust/pull/50758 if minor >= 27 { diff --git a/serde/src/de/impls.rs b/serde/src/de/impls.rs index 57d8307e..fc85710e 100644 --- a/serde/src/de/impls.rs +++ b/serde/src/de/impls.rs @@ -2138,73 +2138,6 @@ where } } -impl<'de, Idx> Deserialize<'de> for RangeFrom -where - Idx: Deserialize<'de>, -{ - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - let field = range::Field::Start; - let start = deserializer.deserialize_struct( - "RangeFrom", - field.name_slice(), - range::UnboundedRangeVisitor { - expecting: "struct RangeFrom", - phantom: PhantomData, - field: field, - }, - )?; - Ok(start..) - } -} - -impl<'de, Idx> Deserialize<'de> for RangeTo -where - Idx: Deserialize<'de>, -{ - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - let field = range::Field::End; - let end = deserializer.deserialize_struct( - "RangeTo", - field.name_slice(), - range::UnboundedRangeVisitor { - expecting: "struct RangeTo", - phantom: PhantomData, - field: field, - }, - )?; - Ok(..end) - } -} - -#[cfg(range_to_inclusive)] -impl<'de, Idx> Deserialize<'de> for RangeToInclusive -where - Idx: Deserialize<'de>, -{ - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - let field = range::Field::End; - let end = deserializer.deserialize_struct( - "RangeToInclusive", - field.name_slice(), - range::UnboundedRangeVisitor { - expecting: "struct RangeToInclusive", - phantom: PhantomData, - field: field, - }, - )?; - Ok(RangeToInclusive { end: end }) - } -} - mod range { use lib::*; @@ -2216,31 +2149,11 @@ mod range { // // #[derive(Deserialize)] // #[serde(field_identifier, rename_all = "lowercase")] - #[derive(PartialEq)] - pub enum Field { + enum Field { Start, End, } - const FIELDS_START_ONLY: &'static [&'static str] = &["start"]; - const FIELD_END_ONLY: &'static [&'static str] = &["end"]; - - impl Field { - fn name(&self) -> &'static str { - match *self { - Field::Start => "start", - Field::End => "end", - } - } - - pub fn name_slice(&self) -> &'static [&'static str] { - match *self { - Field::Start => FIELDS_START_ONLY, - Field::End => FIELD_END_ONLY, - } - } - } - impl<'de> Deserialize<'de> for Field { fn deserialize(deserializer: D) -> Result where @@ -2352,62 +2265,6 @@ mod range { Ok((start, end)) } } - - pub struct UnboundedRangeVisitor { - pub expecting: &'static str, - pub phantom: PhantomData, - pub field: Field, - } - - impl<'de, Idx> Visitor<'de> for UnboundedRangeVisitor - where - Idx: Deserialize<'de>, - { - type Value = Idx; - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.write_str(self.expecting) - } - - fn visit_seq(self, mut seq: A) -> Result - where - A: SeqAccess<'de>, - { - let value: Idx = match try!(seq.next_element()) { - Some(value) => value, - None => { - return Err(Error::invalid_length(0, &self)); - } - }; - Ok(value) - } - - fn visit_map(self, mut map: A) -> Result - where - A: MapAccess<'de>, - { - let mut value: Option = None; - while let Some(key) = try!(map.next_key()) { - let key: Field = key; - match key { - ref key if *key == self.field => { - if value.is_some() { - return Err(::duplicate_field(key.name())); - } - value = Some(try!(map.next_value())); - } - key => { - return Err(::unknown_field(key.name(), self.field.name_slice())); - } - } - } - let value = match value { - Some(value) => value, - None => return Err(::missing_field(self.field.name())), - }; - Ok(value) - } - } } //////////////////////////////////////////////////////////////////////////////// diff --git a/serde/src/lib.rs b/serde/src/lib.rs index 2be5b471..9ae47ba6 100644 --- a/serde/src/lib.rs +++ b/serde/src/lib.rs @@ -143,7 +143,7 @@ mod lib { pub use self::core::default::{self, Default}; pub use self::core::fmt::{self, Debug, Display}; pub use self::core::marker::{self, PhantomData}; - pub use self::core::ops::{Range, RangeFrom, RangeTo}; + pub use self::core::ops::Range; pub use self::core::option::{self, Option}; pub use self::core::result::{self, Result}; @@ -213,9 +213,6 @@ mod lib { #[cfg(ops_bound)] pub use self::core::ops::Bound; - - #[cfg(range_to_inclusive)] - pub use self::core::ops::RangeToInclusive; } //////////////////////////////////////////////////////////////////////////////// diff --git a/serde/src/ser/impls.rs b/serde/src/ser/impls.rs index 0adfd535..99bf7e97 100644 --- a/serde/src/ser/impls.rs +++ b/serde/src/ser/impls.rs @@ -256,57 +256,6 @@ where //////////////////////////////////////////////////////////////////////////////// -impl Serialize for RangeFrom -where - Idx: Serialize, -{ - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - use super::SerializeStruct; - let mut state = try!(serializer.serialize_struct("RangeFrom", 1)); - try!(state.serialize_field("start", &self.start)); - state.end() - } -} - -//////////////////////////////////////////////////////////////////////////////// - -impl Serialize for RangeTo -where - Idx: Serialize, -{ - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - use super::SerializeStruct; - let mut state = try!(serializer.serialize_struct("RangeTo", 1)); - try!(state.serialize_field("end", &self.end)); - state.end() - } -} - -//////////////////////////////////////////////////////////////////////////////// -#[cfg(range_to_inclusive)] -impl Serialize for RangeToInclusive -where - Idx: Serialize, -{ - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - use super::SerializeStruct; - let mut state = try!(serializer.serialize_struct("RangeToInclusive", 1)); - try!(state.serialize_field("end", &self.end)); - state.end() - } -} - -//////////////////////////////////////////////////////////////////////////////// - #[cfg(any(ops_bound, collections_bound))] impl Serialize for Bound where diff --git a/test_suite/tests/test_de.rs b/test_suite/tests/test_de.rs index 8a4b346d..461494f3 100644 --- a/test_suite/tests/test_de.rs +++ b/test_suite/tests/test_de.rs @@ -837,30 +837,6 @@ declare_tests! { Token::SeqEnd, ], } - test_range_from { - 0u8.. => &[ - Token::Struct { name: "RangeFrom", len: 1 }, - Token::Str("start"), - Token::U8(0), - Token::StructEnd, - ], - } - test_range_to { - ..2u8 => &[ - Token::Struct { name: "RangeTo", len: 1 }, - Token::Str("end"), - Token::U8(2), - Token::StructEnd, - ], - } - test_range_to_inclusive { - ..=2u8 => &[ - Token::Struct { name: "RangeToInclusive", len: 1 }, - Token::Str("end"), - Token::U8(2), - Token::StructEnd, - ], - } test_bound { Bound::Unbounded::<()> => &[ Token::Enum { name: "Bound" }, diff --git a/test_suite/tests/test_ser.rs b/test_suite/tests/test_ser.rs index 9a56e9eb..034372bc 100644 --- a/test_suite/tests/test_ser.rs +++ b/test_suite/tests/test_ser.rs @@ -376,30 +376,6 @@ declare_tests! { Token::StructEnd, ], } - test_range_from { - 0u8.. => &[ - Token::Struct { name: "RangeFrom", len: 1 }, - Token::Str("start"), - Token::U8(0), - Token::StructEnd, - ], - } - test_range_to { - ..2u8 => &[ - Token::Struct { name: "RangeTo", len: 1 }, - Token::Str("end"), - Token::U8(2), - Token::StructEnd, - ], - } - test_range_to_inclusive { - ..=2u8 => &[ - Token::Struct { name: "RangeToInclusive", len: 1 }, - Token::Str("end"), - Token::U8(2), - Token::StructEnd, - ], - } test_bound { Bound::Unbounded::<()> => &[ Token::Enum { name: "Bound" },