rollup merge of #20722: alexcrichton/audit-show
Conflicts: src/libcollections/vec.rs src/libcore/fmt/mod.rs src/librustdoc/html/format.rs
This commit is contained in:
commit
a204dc56c9
@ -584,6 +584,13 @@ impl<T: fmt::Show> fmt::Show for Arc<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<T: fmt::String> fmt::String for Arc<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::String::fmt(&**self, f)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<T: Default + Sync + Send> Default for Arc<T> {
|
||||
#[stable]
|
||||
|
@ -157,6 +157,7 @@ impl<T: ?Sized + fmt::Show> fmt::Show for Box<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<T: ?Sized + fmt::String> fmt::String for Box<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::String::fmt(&**self, f)
|
||||
|
@ -622,6 +622,13 @@ impl<T: fmt::Show> fmt::Show for Rc<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<T: fmt::String> fmt::String for Rc<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::String::fmt(&**self, f)
|
||||
}
|
||||
}
|
||||
|
||||
/// A weak version of `Rc<T>`.
|
||||
///
|
||||
/// Weak references do not count when determining if the inner value should be dropped.
|
||||
|
@ -681,6 +681,7 @@ impl fmt::Show for FromUtf8Error {
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl fmt::String for FromUtf8Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::String::fmt(&self.error, f)
|
||||
@ -693,6 +694,7 @@ impl fmt::Show for FromUtf16Error {
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl fmt::String for FromUtf16Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::String::fmt("invalid utf-16: lone surrogate found", f)
|
||||
@ -805,7 +807,7 @@ impl Default for String {
|
||||
}
|
||||
}
|
||||
|
||||
#[experimental = "waiting on fmt stabilization"]
|
||||
#[stable]
|
||||
impl fmt::String for String {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::String::fmt(&**self, f)
|
||||
@ -1274,18 +1276,17 @@ mod tests {
|
||||
assert_eq!(2u8.to_string(), "2");
|
||||
assert_eq!(true.to_string(), "true");
|
||||
assert_eq!(false.to_string(), "false");
|
||||
assert_eq!(().to_string(), "()");
|
||||
assert_eq!(("hi".to_string()).to_string(), "hi");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vectors() {
|
||||
let x: Vec<int> = vec![];
|
||||
assert_eq!(x.to_string(), "[]");
|
||||
assert_eq!((vec![1i]).to_string(), "[1]");
|
||||
assert_eq!((vec![1i, 2, 3]).to_string(), "[1, 2, 3]");
|
||||
assert!((vec![vec![], vec![1i], vec![1i, 1]]).to_string() ==
|
||||
"[[], [1], [1, 1]]");
|
||||
assert_eq!(format!("{:?}", x), "[]");
|
||||
assert_eq!(format!("{:?}", vec![1i]), "[1i]");
|
||||
assert_eq!(format!("{:?}", vec![1i, 2, 3]), "[1i, 2i, 3i]");
|
||||
assert!(format!("{:?}", vec![vec![], vec![1i], vec![1i, 1]]) ==
|
||||
"[[], [1i], [1i, 1i]]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1462,13 +1462,6 @@ impl<T: fmt::Show> fmt::Show for Vec<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[experimental = "waiting on Show stability"]
|
||||
impl<T: fmt::String> fmt::String for Vec<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::String::fmt(self.as_slice(), f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Writer for Vec<u8> {
|
||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
self.push_all(s.as_bytes());
|
||||
|
@ -238,6 +238,7 @@ impl<'a, T, B: ?Sized> PartialOrd for Cow<'a, T, B> where B: PartialOrd + ToOwne
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<'a, T, B: ?Sized> fmt::String for Cow<'a, T, B> where
|
||||
B: fmt::String + ToOwned<T>,
|
||||
T: fmt::String,
|
||||
|
@ -219,6 +219,7 @@ impl<'a> Show for Arguments<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<'a> String for Arguments<'a> {
|
||||
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
||||
write(fmt.buf, *self)
|
||||
@ -627,6 +628,7 @@ impl Show for bool {
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl String for bool {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
String::fmt(if *self { "true" } else { "false" }, f)
|
||||
@ -643,6 +645,7 @@ impl Show for str {
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl String for str {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
f.pad(self)
|
||||
@ -660,6 +663,7 @@ impl Show for char {
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl String for char {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
let mut utf8 = [0u8; 4];
|
||||
@ -705,6 +709,7 @@ macro_rules! floating { ($ty:ident) => {
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl String for $ty {
|
||||
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
||||
use num::Float;
|
||||
@ -776,15 +781,9 @@ floating! { f64 }
|
||||
impl<T> Show for *const T {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result { Pointer::fmt(self, f) }
|
||||
}
|
||||
impl<T> String for *const T {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result { Pointer::fmt(self, f) }
|
||||
}
|
||||
impl<T> Show for *mut T {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result { Pointer::fmt(self, f) }
|
||||
}
|
||||
impl<T> String for *mut T {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result { Pointer::fmt(self, f) }
|
||||
}
|
||||
|
||||
macro_rules! peel {
|
||||
($name:ident, $($other:ident,)*) => (tuple! { $($other,)* })
|
||||
@ -843,39 +842,12 @@ impl<T: Show> Show for [T] {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: String> String for [T] {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
if f.flags & (1 << (rt::FlagAlternate as uint)) == 0 {
|
||||
try!(write!(f, "["));
|
||||
}
|
||||
let mut is_first = true;
|
||||
for x in self.iter() {
|
||||
if is_first {
|
||||
is_first = false;
|
||||
} else {
|
||||
try!(write!(f, ", "));
|
||||
}
|
||||
try!(write!(f, "{}", *x))
|
||||
}
|
||||
if f.flags & (1 << (rt::FlagAlternate as uint)) == 0 {
|
||||
try!(write!(f, "]"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Show for () {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
f.pad("()")
|
||||
}
|
||||
}
|
||||
|
||||
impl String for () {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
f.pad("()")
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Copy + Show> Show for Cell<T> {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
write!(f, "Cell {{ value: {:?} }}", self.get())
|
||||
@ -904,6 +876,7 @@ impl<'b, T: Show> Show for RefMut<'b, T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl String for Utf8Error {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
match *self {
|
||||
|
@ -145,17 +145,18 @@
|
||||
|
||||
use self::Option::*;
|
||||
|
||||
use clone::Clone;
|
||||
use cmp::{Eq, Ord};
|
||||
use default::Default;
|
||||
use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator};
|
||||
use fmt;
|
||||
use iter::{ExactSizeIterator};
|
||||
use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator};
|
||||
use mem;
|
||||
use result::Result;
|
||||
use result::Result::{Ok, Err};
|
||||
use slice;
|
||||
use slice::AsSlice;
|
||||
use clone::Clone;
|
||||
use ops::{Deref, FnOnce};
|
||||
use result::Result::{Ok, Err};
|
||||
use result::Result;
|
||||
use slice::AsSlice;
|
||||
use slice;
|
||||
|
||||
// Note that this is not a lang item per se, but it has a hidden dependency on
|
||||
// `Iterator`, which is one. The compiler assumes that the `next` method of
|
||||
@ -762,7 +763,6 @@ impl<T> AsSlice<T> for Option<T> {
|
||||
|
||||
#[stable]
|
||||
impl<T> Default for Option<T> {
|
||||
#[stable]
|
||||
#[inline]
|
||||
#[stable]
|
||||
fn default() -> Option<T> { None }
|
||||
|
@ -51,6 +51,8 @@ pub struct ConciseStability<'a>(pub &'a Option<clean::Stability>);
|
||||
pub struct WhereClause<'a>(pub &'a clean::Generics);
|
||||
/// Wrapper struct for emitting type parameter bounds.
|
||||
pub struct TyParamBounds<'a>(pub &'a [clean::TyParamBound]);
|
||||
/// Wrapper struct for emitting a comma-separated list of items
|
||||
pub struct CommaSep<'a, T: 'a>(pub &'a [T]);
|
||||
|
||||
impl VisSpace {
|
||||
pub fn get(&self) -> Option<ast::Visibility> {
|
||||
@ -64,6 +66,16 @@ impl UnsafetySpace {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: fmt::String> fmt::String for CommaSep<'a, T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
for (i, item) in self.0.iter().enumerate() {
|
||||
if i != 0 { try!(write!(f, ", ")); }
|
||||
try!(write!(f, "{}", item));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::String for TyParamBounds<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let &TyParamBounds(bounds) = self;
|
||||
@ -450,7 +462,8 @@ impl fmt::String for clean::Type {
|
||||
lifetimes = if decl.lifetimes.len() == 0 {
|
||||
"".to_string()
|
||||
} else {
|
||||
format!("for <{:#}>", decl.lifetimes)
|
||||
format!("for <{}>",
|
||||
CommaSep(decl.lifetimes.as_slice()))
|
||||
},
|
||||
args = decl.decl.inputs,
|
||||
arrow = decl.decl.output,
|
||||
@ -482,7 +495,8 @@ impl fmt::String for clean::Type {
|
||||
lifetimes = if decl.lifetimes.len() == 0 {
|
||||
"".to_string()
|
||||
} else {
|
||||
format!("for <{:#}>", decl.lifetimes)
|
||||
format!("for <{}>",
|
||||
CommaSep(decl.lifetimes.as_slice()))
|
||||
},
|
||||
args = decl.decl.inputs,
|
||||
bounds = if decl.bounds.len() == 0 {
|
||||
@ -512,7 +526,8 @@ impl fmt::String for clean::Type {
|
||||
primitive_link(f, clean::PrimitiveTuple,
|
||||
match typs.as_slice() {
|
||||
[ref one] => format!("({},)", one),
|
||||
many => format!("({:#})", many)
|
||||
many => format!("({})",
|
||||
CommaSep(many.as_slice()))
|
||||
}.as_slice())
|
||||
}
|
||||
clean::Vector(ref t) => {
|
||||
|
@ -60,7 +60,7 @@ pub fn is_sep(c: char) -> bool {
|
||||
|
||||
impl fmt::Show for Path {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Path {{ {} }}", self.display())
|
||||
fmt::Show::fmt(&self.display(), f)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ pub struct Path {
|
||||
|
||||
impl fmt::Show for Path {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Path {{ {} }}", self.display())
|
||||
fmt::Show::fmt(&self.display(), f)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ struct defer<'a> {
|
||||
impl<'a> Drop for defer<'a> {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
println!("{}", self.x);
|
||||
println!("{:?}", self.x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,5 +15,5 @@ fn read_lines_borrowed<'a>() -> Vec<&'a str> {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("{}", read_lines_borrowed());
|
||||
println!("{:?}", read_lines_borrowed());
|
||||
}
|
||||
|
@ -23,5 +23,5 @@ fn main() {
|
||||
|
||||
assert_eq!((*arc_v)[2], 3);
|
||||
|
||||
println!("{}", *arc_v);
|
||||
println!("{:?}", *arc_v);
|
||||
}
|
||||
|
@ -21,5 +21,5 @@ fn main() {
|
||||
|
||||
assert_eq!((*arc_v)[2], 3); //~ ERROR use of moved value: `arc_v`
|
||||
|
||||
println!("{}", *arc_v); //~ ERROR use of moved value: `arc_v`
|
||||
println!("{:?}", *arc_v); //~ ERROR use of moved value: `arc_v`
|
||||
}
|
||||
|
@ -34,6 +34,6 @@ fn main() {
|
||||
let foo = Foo { bar: [1u8, 2, 3, 4, 5], baz: 10i32 };
|
||||
unsafe {
|
||||
let oof: Oof<[u8; 5], i32> = mem::transmute(foo);
|
||||
println!("{} {}", &oof.rab[], oof.zab);
|
||||
println!("{:?} {:?}", &oof.rab[], oof.zab);
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ pub fn main() {
|
||||
let c : &[int] = &[2,2,2,2,3];
|
||||
let cc : &[int] = &[2,2,2,2,2,2];
|
||||
|
||||
println!("{}", a);
|
||||
println!("{:?}", a);
|
||||
|
||||
assert!(a < b);
|
||||
assert!(a <= b);
|
||||
@ -30,7 +30,7 @@ pub fn main() {
|
||||
assert!(b >= a);
|
||||
assert!(b > a);
|
||||
|
||||
println!("{}", b);
|
||||
println!("{:?}", b);
|
||||
|
||||
assert!(b < c);
|
||||
assert!(b <= c);
|
||||
@ -44,7 +44,7 @@ pub fn main() {
|
||||
assert!(c >= a);
|
||||
assert!(c > a);
|
||||
|
||||
println!("{}", c);
|
||||
println!("{:?}", c);
|
||||
|
||||
assert!(a < cc);
|
||||
assert!(a <= cc);
|
||||
@ -52,5 +52,5 @@ pub fn main() {
|
||||
assert!(cc >= a);
|
||||
assert!(cc > a);
|
||||
|
||||
println!("{}", cc);
|
||||
println!("{:?}", cc);
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ fn test_write() {
|
||||
// can do with them just yet (to test the output)
|
||||
fn test_print() {
|
||||
print!("hi");
|
||||
print!("{}", vec!(0u8));
|
||||
print!("{:?}", vec!(0u8));
|
||||
println!("hello");
|
||||
println!("this is a {}", "test");
|
||||
println!("{foo}", foo="bar");
|
||||
|
@ -15,7 +15,7 @@ fn main() {
|
||||
let ss: &&[int] = &s;
|
||||
let sss: &&&[int] = &ss;
|
||||
|
||||
println!("{}", &s[0..3]);
|
||||
println!("{}", &ss[3..]);
|
||||
println!("{}", &sss[2..4]);
|
||||
println!("{:?}", &s[0..3]);
|
||||
println!("{:?}", &ss[3..]);
|
||||
println!("{:?}", &sss[2..4]);
|
||||
}
|
||||
|
@ -25,6 +25,6 @@ static V: &'static [X] = &[X { vec: &[1, 2, 3] }];
|
||||
|
||||
pub fn main() {
|
||||
for &v in V.iter() {
|
||||
println!("{}", v.vec);
|
||||
println!("{:?}", v.vec);
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ pub fn main() {
|
||||
|
||||
print!("[");
|
||||
for xi in x.iter() {
|
||||
print!("{}, ", &xi[]);
|
||||
print!("{:?}, ", &xi[]);
|
||||
}
|
||||
println!("]");
|
||||
println!("{}", &y[]);
|
||||
println!("{:?}", &y[]);
|
||||
}
|
||||
|
@ -9,11 +9,11 @@
|
||||
// except according to those terms.
|
||||
|
||||
pub fn main() {
|
||||
assert_eq!((vec!(0i, 1)).to_string(), "[0, 1]".to_string());
|
||||
assert_eq!(format!("{:?}", vec!(0i, 1)), "[0i, 1i]".to_string());
|
||||
|
||||
let foo = vec!(3i, 4);
|
||||
let bar: &[int] = &[4, 5];
|
||||
|
||||
assert_eq!(foo.to_string(), "[3, 4]".to_string());
|
||||
assert_eq!(bar.to_string(), "[4, 5]".to_string());
|
||||
assert_eq!(format!("{:?}", foo), "[3i, 4i]");
|
||||
assert_eq!(format!("{:?}", bar), "[4i, 5i]");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user