Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
c410-f3r committed Aug 5, 2018
1 parent 8b2e6ba commit 8eb195e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
6 changes: 6 additions & 0 deletions serde/build.rs
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions serde/src/de/impls.rs
Expand Up @@ -2196,8 +2196,8 @@ where

////////////////////////////////////////////////////////////////////////////////

#[cfg(feature = "std")]
impl<'de, Idx> Deserialize<'de> for ops::RangeInclusive<Idx>
#[cfg(range_inclusive)]
impl<'de, Idx> Deserialize<'de> for RangeInclusive<Idx>
where
Idx: Deserialize<'de>,
{
Expand Down Expand Up @@ -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))
}
}
Expand All @@ -2262,7 +2262,7 @@ where
where
Idx: Deserialize<'de>,
{
type Value = ops::RangeInclusive<Idx>;
type Value = RangeInclusive<Idx>;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("struct RangeInclusive")
Expand All @@ -2284,7 +2284,7 @@ where
return Err(Error::invalid_length(1, &self));
}
};
Ok(start..=end)
Ok(RangeInclusive::new(start, end))
}

fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
Expand Down Expand Up @@ -2317,7 +2317,7 @@ where
Some(end) => end,
None => return Err(<A::Error as Error>::missing_field("end")),
};
Ok(start..=end)
Ok(RangeInclusive::new(start, end))
}
}

Expand Down
3 changes: 3 additions & 0 deletions serde/src/lib.rs
Expand Up @@ -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;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions serde/src/ser/impls.rs
Expand Up @@ -246,8 +246,8 @@ where

////////////////////////////////////////////////////////////////////////////////

#[cfg(feature = "std")]
impl<Idx> Serialize for ops::RangeInclusive<Idx>
#[cfg(range_inclusive)]
impl<Idx> Serialize for RangeInclusive<Idx>
where
Idx: Serialize,
{
Expand Down

0 comments on commit 8eb195e

Please sign in to comment.