From 2efb95015bab91c5b914a70e646725cd1b3b2358 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 10 Apr 2017 19:06:42 -0700 Subject: [PATCH] Appease Rust 1.13.0 --- serde/src/export.rs | 42 +++++++++++++++++++++++------------------- serde/src/lib.rs | 10 ++++++---- serde/src/ser/mod.rs | 2 +- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/serde/src/export.rs b/serde/src/export.rs index a2014233..0c88f5e3 100644 --- a/serde/src/export.rs +++ b/serde/src/export.rs @@ -1,5 +1,3 @@ -use lib::*; - pub use lib::clone::Clone; pub use lib::convert::{From, Into}; pub use lib::default::Default; @@ -8,22 +6,28 @@ pub use lib::marker::PhantomData; pub use lib::option::Option::{self, None, Some}; pub use lib::result::Result::{self, Ok, Err}; -#[cfg(any(feature = "std", feature = "collections"))] -pub fn from_utf8_lossy(bytes: &[u8]) -> Cow { - String::from_utf8_lossy(bytes) -} +pub use self::string::from_utf8_lossy; -// The generated code calls this like: -// -// let value = &_serde::export::from_utf8_lossy(bytes); -// Err(_serde::de::Error::unknown_variant(value, VARIANTS)) -// -// so it is okay for the return type to be different from the std case as long -// as the above works. -#[cfg(not(any(feature = "std", feature = "collections")))] -pub fn from_utf8_lossy(bytes: &[u8]) -> &str { - // Three unicode replacement characters if it fails. They look like a - // white-on-black question mark. The user will recognize it as invalid - // UTF-8. - str::from_utf8(bytes).unwrap_or("\u{fffd}\u{fffd}\u{fffd}") +mod string { + use lib::*; + + #[cfg(any(feature = "std", feature = "collections"))] + pub fn from_utf8_lossy(bytes: &[u8]) -> Cow { + String::from_utf8_lossy(bytes) + } + + // The generated code calls this like: + // + // let value = &_serde::export::from_utf8_lossy(bytes); + // Err(_serde::de::Error::unknown_variant(value, VARIANTS)) + // + // so it is okay for the return type to be different from the std case as long + // as the above works. + #[cfg(not(any(feature = "std", feature = "collections")))] + pub fn from_utf8_lossy(bytes: &[u8]) -> &str { + // Three unicode replacement characters if it fails. They look like a + // white-on-black question mark. The user will recognize it as invalid + // UTF-8. + str::from_utf8(bytes).unwrap_or("\u{fffd}\u{fffd}\u{fffd}") + } } diff --git a/serde/src/lib.rs b/serde/src/lib.rs index 873c9a17..92d65818 100644 --- a/serde/src/lib.rs +++ b/serde/src/lib.rs @@ -81,10 +81,12 @@ extern crate core; /// `collections` crates. This avoids elaborate import wrangling having to /// happen in every module. mod lib { - #[cfg(feature = "std")] - use std as core; - #[cfg(not(feature = "std"))] - use core; + mod core { + #[cfg(feature = "std")] + pub use std::*; + #[cfg(not(feature = "std"))] + pub use core::*; + } pub use self::core::{cmp, iter, mem, ops, str}; pub use self::core::{i8, i16, i32, i64, isize}; diff --git a/serde/src/ser/mod.rs b/serde/src/ser/mod.rs index 21655493..5e44895a 100644 --- a/serde/src/ser/mod.rs +++ b/serde/src/ser/mod.rs @@ -866,7 +866,7 @@ pub trait Serializer: Sized { fn collect_str(self, value: &T) -> Result where T: Display { - use self::fmt::Write; + use lib::fmt::Write; let mut string = String::new(); write!(string, "{}", value).unwrap(); self.serialize_str(&string)