std: Rename Show/String to Debug/Display

This commit is an implementation of [RFC 565][rfc] which is a stabilization of
the `std::fmt` module and the implementations of various formatting traits.
Specifically, the following changes were performed:

[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0565-show-string-guidelines.md

* The `Show` trait is now deprecated, it was renamed to `Debug`
* The `String` trait is now deprecated, it was renamed to `Display`
* Many `Debug` and `Display` implementations were audited in accordance with the
  RFC and audited implementations now have the `#[stable]` attribute
  * Integers and floats no longer print a suffix
  * Smart pointers no longer print details that they are a smart pointer
  * Paths with `Debug` are now quoted and escape characters
* The `unwrap` methods on `Result` now require `Display` instead of `Debug`
* The `Error` trait no longer has a `detail` method and now requires that
  `Display` must be implemented. With the loss of `String`, this has moved into
  libcore.
* `impl<E: Error> FromError<E> for Box<Error>` now exists
* `derive(Show)` has been renamed to `derive(Debug)`. This is not currently
  warned about due to warnings being emitted on stage1+

While backwards compatibility is attempted to be maintained with a blanket
implementation of `Display` for the old `String` trait (and the same for
`Show`/`Debug`) this is still a breaking change due to primitives no longer
implementing `String` as well as modifications such as `unwrap` and the `Error`
trait. Most code is fairly straightforward to update with a rename or tweaks of
method calls.

[breaking-change]
Closes #21436
This commit is contained in:
Alex Crichton 2015-01-20 15:45:07 -08:00
parent 29bd9a06ef
commit 3cb9fa26ef
136 changed files with 763 additions and 706 deletions

View file

@ -57,7 +57,7 @@ struct Matrix<'a>(Vec<Vec<&'a Pat>>);
/// ++++++++++++++++++++++++++
/// + _ + [_, _, ..tail] +
/// ++++++++++++++++++++++++++
impl<'a> fmt::Show for Matrix<'a> {
impl<'a> fmt::Debug for Matrix<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "\n"));

View file

@ -32,7 +32,7 @@
#![allow(dead_code)] // still WIP
use std::fmt::{Formatter, Error, Show};
use std::fmt::{Formatter, Error, Debug};
use std::uint;
use std::collections::BitvSet;
@ -53,7 +53,7 @@ pub struct Edge<E> {
pub data: E,
}
impl<E: Show> Show for Edge<E> {
impl<E: Debug> Debug for Edge<E> {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
write!(f, "Edge {{ next_edge: [{:?}, {:?}], source: {:?}, target: {:?}, data: {:?} }}",
self.next_edge[0], self.next_edge[1], self.source,
@ -353,7 +353,7 @@ impl<E> Edge<E> {
#[cfg(test)]
mod test {
use middle::graph::*;
use std::fmt::Show;
use std::fmt::Debug;
type TestNode = Node<&'static str>;
type TestEdge = Edge<&'static str>;
@ -408,7 +408,7 @@ mod test {
});
}
fn test_adjacent_edges<N:PartialEq+Show,E:PartialEq+Show>(graph: &Graph<N,E>,
fn test_adjacent_edges<N:PartialEq+Debug,E:PartialEq+Debug>(graph: &Graph<N,E>,
start_index: NodeIndex,
start_data: N,
expected_incoming: &[(E,N)],

View file

@ -17,7 +17,7 @@ use middle::ty::{self, Ty};
use middle::infer::{uok, ures};
use middle::infer::InferCtxt;
use std::cell::RefCell;
use std::fmt::Show;
use std::fmt::Debug;
use syntax::ast;
use util::ppaux::Repr;
use util::snapshot_vec as sv;
@ -32,7 +32,7 @@ use util::snapshot_vec as sv;
/// (possibly not yet known) sort of integer.
///
/// Implementations of this trait are at the end of this file.
pub trait UnifyKey<'tcx, V> : Clone + Show + PartialEq + Repr<'tcx> {
pub trait UnifyKey<'tcx, V> : Clone + Debug + PartialEq + Repr<'tcx> {
fn index(&self) -> uint;
fn from_index(u: uint) -> Self;

View file

@ -198,13 +198,13 @@ pub fn check_crate(tcx: &ty::ctxt) {
tcx.sess.abort_if_errors();
}
impl fmt::Show for LiveNode {
impl fmt::Debug for LiveNode {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ln({})", self.get())
}
}
impl fmt::Show for Variable {
impl fmt::Debug for Variable {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "v({})", self.get())
}

View file

@ -602,7 +602,7 @@ fn early_bound_lifetime_names(generics: &ast::Generics) -> Vec<ast::Name> {
}
}
impl<'a> fmt::Show for ScopeChain<'a> {
impl<'a> fmt::Debug for ScopeChain<'a> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match *self {
EarlyScope(space, defs, _) => write!(fmt, "EarlyScope({:?}, {:?})", space, defs),

View file

@ -238,7 +238,7 @@ pub struct SeparateVecsPerParamSpace<T> {
pub fns: Vec<T>,
}
impl<T:fmt::Show> fmt::Show for VecPerParamSpace<T> {
impl<T: fmt::Debug> fmt::Debug for VecPerParamSpace<T> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
try!(write!(fmt, "VecPerParamSpace {{"));
for space in ParamSpace::all().iter() {

View file

@ -200,7 +200,7 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
ty::Predicate::Equate(ref predicate) => {
let predicate = infcx.resolve_type_vars_if_possible(predicate);
let err = infcx.equality_predicate(obligation.cause.span,
&predicate).unwrap_err();
&predicate).err().unwrap();
infcx.tcx.sess.span_err(
obligation.cause.span,
format!(
@ -212,7 +212,7 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
ty::Predicate::RegionOutlives(ref predicate) => {
let predicate = infcx.resolve_type_vars_if_possible(predicate);
let err = infcx.region_outlives_predicate(obligation.cause.span,
&predicate).unwrap_err();
&predicate).err().unwrap();
infcx.tcx.sess.span_err(
obligation.cause.span,
format!(

View file

@ -236,13 +236,13 @@ pub fn fresh_substs_for_impl<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
infcx.fresh_substs_for_generics(span, &impl_generics)
}
impl<'tcx, N> fmt::Show for VtableImplData<'tcx, N> {
impl<'tcx, N> fmt::Debug for VtableImplData<'tcx, N> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "VtableImpl({:?})", self.impl_def_id)
}
}
impl<'tcx> fmt::Show for super::VtableObjectData<'tcx> {
impl<'tcx> fmt::Debug for super::VtableObjectData<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "VtableObject(...)")
}
@ -449,7 +449,7 @@ impl<'tcx> Repr<'tcx> for super::FulfillmentErrorCode<'tcx> {
}
}
impl<'tcx> fmt::Show for super::FulfillmentErrorCode<'tcx> {
impl<'tcx> fmt::Debug for super::FulfillmentErrorCode<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
super::CodeSelectionError(ref e) => write!(f, "{:?}", e),
@ -465,7 +465,7 @@ impl<'tcx> Repr<'tcx> for super::MismatchedProjectionTypes<'tcx> {
}
}
impl<'tcx> fmt::Show for super::MismatchedProjectionTypes<'tcx> {
impl<'tcx> fmt::Debug for super::MismatchedProjectionTypes<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "MismatchedProjectionTypes(..)")
}

View file

@ -934,7 +934,7 @@ pub struct TyS<'tcx> {
region_depth: u32,
}
impl fmt::Show for TypeFlags {
impl fmt::Debug for TypeFlags {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.bits)
}
@ -1703,37 +1703,37 @@ impl cmp::PartialEq for InferRegion {
}
}
impl fmt::Show for TyVid {
impl fmt::Debug for TyVid {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result{
write!(f, "_#{}t", self.index)
}
}
impl fmt::Show for IntVid {
impl fmt::Debug for IntVid {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "_#{}i", self.index)
}
}
impl fmt::Show for FloatVid {
impl fmt::Debug for FloatVid {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "_#{}f", self.index)
}
}
impl fmt::Show for RegionVid {
impl fmt::Debug for RegionVid {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "'_#{}r", self.index)
}
}
impl<'tcx> fmt::Show for FnSig<'tcx> {
impl<'tcx> fmt::Debug for FnSig<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "({:?}; variadic: {})->{:?}", self.inputs, self.variadic, self.output)
}
}
impl fmt::Show for InferTy {
impl fmt::Debug for InferTy {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
TyVar(ref v) => v.fmt(f),
@ -1745,7 +1745,7 @@ impl fmt::Show for InferTy {
}
}
impl fmt::Show for IntVarValue {
impl fmt::Debug for IntVarValue {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
IntType(ref v) => v.fmt(f),
@ -3319,7 +3319,7 @@ impl ops::Sub for TypeContents {
}
}
impl fmt::Show for TypeContents {
impl fmt::Debug for TypeContents {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "TypeContents({:b})", self.bits)
}

View file

@ -249,7 +249,7 @@ pub enum EntryFnType {
EntryNone,
}
#[derive(Copy, PartialEq, PartialOrd, Clone, Ord, Eq, Hash)]
#[derive(Copy, PartialEq, PartialOrd, Clone, Ord, Eq, Hash, Show)]
pub enum CrateType {
CrateTypeExecutable,
CrateTypeDylib,
@ -1159,7 +1159,7 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateTy
return Ok(crate_types);
}
impl fmt::Show for CrateType {
impl fmt::Display for CrateType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
CrateTypeExecutable => "bin".fmt(f),

View file

@ -12,7 +12,7 @@
use std::cell::{RefCell, Cell};
use std::collections::HashMap;
use std::fmt::Show;
use std::fmt::Debug;
use std::hash::{Hash, Hasher};
use std::iter::repeat;
use std::time::Duration;
@ -58,7 +58,7 @@ pub fn time<T, U, F>(do_it: bool, what: &str, u: U, f: F) -> T where
}
pub fn indent<R, F>(op: F) -> R where
R: Show,
R: Debug,
F: FnOnce() -> R,
{
// Use in conjunction with the log post-processor like `src/etc/indenter`