From e0945937c4d6786af0b03a11c8cec2c34cde7662 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Fri, 4 Mar 2016 18:49:43 -0800 Subject: [PATCH] libcore: add Debug implementations to most missing types --- src/libcore/char.rs | 8 +-- src/libcore/fmt/builders.rs | 5 ++ src/libcore/fmt/mod.rs | 26 ++++++-- src/libcore/fmt/rt/v1.rs | 1 + src/libcore/hash/mod.rs | 8 +++ src/libcore/hash/sip.rs | 1 + src/libcore/iter.rs | 115 +++++++++++++++++++++++++++++---- src/libcore/lib.rs | 1 + src/libcore/num/flt2dec/mod.rs | 1 + src/libcore/option.rs | 6 +- src/libcore/ptr.rs | 2 + src/libcore/raw.rs | 2 + src/libcore/result.rs | 3 + src/libcore/slice.rs | 79 ++++++++++++++++++++++ src/libcore/str/mod.rs | 75 +++++++++++++++++++-- src/libcore/str/pattern.rs | 18 +++++- src/libcore/sync/atomic.rs | 2 +- 17 files changed, 319 insertions(+), 34 deletions(-) diff --git a/src/libcore/char.rs b/src/libcore/char.rs index abae121ea7f53..5b39fa42c6edb 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -416,14 +416,14 @@ pub fn encode_utf16_raw(mut ch: u32, dst: &mut [u16]) -> Option { /// /// [`escape_unicode()`]: ../../std/primitive.char.html#method.escape_unicode /// [`char`]: ../../std/primitive.char.html -#[derive(Clone)] +#[derive(Clone, Debug)] #[stable(feature = "rust1", since = "1.0.0")] pub struct EscapeUnicode { c: char, state: EscapeUnicodeState } -#[derive(Clone)] +#[derive(Clone, Debug)] enum EscapeUnicodeState { Backslash, Type, @@ -496,13 +496,13 @@ impl Iterator for EscapeUnicode { /// /// [`escape_default()`]: ../../std/primitive.char.html#method.escape_default /// [`char`]: ../../std/primitive.char.html -#[derive(Clone)] +#[derive(Clone, Debug)] #[stable(feature = "rust1", since = "1.0.0")] pub struct EscapeDefault { state: EscapeDefaultState } -#[derive(Clone)] +#[derive(Clone, Debug)] enum EscapeDefaultState { Backslash(char), Char(char), diff --git a/src/libcore/fmt/builders.rs b/src/libcore/fmt/builders.rs index b562e658b62db..5ad1e2009b3f6 100644 --- a/src/libcore/fmt/builders.rs +++ b/src/libcore/fmt/builders.rs @@ -54,6 +54,7 @@ impl<'a, 'b: 'a> fmt::Write for PadAdapter<'a, 'b> { /// /// Constructed by the `Formatter::debug_struct` method. #[must_use] +#[allow(missing_debug_implementations)] #[stable(feature = "debug_builders", since = "1.2.0")] pub struct DebugStruct<'a, 'b: 'a> { fmt: &'a mut fmt::Formatter<'b>, @@ -120,6 +121,7 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> { /// /// Constructed by the `Formatter::debug_tuple` method. #[must_use] +#[allow(missing_debug_implementations)] #[stable(feature = "debug_builders", since = "1.2.0")] pub struct DebugTuple<'a, 'b: 'a> { fmt: &'a mut fmt::Formatter<'b>, @@ -231,6 +233,7 @@ impl<'a, 'b: 'a> DebugInner<'a, 'b> { /// /// Constructed by the `Formatter::debug_set` method. #[must_use] +#[allow(missing_debug_implementations)] #[stable(feature = "debug_builders", since = "1.2.0")] pub struct DebugSet<'a, 'b: 'a> { inner: DebugInner<'a, 'b>, @@ -279,6 +282,7 @@ impl<'a, 'b: 'a> DebugSet<'a, 'b> { /// /// Constructed by the `Formatter::debug_list` method. #[must_use] +#[allow(missing_debug_implementations)] #[stable(feature = "debug_builders", since = "1.2.0")] pub struct DebugList<'a, 'b: 'a> { inner: DebugInner<'a, 'b>, @@ -327,6 +331,7 @@ impl<'a, 'b: 'a> DebugList<'a, 'b> { /// /// Constructed by the `Formatter::debug_map` method. #[must_use] +#[allow(missing_debug_implementations)] #[stable(feature = "debug_builders", since = "1.2.0")] pub struct DebugMap<'a, 'b: 'a> { fmt: &'a mut fmt::Formatter<'b>, diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 7f7bfe73c51e4..d2da16624cabe 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -14,7 +14,7 @@ use prelude::v1::*; -use cell::{Cell, RefCell, Ref, RefMut, BorrowState}; +use cell::{UnsafeCell, Cell, RefCell, Ref, RefMut, BorrowState}; use marker::PhantomData; use mem; use num::flt2dec; @@ -25,6 +25,7 @@ use str; #[unstable(feature = "fmt_flags_align", issue = "27726")] /// Possible alignments returned by `Formatter::align` +#[derive(Debug)] pub enum Alignment { /// Indication that contents should be left-aligned. Left, @@ -152,6 +153,7 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { /// A struct to represent both where to emit formatting strings to and how they /// should be formatted. A mutable version of this is passed to all formatting /// traits. +#[allow(missing_debug_implementations)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Formatter<'a> { flags: u32, @@ -175,6 +177,7 @@ enum Void {} /// compile time it is ensured that the function and the value have the correct /// types, and then this struct is used to canonicalize arguments to one type. #[derive(Copy)] +#[allow(missing_debug_implementations)] #[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "0")] #[doc(hidden)] @@ -1585,7 +1588,9 @@ impl Debug for PhantomData { #[stable(feature = "rust1", since = "1.0.0")] impl Debug for Cell { fn fmt(&self, f: &mut Formatter) -> Result { - write!(f, "Cell {{ value: {:?} }}", self.get()) + f.debug_struct("Cell") + .field("value", &self.get()) + .finish() } } @@ -1594,9 +1599,15 @@ impl Debug for RefCell { fn fmt(&self, f: &mut Formatter) -> Result { match self.borrow_state() { BorrowState::Unused | BorrowState::Reading => { - write!(f, "RefCell {{ value: {:?} }}", self.borrow()) + f.debug_struct("RefCell") + .field("value", &self.borrow()) + .finish() + } + BorrowState::Writing => { + f.debug_struct("RefCell") + .field("value", &"") + .finish() } - BorrowState::Writing => write!(f, "RefCell {{ }}"), } } } @@ -1615,5 +1626,12 @@ impl<'b, T: ?Sized + Debug> Debug for RefMut<'b, T> { } } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl Debug for UnsafeCell { + fn fmt(&self, f: &mut Formatter) -> Result { + f.pad("UnsafeCell") + } +} + // If you expected tests to be here, look instead at the run-pass/ifmt.rs test, // it's a lot easier than creating all of the rt::Piece structures here. diff --git a/src/libcore/fmt/rt/v1.rs b/src/libcore/fmt/rt/v1.rs index f889045a3f595..6b31e040622cd 100644 --- a/src/libcore/fmt/rt/v1.rs +++ b/src/libcore/fmt/rt/v1.rs @@ -13,6 +13,7 @@ //! //! These definitions are similar to their `ct` equivalents, but differ in that //! these can be statically allocated and are slightly optimized for the runtime +#![allow(missing_debug_implementations)] #[derive(Copy, Clone)] pub struct Argument { diff --git a/src/libcore/hash/mod.rs b/src/libcore/hash/mod.rs index 3c219692bc48d..4d0fed9833436 100644 --- a/src/libcore/hash/mod.rs +++ b/src/libcore/hash/mod.rs @@ -73,6 +73,7 @@ use prelude::v1::*; +use fmt; use marker; use mem; @@ -215,6 +216,13 @@ pub trait BuildHasher { #[stable(since = "1.7.0", feature = "build_hasher")] pub struct BuildHasherDefault(marker::PhantomData); +#[stable(since = "1.9.0", feature = "core_impl_debug")] +impl fmt::Debug for BuildHasherDefault { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("BuildHasherDefault") + } +} + #[stable(since = "1.7.0", feature = "build_hasher")] impl BuildHasher for BuildHasherDefault { type Hasher = H; diff --git a/src/libcore/hash/sip.rs b/src/libcore/hash/sip.rs index 342071f1b51b7..a1a306d5c7d7d 100644 --- a/src/libcore/hash/sip.rs +++ b/src/libcore/hash/sip.rs @@ -30,6 +30,7 @@ use super::Hasher; /// Although the SipHash algorithm is considered to be generally strong, /// it is not intended for cryptographic purposes. As such, all /// cryptographic uses of this implementation are _strongly discouraged_. +#[derive(Debug)] #[stable(feature = "rust1", since = "1.0.0")] pub struct SipHasher { k0: u64, diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index def44e1a9ceba..72421e94a4355 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -303,6 +303,7 @@ use clone::Clone; use cmp; use cmp::{Ord, PartialOrd, PartialEq, Ordering}; use default::Default; +use fmt; use marker; use mem; use num::{Zero, One}; @@ -2929,7 +2930,7 @@ impl ExactSizeIterator for Zip /// /// [`rev()`]: trait.Iterator.html#method.rev /// [`Iterator`]: trait.Iterator.html -#[derive(Clone)] +#[derive(Clone, Debug)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] pub struct Rev { @@ -2961,7 +2962,7 @@ impl DoubleEndedIterator for Rev where I: DoubleEndedIterator { /// [`Iterator`]: trait.Iterator.html #[stable(feature = "iter_cloned", since = "1.1.0")] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct Cloned { it: I, } @@ -3002,7 +3003,7 @@ impl<'a, I, T: 'a> ExactSizeIterator for Cloned /// /// [`cycle()`]: trait.Iterator.html#method.cycle /// [`Iterator`]: trait.Iterator.html -#[derive(Clone)] +#[derive(Clone, Debug)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] pub struct Cycle { @@ -3040,7 +3041,7 @@ impl Iterator for Cycle where I: Clone + Iterator { /// /// [`chain()`]: trait.Iterator.html#method.chain /// [`Iterator`]: trait.Iterator.html -#[derive(Clone)] +#[derive(Clone, Debug)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] pub struct Chain { @@ -3062,7 +3063,7 @@ pub struct Chain { // // The fourth state (neither iterator is remaining) only occurs after Chain has // returned None once, so we don't need to store this state. -#[derive(Clone)] +#[derive(Clone, Debug)] enum ChainState { // both front and back iterator are remaining Both, @@ -3184,7 +3185,7 @@ impl DoubleEndedIterator for Chain where /// /// [`zip()`]: trait.Iterator.html#method.zip /// [`Iterator`]: trait.Iterator.html -#[derive(Clone)] +#[derive(Clone, Debug)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] pub struct Zip { @@ -3307,6 +3308,15 @@ pub struct Map { f: F, } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl fmt::Debug for Map { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Map") + .field("iter", &self.iter) + .finish() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Iterator for Map where F: FnMut(I::Item) -> B { type Item = B; @@ -3347,6 +3357,15 @@ pub struct Filter { predicate: P, } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl fmt::Debug for Filter { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Filter") + .field("iter", &self.iter) + .finish() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Iterator for Filter where P: FnMut(&I::Item) -> bool { type Item = I::Item; @@ -3398,6 +3417,15 @@ pub struct FilterMap { f: F, } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl fmt::Debug for FilterMap { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("FilterMap") + .field("iter", &self.iter) + .finish() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Iterator for FilterMap where F: FnMut(I::Item) -> Option, @@ -3443,7 +3471,7 @@ impl DoubleEndedIterator for FilterMap /// /// [`enumerate()`]: trait.Iterator.html#method.enumerate /// [`Iterator`]: trait.Iterator.html -#[derive(Clone)] +#[derive(Clone, Debug)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] pub struct Enumerate { @@ -3517,7 +3545,7 @@ impl DoubleEndedIterator for Enumerate where /// /// [`peekable()`]: trait.Iterator.html#method.peekable /// [`Iterator`]: trait.Iterator.html -#[derive(Clone)] +#[derive(Clone, Debug)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] pub struct Peekable { @@ -3676,6 +3704,16 @@ pub struct SkipWhile { predicate: P, } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl fmt::Debug for SkipWhile { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("SkipWhile") + .field("iter", &self.iter) + .field("flag", &self.flag) + .finish() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Iterator for SkipWhile where P: FnMut(&I::Item) -> bool @@ -3716,6 +3754,16 @@ pub struct TakeWhile { predicate: P, } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl fmt::Debug for TakeWhile { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("TakeWhile") + .field("iter", &self.iter) + .field("flag", &self.flag) + .finish() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Iterator for TakeWhile where P: FnMut(&I::Item) -> bool @@ -3752,7 +3800,7 @@ impl Iterator for TakeWhile /// /// [`skip()`]: trait.Iterator.html#method.skip /// [`Iterator`]: trait.Iterator.html -#[derive(Clone)] +#[derive(Clone, Debug)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] pub struct Skip { @@ -3843,7 +3891,7 @@ impl DoubleEndedIterator for Skip where I: DoubleEndedIterator + ExactSize /// /// [`take()`]: trait.Iterator.html#method.take /// [`Iterator`]: trait.Iterator.html -#[derive(Clone)] +#[derive(Clone, Debug)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] pub struct Take { @@ -3914,6 +3962,16 @@ pub struct Scan { state: St, } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl fmt::Debug for Scan { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Scan") + .field("iter", &self.iter) + .field("state", &self.state) + .finish() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Iterator for Scan where I: Iterator, @@ -3951,6 +4009,19 @@ pub struct FlatMap { backiter: Option, } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl fmt::Debug for FlatMap + where U::IntoIter: fmt::Debug +{ + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("FlatMap") + .field("iter", &self.iter) + .field("frontiter", &self.frontiter) + .field("backiter", &self.backiter) + .finish() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Iterator for FlatMap where F: FnMut(I::Item) -> U, @@ -4014,7 +4085,7 @@ impl DoubleEndedIterator for FlatMap wher /// /// [`fuse()`]: trait.Iterator.html#method.fuse /// [`Iterator`]: trait.Iterator.html -#[derive(Clone)] +#[derive(Clone, Debug)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] pub struct Fuse { @@ -4109,6 +4180,15 @@ pub struct Inspect { f: F, } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl fmt::Debug for Inspect { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Inspect") + .field("iter", &self.iter) + .finish() + } +} + impl Inspect where F: FnMut(&I::Item) { #[inline] fn do_inspect(&mut self, elt: Option) -> Option { @@ -4272,7 +4352,7 @@ step_impl_no_between!(u64 i64); /// The resulting iterator handles overflow by stopping. The `A` /// parameter is the type being iterated over, while `R` is the range /// type (usually one of `std::ops::{Range, RangeFrom, RangeInclusive}`. -#[derive(Clone)] +#[derive(Clone, Debug)] #[unstable(feature = "step_by", reason = "recent addition", issue = "27741")] pub struct StepBy { @@ -4679,7 +4759,7 @@ impl DoubleEndedIterator for ops::RangeInclusive where /// This `struct` is created by the [`repeat()`] function. See its documentation for more. /// /// [`repeat()`]: fn.repeat.html -#[derive(Clone)] +#[derive(Clone, Debug)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Repeat { element: A @@ -4761,6 +4841,13 @@ pub fn repeat(elt: T) -> Repeat { #[stable(feature = "iter_empty", since = "1.2.0")] pub struct Empty(marker::PhantomData); +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty") + } +} + #[stable(feature = "iter_empty", since = "1.2.0")] impl Iterator for Empty { type Item = T; @@ -4830,7 +4917,7 @@ pub fn empty() -> Empty { /// This `struct` is created by the [`once()`] function. See its documentation for more. /// /// [`once()`]: fn.once.html -#[derive(Clone)] +#[derive(Clone, Debug)] #[stable(feature = "iter_once", since = "1.2.0")] pub struct Once { inner: ::option::IntoIter diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 13d3f42ba1896..fa1fea3534095 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -56,6 +56,7 @@ #![no_core] #![deny(missing_docs)] +#![deny(missing_debug_implementations)] #![cfg_attr(not(stage0), deny(warnings))] #![feature(allow_internal_unstable)] diff --git a/src/libcore/num/flt2dec/mod.rs b/src/libcore/num/flt2dec/mod.rs index b9a7afc400d5e..b549f33424264 100644 --- a/src/libcore/num/flt2dec/mod.rs +++ b/src/libcore/num/flt2dec/mod.rs @@ -222,6 +222,7 @@ impl<'a> Part<'a> { /// Formatted result containing one or more parts. /// This can be written to the byte buffer or converted to the allocated string. +#[allow(missing_debug_implementations)] #[derive(Clone)] pub struct Formatted<'a> { /// A byte slice representing a sign, either `""`, `"-"` or `"+"`. diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 56b84fd6a64dd..dd60e8797a948 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -763,7 +763,7 @@ impl<'a, T> IntoIterator for &'a mut Option { // The Option Iterators ///////////////////////////////////////////////////////////////////////////// -#[derive(Clone)] +#[derive(Clone, Debug)] struct Item { opt: Option } @@ -796,6 +796,7 @@ impl ExactSizeIterator for Item {} /// An iterator over a reference of the contained item in an Option. #[stable(feature = "rust1", since = "1.0.0")] +#[derive(Debug)] pub struct Iter<'a, A: 'a> { inner: Item<&'a A> } #[stable(feature = "rust1", since = "1.0.0")] @@ -826,6 +827,7 @@ impl<'a, A> Clone for Iter<'a, A> { /// An iterator over a mutable reference of the contained item in an Option. #[stable(feature = "rust1", since = "1.0.0")] +#[derive(Debug)] pub struct IterMut<'a, A: 'a> { inner: Item<&'a mut A> } #[stable(feature = "rust1", since = "1.0.0")] @@ -848,7 +850,7 @@ impl<'a, A> DoubleEndedIterator for IterMut<'a, A> { impl<'a, A> ExactSizeIterator for IterMut<'a, A> {} /// An iterator over the item contained inside an Option. -#[derive(Clone)] +#[derive(Clone, Debug)] #[stable(feature = "rust1", since = "1.0.0")] pub struct IntoIter { inner: Item } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 3cbeac450e218..ec72809acab6a 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -520,6 +520,7 @@ impl PartialOrd for *mut T { /// modified without a unique path to the `Unique` reference. Useful /// for building abstractions like `Vec` or `Box`, which /// internally use raw pointers to manage the memory that they own. +#[allow(missing_debug_implementations)] #[unstable(feature = "unique", reason = "needs an RFC to flesh out design", issue = "27730")] pub struct Unique { @@ -592,6 +593,7 @@ impl fmt::Pointer for Unique { /// of this wrapper has shared ownership of the referent. Useful for /// building abstractions like `Rc` or `Arc`, which internally /// use raw pointers to manage the memory that they own. +#[allow(missing_debug_implementations)] #[unstable(feature = "shared", reason = "needs an RFC to flesh out design", issue = "27730")] pub struct Shared { diff --git a/src/libcore/raw.rs b/src/libcore/raw.rs index 84467be6eca56..20c85b5efc116 100644 --- a/src/libcore/raw.rs +++ b/src/libcore/raw.rs @@ -59,6 +59,7 @@ use mem; /// println!("data pointer = {:?}, length = {}", repr.data, repr.len); /// ``` #[repr(C)] +#[allow(missing_debug_implementations)] pub struct Slice { pub data: *const T, pub len: usize, @@ -143,6 +144,7 @@ impl Clone for Slice { /// ``` #[repr(C)] #[derive(Copy, Clone)] +#[allow(missing_debug_implementations)] pub struct TraitObject { pub data: *mut (), pub vtable: *mut (), diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 09f612c20ecdf..7f8cf531d2617 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -799,6 +799,7 @@ impl<'a, T, E> IntoIterator for &'a mut Result { ///////////////////////////////////////////////////////////////////////////// /// An iterator over a reference to the `Ok` variant of a `Result`. +#[derive(Debug)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Iter<'a, T: 'a> { inner: Option<&'a T> } @@ -830,6 +831,7 @@ impl<'a, T> Clone for Iter<'a, T> { } /// An iterator over a mutable reference to the `Ok` variant of a `Result`. +#[derive(Debug)] #[stable(feature = "rust1", since = "1.0.0")] pub struct IterMut<'a, T: 'a> { inner: Option<&'a mut T> } @@ -856,6 +858,7 @@ impl<'a, T> DoubleEndedIterator for IterMut<'a, T> { impl<'a, T> ExactSizeIterator for IterMut<'a, T> {} /// An iterator over the value in a `Ok` variant of a `Result`. +#[derive(Debug)] #[stable(feature = "rust1", since = "1.0.0")] pub struct IntoIter { inner: Option } diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 6e0e972fa0c83..c27d307fdc643 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -38,6 +38,7 @@ use cmp::{Ordering, PartialEq, PartialOrd, Eq, Ord}; use cmp::Ordering::{Less, Equal, Greater}; use cmp; use default::Default; +use fmt; use intrinsics::assume; use iter::*; use ops::{FnMut, self, Index}; @@ -879,6 +880,15 @@ pub struct Iter<'a, T: 'a> { _marker: marker::PhantomData<&'a T>, } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl<'a, T: 'a + fmt::Debug> fmt::Debug for Iter<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("Iter") + .field(&self.as_slice()) + .finish() + } +} + #[stable(feature = "rust1", since = "1.0.0")] unsafe impl<'a, T: Sync> Sync for Iter<'a, T> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -927,6 +937,15 @@ pub struct IterMut<'a, T: 'a> { _marker: marker::PhantomData<&'a mut T>, } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl<'a, T: 'a + fmt::Debug> fmt::Debug for IterMut<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("IterMut") + .field(&make_slice!(self.ptr, self.end)) + .finish() + } +} + #[stable(feature = "rust1", since = "1.0.0")] unsafe impl<'a, T: Sync> Sync for IterMut<'a, T> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -982,6 +1001,16 @@ pub struct Split<'a, T:'a, P> where P: FnMut(&T) -> bool { finished: bool } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for Split<'a, T, P> where P: FnMut(&T) -> bool { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Split") + .field("v", &self.v) + .field("finished", &self.finished) + .finish() + } +} + // FIXME(#19839) Remove in favor of `#[derive(Clone)]` #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T, P> Clone for Split<'a, T, P> where P: Clone + FnMut(&T) -> bool { @@ -1055,6 +1084,16 @@ pub struct SplitMut<'a, T:'a, P> where P: FnMut(&T) -> bool { finished: bool } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for SplitMut<'a, T, P> where P: FnMut(&T) -> bool { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("SplitMut") + .field("v", &self.v) + .field("finished", &self.finished) + .finish() + } +} + impl<'a, T, P> SplitIter for SplitMut<'a, T, P> where P: FnMut(&T) -> bool { #[inline] fn finish(&mut self) -> Option<&'a mut [T]> { @@ -1129,6 +1168,7 @@ impl<'a, T, P> DoubleEndedIterator for SplitMut<'a, T, P> where /// An private iterator over subslices separated by elements that /// match a predicate function, splitting at most a fixed number of /// times. +#[derive(Debug)] struct GenericSplitN { iter: I, count: usize, @@ -1164,6 +1204,15 @@ pub struct SplitN<'a, T: 'a, P> where P: FnMut(&T) -> bool { inner: GenericSplitN> } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for SplitN<'a, T, P> where P: FnMut(&T) -> bool { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("SplitN") + .field("inner", &self.inner) + .finish() + } +} + /// An iterator over subslices separated by elements that match a /// predicate function, limited to a given number of splits, starting /// from the end of the slice. @@ -1172,6 +1221,15 @@ pub struct RSplitN<'a, T: 'a, P> where P: FnMut(&T) -> bool { inner: GenericSplitN> } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for RSplitN<'a, T, P> where P: FnMut(&T) -> bool { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("RSplitN") + .field("inner", &self.inner) + .finish() + } +} + /// An iterator over subslices separated by elements that match a predicate /// function, limited to a given number of splits. #[stable(feature = "rust1", since = "1.0.0")] @@ -1179,6 +1237,15 @@ pub struct SplitNMut<'a, T: 'a, P> where P: FnMut(&T) -> bool { inner: GenericSplitN> } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for SplitNMut<'a, T, P> where P: FnMut(&T) -> bool { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("SplitNMut") + .field("inner", &self.inner) + .finish() + } +} + /// An iterator over subslices separated by elements that match a /// predicate function, limited to a given number of splits, starting /// from the end of the slice. @@ -1187,6 +1254,15 @@ pub struct RSplitNMut<'a, T: 'a, P> where P: FnMut(&T) -> bool { inner: GenericSplitN> } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for RSplitNMut<'a, T, P> where P: FnMut(&T) -> bool { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("RSplitNMut") + .field("inner", &self.inner) + .finish() + } +} + macro_rules! forward_iterator { ($name:ident: $elem:ident, $iter_of:ty) => { #[stable(feature = "rust1", since = "1.0.0")] @@ -1214,6 +1290,7 @@ forward_iterator! { SplitNMut: T, &'a mut [T] } forward_iterator! { RSplitNMut: T, &'a mut [T] } /// An iterator over overlapping subslices of length `size`. +#[derive(Debug)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Windows<'a, T:'a> { v: &'a [T], @@ -1307,6 +1384,7 @@ impl<'a, T> ExactSizeIterator for Windows<'a, T> {} /// /// When the slice len is not evenly divided by the chunk size, the last slice /// of the iteration will be the remainder. +#[derive(Debug)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Chunks<'a, T:'a> { v: &'a [T], @@ -1407,6 +1485,7 @@ impl<'a, T> ExactSizeIterator for Chunks<'a, T> {} /// An iterator over a slice in (non-overlapping) mutable chunks (`size` /// elements at a time). When the slice len is not evenly divided by the chunk /// size, the last slice of the iteration will be the remainder. +#[derive(Debug)] #[stable(feature = "rust1", since = "1.0.0")] pub struct ChunksMut<'a, T:'a> { v: &'a mut [T], diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index f9d1902bea7a7..c9dd02563dd39 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -323,7 +323,7 @@ Section: Iterators /// Created with the method [`chars()`]. /// /// [`chars()`]: ../../std/primitive.str.html#method.chars -#[derive(Clone)] +#[derive(Clone, Debug)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Chars<'a> { iter: slice::Iter<'a, u8> @@ -468,7 +468,7 @@ impl<'a> Chars<'a> { } /// Iterator for a string's characters and their byte offsets. -#[derive(Clone)] +#[derive(Clone, Debug)] #[stable(feature = "rust1", since = "1.0.0")] pub struct CharIndices<'a> { front_offset: usize, @@ -533,7 +533,7 @@ impl<'a> CharIndices<'a> { /// /// [`bytes()`]: ../../std/primitive.str.html#method.bytes #[stable(feature = "rust1", since = "1.0.0")] -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct Bytes<'a>(Cloned>); #[stable(feature = "rust1", since = "1.0.0")] @@ -662,6 +662,17 @@ macro_rules! generate_pattern_iterators { $(#[$common_stability_attribute])* pub struct $forward_iterator<'a, P: Pattern<'a>>($internal_iterator<'a, P>); + $(#[$common_stability_attribute])* + impl<'a, P: Pattern<'a>> fmt::Debug for $forward_iterator<'a, P> + where P::Searcher: fmt::Debug + { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple(stringify!($forward_iterator)) + .field(&self.0) + .finish() + } + } + $(#[$common_stability_attribute])* impl<'a, P: Pattern<'a>> Iterator for $forward_iterator<'a, P> { type Item = $iterty; @@ -685,6 +696,17 @@ macro_rules! generate_pattern_iterators { $(#[$common_stability_attribute])* pub struct $reverse_iterator<'a, P: Pattern<'a>>($internal_iterator<'a, P>); + $(#[$common_stability_attribute])* + impl<'a, P: Pattern<'a>> fmt::Debug for $reverse_iterator<'a, P> + where P::Searcher: fmt::Debug + { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple(stringify!($reverse_iterator)) + .field(&self.0) + .finish() + } + } + $(#[$common_stability_attribute])* impl<'a, P: Pattern<'a>> Iterator for $reverse_iterator<'a, P> where P::Searcher: ReverseSearcher<'a> @@ -746,6 +768,7 @@ derive_pattern_clone!{ clone SplitInternal with |s| SplitInternal { matcher: s.matcher.clone(), ..*s } } + struct SplitInternal<'a, P: Pattern<'a>> { start: usize, end: usize, @@ -754,6 +777,18 @@ struct SplitInternal<'a, P: Pattern<'a>> { finished: bool, } +impl<'a, P: Pattern<'a>> fmt::Debug for SplitInternal<'a, P> where P::Searcher: fmt::Debug { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("SplitInternal") + .field("start", &self.start) + .field("end", &self.end) + .field("matcher", &self.matcher) + .field("allow_trailing_empty", &self.allow_trailing_empty) + .field("finished", &self.finished) + .finish() + } +} + impl<'a, P: Pattern<'a>> SplitInternal<'a, P> { #[inline] fn get_end(&mut self) -> Option<&'a str> { @@ -852,12 +887,22 @@ derive_pattern_clone!{ clone SplitNInternal with |s| SplitNInternal { iter: s.iter.clone(), ..*s } } + struct SplitNInternal<'a, P: Pattern<'a>> { iter: SplitInternal<'a, P>, /// The number of splits remaining count: usize, } +impl<'a, P: Pattern<'a>> fmt::Debug for SplitNInternal<'a, P> where P::Searcher: fmt::Debug { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("SplitNInternal") + .field("iter", &self.iter) + .field("count", &self.count) + .finish() + } +} + impl<'a, P: Pattern<'a>> SplitNInternal<'a, P> { #[inline] fn next(&mut self) -> Option<&'a str> { @@ -902,8 +947,17 @@ derive_pattern_clone!{ clone MatchIndicesInternal with |s| MatchIndicesInternal(s.0.clone()) } + struct MatchIndicesInternal<'a, P: Pattern<'a>>(P::Searcher); +impl<'a, P: Pattern<'a>> fmt::Debug for MatchIndicesInternal<'a, P> where P::Searcher: fmt::Debug { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("MatchIndicesInternal") + .field(&self.0) + .finish() + } +} + impl<'a, P: Pattern<'a>> MatchIndicesInternal<'a, P> { #[inline] fn next(&mut self) -> Option<(usize, &'a str)> { @@ -944,8 +998,17 @@ derive_pattern_clone!{ clone MatchesInternal with |s| MatchesInternal(s.0.clone()) } + struct MatchesInternal<'a, P: Pattern<'a>>(P::Searcher); +impl<'a, P: Pattern<'a>> fmt::Debug for MatchesInternal<'a, P> where P::Searcher: fmt::Debug { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("MatchesInternal") + .field(&self.0) + .finish() + } +} + impl<'a, P: Pattern<'a>> MatchesInternal<'a, P> { #[inline] fn next(&mut self) -> Option<&'a str> { @@ -988,7 +1051,7 @@ generate_pattern_iterators! { /// /// [`lines()`]: ../../std/primitive.str.html#method.lines #[stable(feature = "rust1", since = "1.0.0")] -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct Lines<'a>(Map, LinesAnyMap>); #[stable(feature = "rust1", since = "1.0.0")] @@ -1019,7 +1082,7 @@ impl<'a> DoubleEndedIterator for Lines<'a> { /// [`lines_any()`]: ../../std/primitive.str.html#method.lines_any #[stable(feature = "rust1", since = "1.0.0")] #[rustc_deprecated(since = "1.4.0", reason = "use lines()/Lines instead now")] -#[derive(Clone)] +#[derive(Clone, Debug)] #[allow(deprecated)] pub struct LinesAny<'a>(Lines<'a>); @@ -1242,7 +1305,7 @@ static UTF8_CHAR_WIDTH: [u8; 256] = [ /// Struct that contains a `char` and the index of the first byte of /// the next `char` in a string. This can be used as a data structure /// for iterating over the UTF-8 bytes of a string. -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug)] #[unstable(feature = "str_char", reason = "existence of this struct is uncertain as it is frequently \ able to be replaced with char.len_utf8() and/or \ diff --git a/src/libcore/str/pattern.rs b/src/libcore/str/pattern.rs index abad29cb7751e..b803539e12b1a 100644 --- a/src/libcore/str/pattern.rs +++ b/src/libcore/str/pattern.rs @@ -20,6 +20,7 @@ use prelude::v1::*; use cmp; +use fmt; use usize; // Pattern @@ -275,7 +276,7 @@ impl<'a> CharEq for &'a [char] { struct CharEqPattern(C); -#[derive(Clone)] +#[derive(Clone, Debug)] struct CharEqSearcher<'a, C: CharEq> { char_eq: C, haystack: &'a str, @@ -415,7 +416,7 @@ macro_rules! searcher_methods { ///////////////////////////////////////////////////////////////////////////// /// Associated type for `>::Searcher`. -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct CharSearcher<'a>( as Pattern<'a>>::Searcher); unsafe impl<'a> Searcher<'a> for CharSearcher<'a> { @@ -440,7 +441,7 @@ impl<'a> Pattern<'a> for char { // Todo: Change / Remove due to ambiguity in meaning. /// Associated type for `<&[char] as Pattern<'a>>::Searcher`. -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct CharSliceSearcher<'a, 'b>( as Pattern<'a>>::Searcher); unsafe impl<'a, 'b> Searcher<'a> for CharSliceSearcher<'a, 'b> { @@ -467,6 +468,17 @@ impl<'a, 'b> Pattern<'a> for &'b [char] { pub struct CharPredicateSearcher<'a, F>( as Pattern<'a>>::Searcher) where F: FnMut(char) -> bool; +impl<'a, F> fmt::Debug for CharPredicateSearcher<'a, F> + where F: FnMut(char) -> bool +{ + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("CharPredicateSearcher") + .field("haystack", &self.0.haystack) + .field("char_indices", &self.0.char_indices) + .field("ascii_only", &self.0.ascii_only) + .finish() + } +} unsafe impl<'a, F> Searcher<'a> for CharPredicateSearcher<'a, F> where F: FnMut(char) -> bool { diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs index 0c831bff763d0..9077837fc332e 100644 --- a/src/libcore/sync/atomic.rs +++ b/src/libcore/sync/atomic.rs @@ -160,7 +160,7 @@ unsafe impl Sync for AtomicPtr {} /// Rust's memory orderings are [the same as /// LLVM's](http://llvm.org/docs/LangRef.html#memory-model-for-concurrent-operations). #[stable(feature = "rust1", since = "1.0.0")] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug)] pub enum Ordering { /// No ordering constraints, only atomic operations. Corresponds to LLVM's /// `Monotonic` ordering.