Skip to content

Commit

Permalink
libcore: add Debug implementations to most missing types
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Mar 20, 2016
1 parent 235d774 commit e094593
Show file tree
Hide file tree
Showing 17 changed files with 319 additions and 34 deletions.
8 changes: 4 additions & 4 deletions src/libcore/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,14 @@ pub fn encode_utf16_raw(mut ch: u32, dst: &mut [u16]) -> Option<usize> {
///
/// [`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,
Expand Down Expand Up @@ -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),
Expand Down
5 changes: 5 additions & 0 deletions src/libcore/fmt/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -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>,
Expand Down
26 changes: 22 additions & 4 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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)]
Expand Down Expand Up @@ -1585,7 +1588,9 @@ impl<T: ?Sized> Debug for PhantomData<T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Copy + Debug> Debug for Cell<T> {
fn fmt(&self, f: &mut Formatter) -> Result {
write!(f, "Cell {{ value: {:?} }}", self.get())
f.debug_struct("Cell")
.field("value", &self.get())
.finish()
}
}

Expand All @@ -1594,9 +1599,15 @@ impl<T: ?Sized + Debug> Debug for RefCell<T> {
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", &"<borrowed>")
.finish()
}
BorrowState::Writing => write!(f, "RefCell {{ <borrowed> }}"),
}
}
}
Expand All @@ -1615,5 +1626,12 @@ impl<'b, T: ?Sized + Debug> Debug for RefMut<'b, T> {
}
}

#[stable(feature = "core_impl_debug", since = "1.9.0")]
impl<T: ?Sized + Debug> Debug for UnsafeCell<T> {
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.
1 change: 1 addition & 0 deletions src/libcore/fmt/rt/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions src/libcore/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@

use prelude::v1::*;

use fmt;
use marker;
use mem;

Expand Down Expand Up @@ -215,6 +216,13 @@ pub trait BuildHasher {
#[stable(since = "1.7.0", feature = "build_hasher")]
pub struct BuildHasherDefault<H>(marker::PhantomData<H>);

#[stable(since = "1.9.0", feature = "core_impl_debug")]
impl<H> fmt::Debug for BuildHasherDefault<H> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("BuildHasherDefault")
}
}

#[stable(since = "1.7.0", feature = "build_hasher")]
impl<H: Default + Hasher> BuildHasher for BuildHasherDefault<H> {
type Hasher = H;
Expand Down
1 change: 1 addition & 0 deletions src/libcore/hash/sip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit e094593

Please sign in to comment.