Implement fmt::Debug for all structures in libstd.

Part of https://github.com/rust-lang/rust/issues/31869.

Also turn on the `missing_debug_implementations` lint at the crate
level.
This commit is contained in:
Corey Farwell 2016-11-25 13:21:49 -05:00
parent 1f965cc8e9
commit 86fc63e62d
31 changed files with 515 additions and 7 deletions

View File

@ -12,6 +12,7 @@
#![stable(feature = "rust1", since = "1.0.0")]
use fmt;
use mem;
use ops::Range;
use iter::FusedIterator;
@ -370,6 +371,13 @@ impl ExactSizeIterator for EscapeDefault {}
#[unstable(feature = "fused", issue = "35602")]
impl FusedIterator for EscapeDefault {}
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for EscapeDefault {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("EscapeDefault { .. }")
}
}
static ASCII_LOWERCASE_MAP: [u8; 256] = [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,

View File

@ -1276,6 +1276,15 @@ impl<'a, K, V> Clone for Iter<'a, K, V> {
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<'a, K: Debug, V: Debug> fmt::Debug for Iter<'a, K, V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_list()
.entries(self.clone())
.finish()
}
}
/// HashMap mutable values iterator.
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IterMut<'a, K: 'a, V: 'a> {
@ -1285,7 +1294,7 @@ pub struct IterMut<'a, K: 'a, V: 'a> {
/// HashMap move iterator.
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IntoIter<K, V> {
inner: table::IntoIter<K, V>,
pub(super) inner: table::IntoIter<K, V>,
}
/// HashMap keys iterator.
@ -1302,6 +1311,15 @@ impl<'a, K, V> Clone for Keys<'a, K, V> {
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<'a, K: Debug, V: Debug> fmt::Debug for Keys<'a, K, V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_list()
.entries(self.clone())
.finish()
}
}
/// HashMap values iterator.
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Values<'a, K: 'a, V: 'a> {
@ -1316,10 +1334,19 @@ impl<'a, K, V> Clone for Values<'a, K, V> {
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<'a, K: Debug, V: Debug> fmt::Debug for Values<'a, K, V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_list()
.entries(self.clone())
.finish()
}
}
/// HashMap drain iterator.
#[stable(feature = "drain", since = "1.6.0")]
pub struct Drain<'a, K: 'a, V: 'a> {
inner: table::Drain<'a, K, V>,
pub(super) inner: table::Drain<'a, K, V>,
}
/// Mutable HashMap values iterator.
@ -1557,6 +1584,18 @@ impl<'a, K, V> ExactSizeIterator for IterMut<'a, K, V> {
#[unstable(feature = "fused", issue = "35602")]
impl<'a, K, V> FusedIterator for IterMut<'a, K, V> {}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<'a, K, V> fmt::Debug for IterMut<'a, K, V>
where K: fmt::Debug,
V: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_list()
.entries(self.inner.iter())
.finish()
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<K, V> Iterator for IntoIter<K, V> {
type Item = (K, V);
@ -1580,6 +1619,15 @@ impl<K, V> ExactSizeIterator for IntoIter<K, V> {
#[unstable(feature = "fused", issue = "35602")]
impl<K, V> FusedIterator for IntoIter<K, V> {}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<K: Debug, V: Debug> fmt::Debug for IntoIter<K, V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_list()
.entries(self.inner.iter())
.finish()
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, K, V> Iterator for Keys<'a, K, V> {
type Item = &'a K;
@ -1649,6 +1697,18 @@ impl<'a, K, V> ExactSizeIterator for ValuesMut<'a, K, V> {
#[unstable(feature = "fused", issue = "35602")]
impl<'a, K, V> FusedIterator for ValuesMut<'a, K, V> {}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<'a, K, V> fmt::Debug for ValuesMut<'a, K, V>
where K: fmt::Debug,
V: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_list()
.entries(self.inner.inner.iter())
.finish()
}
}
#[stable(feature = "drain", since = "1.6.0")]
impl<'a, K, V> Iterator for Drain<'a, K, V> {
type Item = (K, V);
@ -1672,6 +1732,18 @@ impl<'a, K, V> ExactSizeIterator for Drain<'a, K, V> {
#[unstable(feature = "fused", issue = "35602")]
impl<'a, K, V> FusedIterator for Drain<'a, K, V> {}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<'a, K, V> fmt::Debug for Drain<'a, K, V>
where K: fmt::Debug,
V: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_list()
.entries(self.inner.iter())
.finish()
}
}
impl<'a, K, V> Entry<'a, K, V> {
#[stable(feature = "rust1", since = "1.0.0")]
/// Ensures a value is in the entry by inserting the default if empty, and returns
@ -2148,6 +2220,13 @@ impl Default for RandomState {
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for RandomState {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("RandomState { .. }")
}
}
impl<K, S, Q: ?Sized> super::Recover<Q> for HashMap<K, (), S>
where K: Eq + Hash + Borrow<Q>,
S: BuildHasher,

View File

@ -948,6 +948,15 @@ impl<'a, K> ExactSizeIterator for Iter<'a, K> {
#[unstable(feature = "fused", issue = "35602")]
impl<'a, K> FusedIterator for Iter<'a, K> {}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<'a, K: fmt::Debug> fmt::Debug for Iter<'a, K> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_list()
.entries(self.clone())
.finish()
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<K> Iterator for IntoIter<K> {
type Item = K;
@ -968,6 +977,16 @@ impl<K> ExactSizeIterator for IntoIter<K> {
#[unstable(feature = "fused", issue = "35602")]
impl<K> FusedIterator for IntoIter<K> {}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<K: fmt::Debug> fmt::Debug for IntoIter<K> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let entries_iter = self.iter.inner.iter().map(|(k, _)| k);
f.debug_list()
.entries(entries_iter)
.finish()
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, K> Iterator for Drain<'a, K> {
type Item = K;
@ -988,6 +1007,16 @@ impl<'a, K> ExactSizeIterator for Drain<'a, K> {
#[unstable(feature = "fused", issue = "35602")]
impl<'a, K> FusedIterator for Drain<'a, K> {}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<'a, K: fmt::Debug> fmt::Debug for Drain<'a, K> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let entries_iter = self.iter.inner.iter().map(|(k, _)| k);
f.debug_list()
.entries(entries_iter)
.finish()
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T, S> Clone for Intersection<'a, T, S> {
fn clone(&self) -> Intersection<'a, T, S> {
@ -1021,6 +1050,18 @@ impl<'a, T, S> Iterator for Intersection<'a, T, S>
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<'a, T, S> fmt::Debug for Intersection<'a, T, S>
where T: fmt::Debug + Eq + Hash,
S: BuildHasher,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_list()
.entries(self.clone())
.finish()
}
}
#[unstable(feature = "fused", issue = "35602")]
impl<'a, T, S> FusedIterator for Intersection<'a, T, S>
where T: Eq + Hash,
@ -1068,6 +1109,18 @@ impl<'a, T, S> FusedIterator for Difference<'a, T, S>
{
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<'a, T, S> fmt::Debug for Difference<'a, T, S>
where T: fmt::Debug + Eq + Hash,
S: BuildHasher,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_list()
.entries(self.clone())
.finish()
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T, S> Clone for SymmetricDifference<'a, T, S> {
fn clone(&self) -> SymmetricDifference<'a, T, S> {
@ -1097,6 +1150,18 @@ impl<'a, T, S> FusedIterator for SymmetricDifference<'a, T, S>
{
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<'a, T, S> fmt::Debug for SymmetricDifference<'a, T, S>
where T: fmt::Debug + Eq + Hash,
S: BuildHasher,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_list()
.entries(self.clone())
.finish()
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T, S> Clone for Union<'a, T, S> {
fn clone(&self) -> Union<'a, T, S> {
@ -1111,6 +1176,18 @@ impl<'a, T, S> FusedIterator for Union<'a, T, S>
{
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<'a, T, S> fmt::Debug for Union<'a, T, S>
where T: fmt::Debug + Eq + Hash,
S: BuildHasher,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_list()
.entries(self.clone())
.finish()
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T, S> Iterator for Union<'a, T, S>
where T: Eq + Hash,

View File

@ -882,6 +882,15 @@ unsafe impl<'a, K: Sync, V: Sync> Sync for IterMut<'a, K, V> {}
// but Send is the more useful bound
unsafe impl<'a, K: Send, V: Send> Send for IterMut<'a, K, V> {}
impl<'a, K: 'a, V: 'a> IterMut<'a, K, V> {
pub fn iter(&self) -> Iter<K, V> {
Iter {
iter: self.iter.clone(),
elems_left: self.elems_left,
}
}
}
/// Iterator over the entries in a table, consuming the table.
pub struct IntoIter<K, V> {
table: RawTable<K, V>,
@ -891,6 +900,15 @@ pub struct IntoIter<K, V> {
unsafe impl<K: Sync, V: Sync> Sync for IntoIter<K, V> {}
unsafe impl<K: Send, V: Send> Send for IntoIter<K, V> {}
impl<K, V> IntoIter<K, V> {
pub fn iter(&self) -> Iter<K, V> {
Iter {
iter: self.iter.clone(),
elems_left: self.table.size,
}
}
}
/// Iterator over the entries in a table, clearing the table.
pub struct Drain<'a, K: 'a, V: 'a> {
table: Shared<RawTable<K, V>>,
@ -901,6 +919,17 @@ pub struct Drain<'a, K: 'a, V: 'a> {
unsafe impl<'a, K: Sync, V: Sync> Sync for Drain<'a, K, V> {}
unsafe impl<'a, K: Send, V: Send> Send for Drain<'a, K, V> {}
impl<'a, K, V> Drain<'a, K, V> {
pub fn iter(&self) -> Iter<K, V> {
unsafe {
Iter {
iter: self.iter.clone(),
elems_left: (**self.table).size,
}
}
}
}
impl<'a, K, V> Iterator for Iter<'a, K, V> {
type Item = (&'a K, &'a V);

View File

@ -143,6 +143,13 @@ impl Iterator for Vars {
fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for Vars {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("Vars { .. }")
}
}
#[stable(feature = "env", since = "1.0.0")]
impl Iterator for VarsOs {
type Item = (OsString, OsString);
@ -150,6 +157,13 @@ impl Iterator for VarsOs {
fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for VarsOs {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("VarsOs { .. }")
}
}
/// Fetches the environment variable `key` from the current process.
///
/// The returned result is `Ok(s)` if the environment variable is present and is
@ -364,6 +378,13 @@ impl<'a> Iterator for SplitPaths<'a> {
fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<'a> fmt::Debug for SplitPaths<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("SplitPaths { .. }")
}
}
/// Error type returned from `std::env::join_paths` when paths fail to be
/// joined.
#[derive(Debug)]
@ -640,6 +661,13 @@ impl DoubleEndedIterator for Args {
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for Args {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("Args { .. }")
}
}
#[stable(feature = "env", since = "1.0.0")]
impl Iterator for ArgsOs {
type Item = OsString;
@ -657,6 +685,14 @@ impl ExactSizeIterator for ArgsOs {
impl DoubleEndedIterator for ArgsOs {
fn next_back(&mut self) -> Option<OsString> { self.inner.next_back() }
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for ArgsOs {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("ArgsOs { .. }")
}
}
/// Constants associated with the current target
#[stable(feature = "env", since = "1.0.0")]
pub mod consts {

View File

@ -140,7 +140,7 @@ pub struct DirEntry(fs_imp::DirEntry);
/// .create(true)
/// .open("foo.txt");
/// ```
#[derive(Clone)]
#[derive(Clone, Debug)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct OpenOptions(fs_imp::OpenOptions);
@ -168,6 +168,7 @@ pub struct FileType(fs_imp::FileType);
///
/// This builder also supports platform-specific options.
#[stable(feature = "dir_builder", since = "1.6.0")]
#[derive(Debug)]
pub struct DirBuilder {
inner: fs_imp::DirBuilder,
recursive: bool,
@ -834,6 +835,21 @@ impl Metadata {
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for Metadata {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Metadata")
.field("file_type", &self.file_type())
.field("is_dir", &self.is_dir())
.field("is_file", &self.is_file())
.field("permissions", &self.permissions())
.field("modified", &self.modified())
.field("accessed", &self.accessed())
.field("created", &self.created())
.finish()
}
}
impl AsInner<fs_imp::FileAttr> for Metadata {
fn as_inner(&self) -> &fs_imp::FileAttr { &self.0 }
}

View File

@ -1444,6 +1444,16 @@ pub struct Chain<T, U> {
done_first: bool,
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<T: fmt::Debug, U: fmt::Debug> fmt::Debug for Chain<T, U> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Chain")
.field("t", &self.first)
.field("u", &self.second)
.finish()
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Read, U: Read> Read for Chain<T, U> {
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
@ -1485,6 +1495,7 @@ impl<T: BufRead, U: BufRead> BufRead for Chain<T, U> {
///
/// [`take()`]: trait.Read.html#method.take
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Debug)]
pub struct Take<T> {
inner: T,
limit: u64,
@ -1602,6 +1613,7 @@ fn read_one_byte(reader: &mut Read) -> Option<Result<u8>> {
///
/// [`bytes()`]: trait.Read.html#method.bytes
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Debug)]
pub struct Bytes<R> {
inner: R,
}
@ -1623,6 +1635,7 @@ impl<R: Read> Iterator for Bytes<R> {
/// [chars]: trait.Read.html#method.chars
#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
issue = "27802")]
#[derive(Debug)]
pub struct Chars<R> {
inner: R,
}
@ -1712,6 +1725,7 @@ impl fmt::Display for CharsError {
///
/// [split]: trait.BufRead.html#method.split
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Debug)]
pub struct Split<B> {
buf: B,
delim: u8,
@ -1743,6 +1757,7 @@ impl<B: BufRead> Iterator for Split<B> {
///
/// [lines]: trait.BufRead.html#method.lines
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Debug)]
pub struct Lines<B> {
buf: B,
}

View File

@ -282,6 +282,13 @@ impl Stdin {
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for Stdin {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("Stdin { .. }")
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl Read for Stdin {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
@ -314,6 +321,13 @@ impl<'a> BufRead for StdinLock<'a> {
fn consume(&mut self, n: usize) { self.inner.consume(n) }
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<'a> fmt::Debug for StdinLock<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("StdinLock { .. }")
}
}
/// A handle to the global standard output stream of the current process.
///
/// Each handle shares a global buffer of data to be written to the standard
@ -424,6 +438,13 @@ impl Stdout {
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for Stdout {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("Stdout { .. }")
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl Write for Stdout {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
@ -449,6 +470,13 @@ impl<'a> Write for StdoutLock<'a> {
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<'a> fmt::Debug for StdoutLock<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("StdoutLock { .. }")
}
}
/// A handle to the standard error stream of a process.
///
/// For more information, see the [`io::stderr`] method.
@ -545,6 +573,13 @@ impl Stderr {
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for Stderr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("Stderr { .. }")
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl Write for Stderr {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
@ -570,6 +605,13 @@ impl<'a> Write for StderrLock<'a> {
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<'a> fmt::Debug for StderrLock<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("StderrLock { .. }")
}
}
/// Resets the thread-local stderr handle to the specified writer
///
/// This will replace the current thread's stderr handle, returning the old

View File

@ -10,6 +10,7 @@
#![allow(missing_copy_implementations)]
use fmt;
use io::{self, Read, Write, ErrorKind, BufRead};
/// Copies the entire contents of a reader into a writer.
@ -97,6 +98,13 @@ impl BufRead for Empty {
fn consume(&mut self, _n: usize) {}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for Empty {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("Empty { .. }")
}
}
/// A reader which yields one byte over and over and over and over and over and...
///
/// This struct is generally created by calling [`repeat()`][repeat]. Please
@ -133,6 +141,13 @@ impl Read for Repeat {
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for Repeat {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("Repeat { .. }")
}
}
/// A writer which will move data into the void.
///
/// This struct is generally created by calling [`sink()`][sink]. Please
@ -165,6 +180,13 @@ impl Write for Sink {
fn flush(&mut self) -> io::Result<()> { Ok(()) }
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for Sink {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("Sink { .. }")
}
}
#[cfg(test)]
mod tests {
use io::prelude::*;

View File

@ -214,6 +214,7 @@
#![no_std]
#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
// Tell the compiler to link to either panic_abort or panic_unwind
#![needs_panic_runtime]
@ -276,6 +277,7 @@
#![feature(panic_unwind)]
#![feature(placement_in_syntax)]
#![feature(prelude_import)]
#![feature(pub_restricted)]
#![feature(rand)]
#![feature(raw)]
#![feature(repr_simd)]

View File

@ -12,6 +12,7 @@
#![stable(feature = "rust1", since = "1.0.0")]
use fmt;
use io::{self, Error, ErrorKind};
use sys_common::net as net_imp;
@ -105,6 +106,13 @@ impl Iterator for LookupHost {
fn next(&mut self) -> Option<SocketAddr> { self.0.next() }
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for LookupHost {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("LookupHost { .. }")
}
}
/// Resolve the host specified by `host` as a number of `SocketAddr` instances.
///
/// This method may perform a DNS query to resolve `host` and may also inspect

View File

@ -76,6 +76,7 @@ pub struct TcpListener(net_imp::TcpListener);
/// [`incoming`]: struct.TcpListener.html#method.incoming
/// [`TcpListener`]: struct.TcpListener.html
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Debug)]
pub struct Incoming<'a> { listener: &'a TcpListener }
impl TcpStream {

View File

@ -17,6 +17,7 @@
crates.io should be used instead for the correct \
definitions")]
#![allow(deprecated)]
#![allow(missing_debug_implementations)]
use os::raw::c_ulong;

View File

@ -33,7 +33,7 @@ use os::raw::c_long;
pub type pthread_t = usize;
#[repr(C)]
#[derive(Clone)]
#[derive(Clone, Debug)]
#[stable(feature = "raw_ext", since = "1.1.0")]
pub struct stat {
#[stable(feature = "raw_ext", since = "1.1.0")]

View File

@ -12,6 +12,8 @@
#![stable(feature = "raw_os", since = "1.1.0")]
use fmt;
#[cfg(any(target_os = "android",
target_os = "emscripten",
all(target_os = "linux", any(target_arch = "aarch64",
@ -71,6 +73,13 @@ pub enum c_void {
#[doc(hidden)] __variant2,
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for c_void {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("c_void")
}
}
#[cfg(test)]
#[allow(unused_imports)]
mod tests {

View File

@ -14,6 +14,7 @@
use any::Any;
use cell::UnsafeCell;
use fmt;
use ops::{Deref, DerefMut};
use panicking;
use ptr::{Unique, Shared};
@ -296,6 +297,15 @@ impl<R, F: FnOnce() -> R> FnOnce<()> for AssertUnwindSafe<F> {
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<T: fmt::Debug> fmt::Debug for AssertUnwindSafe<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("AssertUnwindSafe")
.field(&self.0)
.finish()
}
}
/// Invokes a closure, capturing the cause of an unwinding panic if one occurs.
///
/// This function will return `Ok` with the closure's result if the closure

View File

@ -177,6 +177,7 @@ pub fn take_hook() -> Box<Fn(&PanicInfo) + 'static + Sync + Send> {
/// panic!("Normal panic");
/// ```
#[stable(feature = "panic_hooks", since = "1.10.0")]
#[derive(Debug)]
pub struct PanicInfo<'a> {
payload: &'a (Any + Send),
location: Location<'a>,
@ -256,6 +257,7 @@ impl<'a> PanicInfo<'a> {
///
/// panic!("Normal panic");
/// ```
#[derive(Debug)]
#[stable(feature = "panic_hooks", since = "1.10.0")]
pub struct Location<'a> {
file: &'a str,

View File

@ -114,6 +114,17 @@ impl IntoInner<imp::Process> for Child {
fn into_inner(self) -> imp::Process { self.handle }
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for Child {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Child")
.field("stdin", &self.stdin)
.field("stdout", &self.stdout)
.field("stderr", &self.stderr)
.finish()
}
}
/// A handle to a child process's stdin. This struct is used in the [`stdin`]
/// field on [`Child`].
///
@ -149,6 +160,13 @@ impl FromInner<AnonPipe> for ChildStdin {
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for ChildStdin {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("ChildStdin { .. }")
}
}
/// A handle to a child process's stdout. This struct is used in the [`stdout`]
/// field on [`Child`].
///
@ -183,6 +201,13 @@ impl FromInner<AnonPipe> for ChildStdout {
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for ChildStdout {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("ChildStdout { .. }")
}
}
/// A handle to a child process's stderr. This struct is used in the [`stderr`]
/// field on [`Child`].
///
@ -217,6 +242,13 @@ impl FromInner<AnonPipe> for ChildStderr {
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for ChildStderr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("ChildStderr { .. }")
}
}
/// A process builder, providing fine-grained control
/// over how a new process should be spawned.
///
@ -622,6 +654,13 @@ impl FromInner<imp::Stdio> for Stdio {
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for Stdio {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("Stdio { .. }")
}
}
/// Describes the result of a process after it has terminated.
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
#[stable(feature = "process", since = "1.0.0")]

View File

@ -59,6 +59,7 @@
#![unstable(feature = "rand", issue = "0")]
use cell::RefCell;
use fmt;
use io;
use mem;
use rc::Rc;
@ -143,6 +144,12 @@ pub struct ThreadRng {
rng: Rc<RefCell<ThreadRngInner>>,
}
impl fmt::Debug for ThreadRng {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("ThreadRng { .. }")
}
}
/// Retrieve the lazily-initialized thread-local random number
/// generator, seeded by the system. Intended to be used in method
/// chaining style, e.g. `thread_rng().gen::<isize>()`.

View File

@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use fmt;
use sync::{Mutex, Condvar};
/// A barrier enables multiple threads to synchronize the beginning
@ -54,6 +55,13 @@ struct BarrierState {
#[stable(feature = "rust1", since = "1.0.0")]
pub struct BarrierWaitResult(bool);
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for Barrier {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("Barrier { .. }")
}
}
impl Barrier {
/// Creates a new barrier that can block a given number of threads.
///
@ -102,6 +110,15 @@ impl Barrier {
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for BarrierWaitResult {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("BarrierWaitResult")
.field("is_leader", &self.is_leader())
.finish()
}
}
impl BarrierWaitResult {
/// Returns whether this thread from `wait` is the "leader thread".
///

View File

@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use fmt;
use sync::atomic::{AtomicUsize, Ordering};
use sync::{mutex, MutexGuard, PoisonError};
use sys_common::condvar as sys;
@ -239,6 +240,13 @@ impl Condvar {
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for Condvar {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("Condvar { .. }")
}
}
#[stable(feature = "condvar_default", since = "1.9.0")]
impl Default for Condvar {
/// Creates a `Condvar` which is ready to be waited on and notified.

View File

@ -306,6 +306,7 @@ impl<T> !Sync for Receiver<T> { }
/// whenever `next` is called, waiting for a new message, and `None` will be
/// returned when the corresponding channel has hung up.
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Debug)]
pub struct Iter<'a, T: 'a> {
rx: &'a Receiver<T>
}
@ -317,6 +318,7 @@ pub struct Iter<'a, T: 'a> {
/// This Iterator will never block the caller in order to wait for data to
/// become available. Instead, it will return `None`.
#[stable(feature = "receiver_try_iter", since = "1.15.0")]
#[derive(Debug)]
pub struct TryIter<'a, T: 'a> {
rx: &'a Receiver<T>
}
@ -325,6 +327,7 @@ pub struct TryIter<'a, T: 'a> {
/// whenever `next` is called, waiting for a new message, and `None` will be
/// returned when the corresponding channel has hung up.
#[stable(feature = "receiver_into_iter", since = "1.1.0")]
#[derive(Debug)]
pub struct IntoIter<T> {
rx: Receiver<T>
}

View File

@ -351,6 +351,15 @@ impl<'a, T: ?Sized> Drop for MutexGuard<'a, T> {
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<'a, T: ?Sized + fmt::Debug> fmt::Debug for MutexGuard<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("MutexGuard")
.field("lock", &self.__lock)
.finish()
}
}
pub fn guard_lock<'a, T: ?Sized>(guard: &MutexGuard<'a, T>) -> &'a sys::Mutex {
&guard.__lock.inner
}

View File

@ -64,6 +64,7 @@
// You'll find a few more details in the implementation, but that's the gist of
// it!
use fmt;
use marker;
use ptr;
use sync::atomic::{AtomicUsize, AtomicBool, Ordering};
@ -103,6 +104,7 @@ unsafe impl Send for Once {}
/// State yielded to the `call_once_force` method which can be used to query
/// whether the `Once` was previously poisoned or not.
#[unstable(feature = "once_poison", issue = "33577")]
#[derive(Debug)]
pub struct OnceState {
poisoned: bool,
}
@ -328,6 +330,13 @@ impl Once {
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for Once {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("Once { .. }")
}
}
impl Drop for Finish {
fn drop(&mut self) {
// Swap out our state with however we finished. We should only ever see

View File

@ -362,6 +362,24 @@ impl<'rwlock, T: ?Sized> RwLockWriteGuard<'rwlock, T> {
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<'a, T: fmt::Debug> fmt::Debug for RwLockReadGuard<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("RwLockReadGuard")
.field("lock", &self.__lock)
.finish()
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<'a, T: fmt::Debug> fmt::Debug for RwLockWriteGuard<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("RwLockWriteGuard")
.field("lock", &self.__lock)
.finish()
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'rwlock, T: ?Sized> Deref for RwLockReadGuard<'rwlock, T> {
type Target = T;

View File

@ -12,6 +12,7 @@
#![unstable(feature = "thread_local_internals", issue = "0")]
use cell::{Cell, UnsafeCell};
use fmt;
use intrinsics;
use ptr;
@ -24,6 +25,12 @@ pub struct Key<T> {
dtor_running: Cell<bool>,
}
impl<T> fmt::Debug for Key<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("Key { .. }")
}
}
unsafe impl<T> ::marker::Sync for Key<T> { }
impl<T> Key<T> {

View File

@ -18,6 +18,7 @@ use sys::cvt;
use sys_common::AsInner;
use sys_common::io::read_to_end_uninitialized;
#[derive(Debug)]
pub struct FileDesc {
fd: c_int,
}

View File

@ -66,7 +66,7 @@ pub struct DirEntry {
name: Box<[u8]>
}
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct OpenOptions {
// generic
read: bool,
@ -86,6 +86,7 @@ pub struct FilePermissions { mode: mode_t }
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct FileType { mode: mode_t }
#[derive(Debug)]
pub struct DirBuilder { mode: mode_t }
impl FileAttr {

View File

@ -58,7 +58,7 @@ pub struct DirEntry {
data: c::WIN32_FIND_DATAW,
}
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct OpenOptions {
// generic
read: bool,
@ -79,6 +79,7 @@ pub struct OpenOptions {
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct FilePermissions { attrs: c::DWORD }
#[derive(Debug)]
pub struct DirBuilder;
impl fmt::Debug for ReadDir {

View File

@ -13,6 +13,7 @@
#![unstable(feature = "thread_local_internals", issue = "0")]
use cell::UnsafeCell;
use fmt;
use mem;
/// A thread local storage key which owns its contents.
@ -98,6 +99,13 @@ pub struct LocalKey<T: 'static> {
init: fn() -> T,
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<T: 'static> fmt::Debug for LocalKey<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("LocalKey { .. }")
}
}
/// Declare a new thread local storage key of type `std::thread::LocalKey`.
///
/// # Syntax
@ -184,7 +192,7 @@ macro_rules! __thread_local_inner {
#[unstable(feature = "thread_local_state",
reason = "state querying was recently added",
issue = "27716")]
#[derive(Eq, PartialEq, Copy, Clone)]
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub enum LocalKeyState {
/// All keys are in this state whenever a thread starts. Keys will
/// transition to the `Valid` state once the first call to `with` happens
@ -313,6 +321,7 @@ impl<T: 'static> LocalKey<T> {
#[doc(hidden)]
pub mod os {
use cell::{Cell, UnsafeCell};
use fmt;
use marker;
use ptr;
use sys_common::thread_local::StaticKey as OsStaticKey;
@ -323,6 +332,13 @@ pub mod os {
marker: marker::PhantomData<Cell<T>>,
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<T> fmt::Debug for Key<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("Key { .. }")
}
}
unsafe impl<T> ::marker::Sync for Key<T> { }
struct Value<T: 'static> {

View File

@ -203,6 +203,7 @@ pub use self::local::{LocalKey, LocalKeyState};
/// Thread configuration. Provides detailed control over the properties
/// and behavior of new threads.
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Debug)]
pub struct Builder {
// A name for the thread-to-be, for identification in panic messages
name: Option<String>,
@ -573,6 +574,13 @@ impl ThreadId {
}
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl fmt::Debug for ThreadId {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("ThreadId { .. }")
}
}
////////////////////////////////////////////////////////////////////////////////
// Thread
////////////////////////////////////////////////////////////////////////////////
@ -788,6 +796,13 @@ impl<T> IntoInner<imp::Thread> for JoinHandle<T> {
fn into_inner(self) -> imp::Thread { self.0.native.unwrap() }
}
#[stable(feature = "std_debug", since = "1.15.0")]
impl<T> fmt::Debug for JoinHandle<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("JoinHandle { .. }")
}
}
fn _assert_sync_and_send() {
fn _assert_both<T: Send + Sync>() {}
_assert_both::<JoinHandle<()>>();