From 8eb195edf01f46e5a0defd97c0a61a31d18942fe Mon Sep 17 00:00:00 2001 From: Caio Date: Sun, 5 Aug 2018 17:38:41 -0300 Subject: [PATCH] Fix tests --- serde/build.rs | 6 ++++++ serde/src/de/impls.rs | 12 ++++++------ serde/src/lib.rs | 3 +++ serde/src/ser/impls.rs | 4 ++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/serde/build.rs b/serde/build.rs index a187cf85c..3e82dddab 100644 --- a/serde/build.rs +++ b/serde/build.rs @@ -36,6 +36,12 @@ fn main() { println!("cargo:rustc-cfg=integer128"); } + // Inclusive ranges methods stabilized in Rust 1.27: + // https://github.com/rust-lang/rust/pull/50758 + if minor >= 27 { + println!("cargo:rustc-cfg=range_inclusive"); + } + // Non-zero integers stabilized in Rust 1.28: // https://github.com/rust-lang/rust/pull/50808 if minor >= 28 { diff --git a/serde/src/de/impls.rs b/serde/src/de/impls.rs index ae02760db..39a8cf4e0 100644 --- a/serde/src/de/impls.rs +++ b/serde/src/de/impls.rs @@ -2196,8 +2196,8 @@ where //////////////////////////////////////////////////////////////////////////////// -#[cfg(feature = "std")] -impl<'de, Idx> Deserialize<'de> for ops::RangeInclusive +#[cfg(range_inclusive)] +impl<'de, Idx> Deserialize<'de> for RangeInclusive where Idx: Deserialize<'de>, { @@ -2243,7 +2243,7 @@ where b"start" => Ok(Field::Start), b"end" => Ok(Field::End), _ => { - let value = String::from_utf8_lossy(value); + let value = ::export::from_utf8_lossy(value); Err(Error::unknown_field(&value, FIELDS)) } } @@ -2262,7 +2262,7 @@ where where Idx: Deserialize<'de>, { - type Value = ops::RangeInclusive; + type Value = RangeInclusive; fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { formatter.write_str("struct RangeInclusive") @@ -2284,7 +2284,7 @@ where return Err(Error::invalid_length(1, &self)); } }; - Ok(start..=end) + Ok(RangeInclusive::new(start, end)) } fn visit_map(self, mut map: A) -> Result @@ -2317,7 +2317,7 @@ where Some(end) => end, None => return Err(::missing_field("end")), }; - Ok(start..=end) + Ok(RangeInclusive::new(start, end)) } } diff --git a/serde/src/lib.rs b/serde/src/lib.rs index ff6dbd3ce..79fd5b7ba 100644 --- a/serde/src/lib.rs +++ b/serde/src/lib.rs @@ -226,6 +226,9 @@ mod lib { #[cfg(any(core_duration, feature = "std"))] pub use self::core::time::Duration; + + #[cfg(range_inclusive)] + pub use self::core::ops::RangeInclusive; } //////////////////////////////////////////////////////////////////////////////// diff --git a/serde/src/ser/impls.rs b/serde/src/ser/impls.rs index 558cb74c7..624d07a5b 100644 --- a/serde/src/ser/impls.rs +++ b/serde/src/ser/impls.rs @@ -246,8 +246,8 @@ where //////////////////////////////////////////////////////////////////////////////// -#[cfg(feature = "std")] -impl Serialize for ops::RangeInclusive +#[cfg(range_inclusive)] +impl Serialize for RangeInclusive where Idx: Serialize, {