diff --git a/serde/src/de/impls.rs b/serde/src/de/impls.rs index 5c6045e6..5a672a03 100644 --- a/serde/src/de/impls.rs +++ b/serde/src/de/impls.rs @@ -2,7 +2,7 @@ #[cfg(feature = "std")] use std::borrow::Cow; -#[cfg(all(feature = "unstable", feature = "collections", not(feature = "std")))] +#[cfg(all(feature = "collections", not(feature = "std")))] use collections::borrow::Cow; #[cfg(all(feature = "collections", not(feature = "std")))] @@ -27,12 +27,13 @@ use std::collections::{ VecDeque, }; -#[cfg(all(feature = "unstable", feature = "collections"))] +#[cfg(feature = "collections")] use collections::enum_set::{CLike, EnumSet}; -#[cfg(all(feature = "unstable", feature = "collections"))] +#[cfg(feature = "collections")] use collections::borrow::ToOwned; use core::fmt; +#[cfg(feature = "std")] use core::hash::{Hash, BuildHasher}; use core::marker::PhantomData; #[cfg(feature = "std")] @@ -43,15 +44,15 @@ use core::str; #[cfg(feature = "std")] use std::rc::Rc; -#[cfg(all(feature = "unstable", feature = "alloc", not(feature = "std")))] +#[cfg(all(feature = "alloc", not(feature = "std")))] use alloc::rc::Rc; #[cfg(feature = "std")] use std::sync::Arc; -#[cfg(all(feature = "unstable", feature = "alloc", not(feature = "std")))] +#[cfg(all(feature = "alloc", not(feature = "std")))] use alloc::arc::Arc; -#[cfg(all(feature = "unstable", feature = "alloc", not(feature = "std")))] +#[cfg(all(feature = "alloc", not(feature = "std")))] use alloc::boxed::Box; #[cfg(feature = "std")] @@ -482,7 +483,7 @@ seq_impl!( BTreeSet::new(), BTreeSet::insert); -#[cfg(all(feature = "unstable", feature = "collections"))] +#[cfg(feature = "collections")] seq_impl!( EnumSet, EnumSetVisitor, diff --git a/serde/src/de/mod.rs b/serde/src/de/mod.rs index 967af350..3a51ead5 100644 --- a/serde/src/de/mod.rs +++ b/serde/src/de/mod.rs @@ -415,7 +415,7 @@ pub trait Deserialize: Sized { /// to deserialize it into a flat representation like `vec![1, 2, 3, 4, 5, 6]`. /// Allocating a brand new `Vec` for each subarray would be slow. Instead we /// would like to allocate a single `Vec` and then deserialize each subarray -/// into it. This requires stateful deserialization using the DeserializeSeed +/// into it. This requires stateful deserialization using the `DeserializeSeed` /// trait. /// /// ```rust diff --git a/serde/src/de/value.rs b/serde/src/de/value.rs index f34fb087..71bb353b 100644 --- a/serde/src/de/value.rs +++ b/serde/src/de/value.rs @@ -33,9 +33,7 @@ use collections::boxed::Box; #[cfg(all(feature = "collections", not(feature = "std")))] use collections::string::ToString; -#[cfg(all(feature = "unstable", feature = "collections"))] -use collections::borrow::ToOwned; - +#[cfg(feature = "std")] use core::hash::Hash; #[cfg(feature = "std")] use std::error; @@ -67,7 +65,7 @@ impl de::Error for Error { } #[cfg(not(any(feature = "std", feature = "collections")))] - fn custom(msg: T) -> Self { + fn custom(_msg: T) -> Self { Error(()) } } @@ -579,7 +577,7 @@ impl MapDeserializer } } - fn next(&mut self) -> Option<(::First, ::Second)> { + fn next_pair(&mut self) -> Option<(::First, ::Second)> { match self.iter.next() { Some(kv) => { self.count += 1; @@ -654,7 +652,7 @@ impl de::MapVisitor for MapDeserializer fn visit_key_seed(&mut self, seed: T) -> Result, Self::Error> where T: de::DeserializeSeed, { - match self.next() { + match self.next_pair() { Some((key, value)) => { self.value = Some(value); seed.deserialize(key.into_deserializer()).map(Some) @@ -677,7 +675,7 @@ impl de::MapVisitor for MapDeserializer where TK: de::DeserializeSeed, TV: de::DeserializeSeed { - match self.next() { + match self.next_pair() { Some((key, value)) => { let key = try!(kseed.deserialize(key.into_deserializer())); let value = try!(vseed.deserialize(value.into_deserializer())); @@ -704,7 +702,7 @@ impl de::SeqVisitor for MapDeserializer fn visit_seed(&mut self, seed: T) -> Result, Self::Error> where T: de::DeserializeSeed, { - match self.next() { + match self.next_pair() { Some((k, v)) => { let de = PairDeserializer(k, v, PhantomData); seed.deserialize(de).map(Some) @@ -993,8 +991,8 @@ mod private { } } - /// Avoid having to restate the generic types on MapDeserializer. The - /// Iterator::Item contains enough information to figure out K and V. + /// Avoid having to restate the generic types on `MapDeserializer`. The + /// `Iterator::Item` contains enough information to figure out K and V. pub trait Pair { type First; type Second; diff --git a/serde/src/lib.rs b/serde/src/lib.rs index 24f2a677..093fa286 100644 --- a/serde/src/lib.rs +++ b/serde/src/lib.rs @@ -11,30 +11,29 @@ #![doc(html_root_url="https://docs.serde.rs")] #![cfg_attr(not(feature = "std"), no_std)] -#![cfg_attr(feature = "unstable", feature(reflect_marker, unicode, nonzero, plugin, step_trait, zero_one, inclusive_range))] +#![cfg_attr(feature = "unstable", feature(nonzero, inclusive_range, zero_one))] #![cfg_attr(feature = "alloc", feature(alloc))] #![cfg_attr(feature = "collections", feature(collections, enumset))] +#![cfg_attr(feature = "clippy", feature(plugin))] #![cfg_attr(feature = "clippy", plugin(clippy))] -#![cfg_attr(feature = "clippy", allow(linkedlist))] - -#![cfg_attr(any(not(feature = "std"), feature = "unstable"), allow(unused_variables, unused_imports, unused_features, dead_code))] - +#![cfg_attr(feature = "clippy", allow(linkedlist, type_complexity))] #![deny(missing_docs)] -#[cfg(all(feature = "unstable", feature = "collections"))] +#[cfg(feature = "collections")] extern crate collections; -#[cfg(all(feature = "unstable", feature = "alloc"))] +#[cfg(feature = "alloc")] extern crate alloc; +#[cfg(feature = "unstable")] +extern crate core as actual_core; + #[cfg(feature = "std")] mod core { pub use std::{ops, hash, fmt, cmp, marker, mem, i8, i16, i32, i64, u8, u16, u32, u64, isize, usize, f32, f64, char, str, num, slice, iter, cell}; #[cfg(feature = "unstable")] - extern crate core; - #[cfg(feature = "unstable")] - pub use self::core::nonzero; + pub use actual_core::nonzero; } pub use ser::{Serialize, Serializer}; @@ -48,6 +47,6 @@ pub mod de; #[cfg(feature = "std")] pub mod iter; pub mod ser; -#[cfg(not(feature = "std"))] +#[cfg_attr(feature = "std", doc(hidden))] pub mod error; mod utils; diff --git a/serde/src/ser/impls.rs b/serde/src/ser/impls.rs index e89f0cd3..25789356 100644 --- a/serde/src/ser/impls.rs +++ b/serde/src/ser/impls.rs @@ -30,19 +30,18 @@ use collections::{ Vec, }; -#[cfg(all(feature = "unstable", feature = "collections"))] +#[cfg(feature = "collections")] use collections::enum_set::{CLike, EnumSet}; -#[cfg(all(feature = "unstable", feature = "collections"))] +#[cfg(feature = "collections")] use collections::borrow::ToOwned; +#[cfg(feature = "std")] use core::hash::{Hash, BuildHasher}; #[cfg(feature = "unstable")] use core::iter; #[cfg(feature = "std")] use std::net; #[cfg(feature = "unstable")] -use core::num; -#[cfg(feature = "unstable")] use core::ops; #[cfg(feature = "std")] use std::path; @@ -67,14 +66,13 @@ use core::marker::PhantomData; use core::nonzero::{NonZero, Zeroable}; use super::{ - Error, Serialize, - SerializeMap, SerializeSeq, - SerializeStruct, SerializeTuple, Serializer, }; +#[cfg(any(feature = "std", feature = "unstable"))] +use super::Error; #[cfg(feature = "unstable")] use super::Iterator; @@ -241,7 +239,7 @@ impl<'a, I> Serialize for Iterator // FIXME: use specialization to prevent invalidating the object in case of clonable iterators? let iter = match self.0.borrow_mut().take() { Some(iter) => iter.into_iter(), - None => return Err(S::Error::custom("Iterator used twice")), + None => return Err(Error::custom("Iterator used twice")), }; let size = match iter.size_hint() { (lo, Some(hi)) if lo == hi => Some(lo), @@ -286,7 +284,7 @@ impl Serialize for BTreeSet serialize_seq!(); } -#[cfg(all(feature = "unstable", feature = "collections"))] +#[cfg(feature = "collections")] impl Serialize for EnumSet where T: Serialize + CLike { @@ -573,6 +571,7 @@ macro_rules! serialize_map { fn serialize(&self, serializer: S) -> Result where S: Serializer, { + use super::SerializeMap; let mut map = try!(serializer.serialize_map(Some(self.len()))); for (k, v) in self { try!(map.serialize_key(k)); @@ -695,6 +694,7 @@ impl Serialize for Duration { fn serialize(&self, serializer: S) -> Result where S: Serializer, { + use super::SerializeStruct; let mut state = try!(serializer.serialize_struct("Duration", 2)); try!(state.serialize_field("secs", self.as_secs())); try!(state.serialize_field("nanos", self.subsec_nanos())); diff --git a/serde/src/ser/mod.rs b/serde/src/ser/mod.rs index 10b14fda..4131f0b2 100644 --- a/serde/src/ser/mod.rs +++ b/serde/src/ser/mod.rs @@ -15,11 +15,6 @@ use std::error; #[cfg(not(feature = "std"))] use error; -#[cfg(all(feature = "collections", not(feature = "std")))] -use collections::String; - -#[cfg(feature = "unstable")] -use core::marker::PhantomData; #[cfg(feature = "unstable")] use core::cell::RefCell;