diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-01-06 15:22:24 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-01-06 15:22:24 -0800 |
| commit | 5c3ddcb15dc8b40fa780a38fd7494b9b5b991d09 (patch) | |
| tree | 9ad6d0c242e45a785dae4b22f1e4ddd9d4f9c55a /src/libstd | |
| parent | 5f27b500800fc2720c5caa4a0cd5dcc46c0b911f (diff) | |
| parent | 44440e5c18a1dbcc9685866ffffe00c508929079 (diff) | |
| download | rust-5c3ddcb15dc8b40fa780a38fd7494b9b5b991d09.tar.gz rust-5c3ddcb15dc8b40fa780a38fd7494b9b5b991d09.zip | |
rollup merge of #20481: seanmonstar/fmt-show-string
Conflicts: src/compiletest/runtest.rs src/libcore/fmt/mod.rs src/libfmt_macros/lib.rs src/libregex/parse.rs src/librustc/middle/cfg/construct.rs src/librustc/middle/dataflow.rs src/librustc/middle/infer/higher_ranked/mod.rs src/librustc/middle/ty.rs src/librustc_back/archive.rs src/librustc_borrowck/borrowck/fragments.rs src/librustc_borrowck/borrowck/gather_loans/mod.rs src/librustc_resolve/lib.rs src/librustc_trans/back/link.rs src/librustc_trans/save/mod.rs src/librustc_trans/trans/base.rs src/librustc_trans/trans/callee.rs src/librustc_trans/trans/common.rs src/librustc_trans/trans/consts.rs src/librustc_trans/trans/controlflow.rs src/librustc_trans/trans/debuginfo.rs src/librustc_trans/trans/expr.rs src/librustc_trans/trans/monomorphize.rs src/librustc_typeck/astconv.rs src/librustc_typeck/check/method/mod.rs src/librustc_typeck/check/mod.rs src/librustc_typeck/check/regionck.rs src/librustc_typeck/collect.rs src/libsyntax/ext/format.rs src/libsyntax/ext/source_util.rs src/libsyntax/ext/tt/transcribe.rs src/libsyntax/parse/mod.rs src/libsyntax/parse/token.rs src/test/run-pass/issue-8898.rs
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/collections/hash/map.rs | 12 | ||||
| -rw-r--r-- | src/libstd/collections/hash/set.rs | 12 | ||||
| -rw-r--r-- | src/libstd/fmt.rs | 36 | ||||
| -rw-r--r-- | src/libstd/io/fs.rs | 68 | ||||
| -rw-r--r-- | src/libstd/io/mod.rs | 14 | ||||
| -rw-r--r-- | src/libstd/io/net/addrinfo.rs | 10 | ||||
| -rw-r--r-- | src/libstd/io/net/ip.rs | 8 | ||||
| -rw-r--r-- | src/libstd/io/process.rs | 15 | ||||
| -rw-r--r-- | src/libstd/io/stdio.rs | 2 | ||||
| -rw-r--r-- | src/libstd/macros.rs | 2 | ||||
| -rw-r--r-- | src/libstd/os.rs | 4 | ||||
| -rw-r--r-- | src/libstd/path/mod.rs | 31 | ||||
| -rw-r--r-- | src/libstd/path/posix.rs | 101 | ||||
| -rw-r--r-- | src/libstd/path/windows.rs | 119 | ||||
| -rw-r--r-- | src/libstd/rand/mod.rs | 4 | ||||
| -rw-r--r-- | src/libstd/rand/reader.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/unix/backtrace.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/unix/fs.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/unix/process.rs | 14 | ||||
| -rw-r--r-- | src/libstd/time/duration.rs | 4 |
20 files changed, 240 insertions, 222 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index a3fc38c34e8..681f2454fa0 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -292,7 +292,7 @@ fn test_resize_policy() { /// /// // Use derived implementation to print the status of the vikings. /// for (viking, health) in vikings.iter() { -/// println!("{} has {} hp", viking, health); +/// println!("{:?} has {} hp", viking, health); /// } /// ``` #[derive(Clone)] @@ -1207,11 +1207,11 @@ impl<K: Eq + Hash<S>, V: Eq, S, H: Hasher<S>> Eq for HashMap<K, V, H> {} #[stable] impl<K: Eq + Hash<S> + Show, V: Show, S, H: Hasher<S>> Show for HashMap<K, V, H> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - try!(write!(f, "{{")); + try!(write!(f, "HashMap {{")); for (i, (k, v)) in self.iter().enumerate() { if i != 0 { try!(write!(f, ", ")); } - try!(write!(f, "{}: {}", *k, *v)); + try!(write!(f, "{:?}: {:?}", *k, *v)); } write!(f, "}}") @@ -1891,10 +1891,10 @@ mod test_map { map.insert(1i, 2i); map.insert(3i, 4i); - let map_str = format!("{}", map); + let map_str = format!("{:?}", map); - assert!(map_str == "{1: 2, 3: 4}" || map_str == "{3: 4, 1: 2}"); - assert_eq!(format!("{}", empty), "{}"); + assert!(map_str == "HashMap {1i: 2i, 3i: 4i}" || map_str == "{3i: 4i, 1i: 2i}"); + assert_eq!(format!("{:?}", empty), "HashMap {}"); } #[test] diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 211bfe2c10e..10e8ca6c622 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -88,7 +88,7 @@ use super::map::{self, HashMap, Keys, INITIAL_CAPACITY}; /// /// // Use derived implementation to print the vikings. /// for x in vikings.iter() { -/// println!("{}", x); +/// println!("{:?}", x); /// } /// ``` #[derive(Clone)] @@ -585,11 +585,11 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> Eq for HashSet<T, H> {} #[stable] impl<T: Eq + Hash<S> + fmt::Show, S, H: Hasher<S>> fmt::Show for HashSet<T, H> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - try!(write!(f, "{{")); + try!(write!(f, "HashSet {{")); for (i, x) in self.iter().enumerate() { if i != 0 { try!(write!(f, ", ")); } - try!(write!(f, "{}", *x)); + try!(write!(f, "{:?}", *x)); } write!(f, "}}") @@ -1116,10 +1116,10 @@ mod test_set { set.insert(1i); set.insert(2); - let set_str = format!("{}", set); + let set_str = format!("{:?}", set); - assert!(set_str == "{1, 2}" || set_str == "{2, 1}"); - assert_eq!(format!("{}", empty), "{}"); + assert!(set_str == "HashSet {1i, 2i}" || set_str == "{2i, 1i}"); + assert_eq!(format!("{:?}", empty), "HashSet {}"); } #[test] diff --git a/src/libstd/fmt.rs b/src/libstd/fmt.rs index 32f5f2d4536..d014f67172c 100644 --- a/src/libstd/fmt.rs +++ b/src/libstd/fmt.rs @@ -31,7 +31,7 @@ //! format!("Hello"); // => "Hello" //! format!("Hello, {}!", "world"); // => "Hello, world!" //! format!("The number is {}", 1i); // => "The number is 1" -//! format!("{}", (3i, 4i)); // => "(3, 4)" +//! format!("{:?}", (3i, 4i)); // => "(3i, 4i)" //! format!("{value}", value=4i); // => "4" //! format!("{} {}", 1i, 2u); // => "1 2" //! # } @@ -87,7 +87,7 @@ //! # fn main() { //! format!("{argument}", argument = "test"); // => "test" //! format!("{name} {}", 1i, name = 2i); // => "2 1" -//! format!("{a} {c} {b}", a="a", b=(), c=3i); // => "a 3 ()" +//! format!("{a} {c} {b}", a="a", b='b', c=3i); // => "a 3 b" //! # } //! ``` //! @@ -127,7 +127,8 @@ //! This allows multiple actual types to be formatted via `{:x}` (like `i8` as //! well as `int`). The current mapping of types to traits is: //! -//! * *nothing* ⇒ `Show` +//! * *nothing* ⇒ `String` +//! * `?` ⇒ `Show` //! * `o` ⇒ `Octal` //! * `x` ⇒ `LowerHex` //! * `X` ⇒ `UpperHex` @@ -140,8 +141,7 @@ //! `std::fmt::Binary` trait can then be formatted with `{:b}`. Implementations //! are provided for these traits for a number of primitive types by the //! standard library as well. If no format is specified (as in `{}` or `{:6}`), -//! then the format trait used is the `Show` trait. This is one of the more -//! commonly implemented traits when formatting a custom type. +//! then the format trait used is the `String` trait. //! //! When implementing a format trait for your own type, you will have to //! implement a method of the signature: @@ -175,12 +175,13 @@ //! use std::f64; //! use std::num::Float; //! +//! #[deriving(Show)] //! struct Vector2D { //! x: int, //! y: int, //! } //! -//! impl fmt::Show for Vector2D { +//! impl fmt::String for Vector2D { //! fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { //! // The `f` value implements the `Writer` trait, which is what the //! // write! macro is expecting. Note that this formatting ignores the @@ -209,10 +210,31 @@ //! let myvector = Vector2D { x: 3, y: 4 }; //! //! println!("{}", myvector); // => "(3, 4)" +//! println!("{:?}", myvector); // => "Vector2D {x: 3i, y:4i}" //! println!("{:10.3b}", myvector); // => " 5.000" //! } //! ``` //! +//! #### fmt::String vs fmt::Show +//! +//! These two formatting traits have distinct purposes: +//! +//! - `fmt::String` implementations assert that the type can be faithfully +//! represented as a UTF-8 string at all times. It is **not** expected that +//! all types implement the `String` trait. +//! - `fmt::Show` implementations should be implemented for **all** public types. +//! Output will typically represent the internal state as faithfully as possible. +//! The purpose of the `Show` trait is to facilitate debugging Rust code. In +//! most cases, using `#[deriving(Show)]` is sufficient and recommended. +//! +//! Some examples of the output from both traits: +//! +//! ``` +//! assert_eq(format!("{} {:?}", 3i32, 4i32), "3 4i32"); +//! assert_eq(format!("{} {:?}", 'a', 'b'), "a 'b'"); +//! assert_eq(format!("{} {:?}", "foo\n", "bar\n"), "foo\n \"bar\\n\""); +//! ``` +//! //! ### Related macros //! //! There are a number of related macros in the `format!` family. The ones that @@ -393,7 +415,7 @@ use string; pub use core::fmt::{Formatter, Result, Writer, rt}; -pub use core::fmt::{Show, Octal, Binary}; +pub use core::fmt::{Show, String, Octal, Binary}; pub use core::fmt::{LowerHex, UpperHex, Pointer}; pub use core::fmt::{LowerExp, UpperExp}; pub use core::fmt::Error; diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index 0fffb2fafbe..1556ef43eb7 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -107,7 +107,7 @@ impl File { /// /// let file = match File::open_mode(&p, Open, ReadWrite) { /// Ok(f) => f, - /// Err(e) => panic!("file error: {}", e), + /// Err(e) => panic!("file error: {:?}", e), /// }; /// // do some stuff with that file /// @@ -156,7 +156,7 @@ impl File { }) } }).update_err("couldn't open path as file", |e| { - format!("{}; path={}; mode={}; access={}", e, path.display(), + format!("{:?}; path={:?}; mode={}; access={}", e, path.display(), mode_string(mode), access_string(access)) }) } @@ -211,7 +211,7 @@ impl File { pub fn fsync(&mut self) -> IoResult<()> { self.fd.fsync() .update_err("couldn't fsync file", - |e| format!("{}; path={}", e, self.path.display())) + |e| format!("{:?}; path={:?}", e, self.path.display())) } /// This function is similar to `fsync`, except that it may not synchronize @@ -221,7 +221,7 @@ impl File { pub fn datasync(&mut self) -> IoResult<()> { self.fd.datasync() .update_err("couldn't datasync file", - |e| format!("{}; path={}", e, self.path.display())) + |e| format!("{:?}; path={:?}", e, self.path.display())) } /// Either truncates or extends the underlying file, updating the size of @@ -235,7 +235,7 @@ impl File { pub fn truncate(&mut self, size: i64) -> IoResult<()> { self.fd.truncate(size) .update_err("couldn't truncate file", |e| - format!("{}; path={}; size={}", e, self.path.display(), size)) + format!("{:?}; path={:?}; size={:?}", e, self.path.display(), size)) } /// Returns true if the stream has reached the end of the file. @@ -255,7 +255,7 @@ impl File { pub fn stat(&self) -> IoResult<FileStat> { self.fd.fstat() .update_err("couldn't fstat file", |e| - format!("{}; path={}", e, self.path.display())) + format!("{:?}; path={:?}", e, self.path.display())) } } @@ -283,7 +283,7 @@ impl File { pub fn unlink(path: &Path) -> IoResult<()> { fs_imp::unlink(path) .update_err("couldn't unlink path", |e| - format!("{}; path={}", e, path.display())) + format!("{:?}; path={:?}", e, path.display())) } /// Given a path, query the file system to get information about a file, @@ -310,7 +310,7 @@ pub fn unlink(path: &Path) -> IoResult<()> { pub fn stat(path: &Path) -> IoResult<FileStat> { fs_imp::stat(path) .update_err("couldn't stat path", |e| - format!("{}; path={}", e, path.display())) + format!("{:?}; path={:?}", e, path.display())) } /// Perform the same operation as the `stat` function, except that this @@ -324,7 +324,7 @@ pub fn stat(path: &Path) -> IoResult<FileStat> { pub fn lstat(path: &Path) -> IoResult<FileStat> { fs_imp::lstat(path) .update_err("couldn't lstat path", |e| - format!("{}; path={}", e, path.display())) + format!("{:?}; path={:?}", e, path.display())) } /// Rename a file or directory to a new name. @@ -346,7 +346,7 @@ pub fn lstat(path: &Path) -> IoResult<FileStat> { pub fn rename(from: &Path, to: &Path) -> IoResult<()> { fs_imp::rename(from, to) .update_err("couldn't rename path", |e| - format!("{}; from={}; to={}", e, from.display(), to.display())) + format!("{:?}; from={:?}; to={:?}", e, from.display(), to.display())) } /// Copies the contents of one file to another. This function will also @@ -380,7 +380,7 @@ pub fn rename(from: &Path, to: &Path) -> IoResult<()> { pub fn copy(from: &Path, to: &Path) -> IoResult<()> { fn update_err<T>(result: IoResult<T>, from: &Path, to: &Path) -> IoResult<T> { result.update_err("couldn't copy path", |e| { - format!("{}; from={}; to={}", e, from.display(), to.display()) + format!("{:?}; from={:?}; to={:?}", e, from.display(), to.display()) }) } @@ -424,14 +424,14 @@ pub fn copy(from: &Path, to: &Path) -> IoResult<()> { pub fn chmod(path: &Path, mode: io::FilePermission) -> IoResult<()> { fs_imp::chmod(path, mode.bits() as uint) .update_err("couldn't chmod path", |e| - format!("{}; path={}; mode={}", e, path.display(), mode)) + format!("{:?}; path={:?}; mode={:?}", e, path.display(), mode)) } /// Change the user and group owners of a file at the specified path. pub fn chown(path: &Path, uid: int, gid: int) -> IoResult<()> { fs_imp::chown(path, uid, gid) .update_err("couldn't chown path", |e| - format!("{}; path={}; uid={}; gid={}", e, path.display(), uid, gid)) + format!("{:?}; path={:?}; uid={:?}; gid={:?}", e, path.display(), uid, gid)) } /// Creates a new hard link on the filesystem. The `dst` path will be a @@ -440,7 +440,7 @@ pub fn chown(path: &Path, uid: int, gid: int) -> IoResult<()> { pub fn link(src: &Path, dst: &Path) -> IoResult<()> { fs_imp::link(src, dst) .update_err("couldn't link path", |e| - format!("{}; src={}; dest={}", e, src.display(), dst.display())) + format!("{:?}; src={:?}; dest={:?}", e, src.display(), dst.display())) } /// Creates a new symbolic link on the filesystem. The `dst` path will be a @@ -448,7 +448,7 @@ pub fn link(src: &Path, dst: &Path) -> IoResult<()> { pub fn symlink(src: &Path, dst: &Path) -> IoResult<()> { fs_imp::symlink(src, dst) .update_err("couldn't symlink path", |e| - format!("{}; src={}; dest={}", e, src.display(), dst.display())) + format!("{:?}; src={:?}; dest={:?}", e, src.display(), dst.display())) } /// Reads a symlink, returning the file that the symlink points to. @@ -460,7 +460,7 @@ pub fn symlink(src: &Path, dst: &Path) -> IoResult<()> { pub fn readlink(path: &Path) -> IoResult<Path> { fs_imp::readlink(path) .update_err("couldn't resolve symlink for path", |e| - format!("{}; path={}", e, path.display())) + format!("{:?}; path={:?}", e, path.display())) } /// Create a new, empty directory at the provided path @@ -483,7 +483,7 @@ pub fn readlink(path: &Path) -> IoResult<Path> { pub fn mkdir(path: &Path, mode: FilePermission) -> IoResult<()> { fs_imp::mkdir(path, mode.bits() as uint) .update_err("couldn't create directory", |e| - format!("{}; path={}; mode={}", e, path.display(), mode)) + format!("{:?}; path={:?}; mode={:?}", e, path.display(), mode)) } /// Remove an existing, empty directory @@ -505,7 +505,7 @@ pub fn mkdir(path: &Path, mode: FilePermission) -> IoResult<()> { pub fn rmdir(path: &Path) -> IoResult<()> { fs_imp::rmdir(path) .update_err("couldn't remove directory", |e| - format!("{}; path={}", e, path.display())) + format!("{:?}; path={:?}", e, path.display())) } /// Retrieve a vector containing all entries within a provided directory @@ -545,7 +545,7 @@ pub fn rmdir(path: &Path) -> IoResult<()> { pub fn readdir(path: &Path) -> IoResult<Vec<Path>> { fs_imp::readdir(path) .update_err("couldn't read directory", - |e| format!("{}; path={}", e, path.display())) + |e| format!("{:?}; path={:?}", e, path.display())) } /// Returns an iterator that will recursively walk the directory structure @@ -555,7 +555,7 @@ pub fn readdir(path: &Path) -> IoResult<Vec<Path>> { pub fn walk_dir(path: &Path) -> IoResult<Directories> { Ok(Directories { stack: try!(readdir(path).update_err("couldn't walk directory", - |e| format!("{}; path={}", e, path.display()))) + |e| format!("{:?}; path={:?}", e, path.display()))) }) } @@ -605,7 +605,7 @@ pub fn mkdir_recursive(path: &Path, mode: FilePermission) -> IoResult<()> { let result = mkdir(&curpath, mode) .update_err("couldn't recursively mkdir", - |e| format!("{}; path={}", e, path.display())); + |e| format!("{:?}; path={:?}", e, path.display())); match result { Err(mkdir_err) => { @@ -632,7 +632,7 @@ pub fn rmdir_recursive(path: &Path) -> IoResult<()> { rm_stack.push(path.clone()); fn rmdir_failed(err: &IoError, path: &Path) -> String { - format!("rmdir_recursive failed; path={}; cause={}", + format!("rmdir_recursive failed; path={:?}; cause={:?}", path.display(), err) } @@ -692,14 +692,14 @@ pub fn rmdir_recursive(path: &Path) -> IoResult<()> { pub fn change_file_times(path: &Path, atime: u64, mtime: u64) -> IoResult<()> { fs_imp::utime(path, atime, mtime) .update_err("couldn't change_file_times", |e| - format!("{}; path={}", e, path.display())) + format!("{:?}; path={:?}", e, path.display())) } impl Reader for File { fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> { fn update_err<T>(result: IoResult<T>, file: &File) -> IoResult<T> { result.update_err("couldn't read file", - |e| format!("{}; path={}", + |e| format!("{:?}; path={:?}", e, file.path.display())) } @@ -722,7 +722,7 @@ impl Writer for File { fn write(&mut self, buf: &[u8]) -> IoResult<()> { self.fd.write(buf) .update_err("couldn't write to file", - |e| format!("{}; path={}", e, self.path.display())) + |e| format!("{:?}; path={:?}", e, self.path.display())) } } @@ -730,7 +730,7 @@ impl Seek for File { fn tell(&self) -> IoResult<u64> { self.fd.tell() .update_err("couldn't retrieve file cursor (`tell`)", - |e| format!("{}; path={}", e, self.path.display())) + |e| format!("{:?}; path={:?}", e, self.path.display())) } fn seek(&mut self, pos: i64, style: SeekStyle) -> IoResult<()> { @@ -743,7 +743,7 @@ impl Seek for File { Err(e) => Err(e), }; err.update_err("couldn't seek in file", - |e| format!("{}; path={}", e, self.path.display())) + |e| format!("{:?}; path={:?}", e, self.path.display())) } } @@ -832,15 +832,15 @@ mod test { macro_rules! check { ($e:expr) => ( match $e { Ok(t) => t, - Err(e) => panic!("{} failed with: {}", stringify!($e), e), + Err(e) => panic!("{} failed with: {:?}", stringify!($e), e), } ) } macro_rules! error { ($e:expr, $s:expr) => ( match $e { - Ok(_) => panic!("Unexpected success. Should've been: {}", $s), + Ok(_) => panic!("Unexpected success. Should've been: {:?}", $s), Err(ref err) => assert!(err.to_string().contains($s.as_slice()), - format!("`{}` did not contain `{}`", err, $s)) + format!("`{:?}` did not contain `{:?}`", err, $s)) } ) } @@ -906,7 +906,7 @@ mod test { if cfg!(unix) { error!(result, "no such file or directory"); } - error!(result, format!("path={}; mode=open; access=read", filename.display())); + error!(result, format!("path={:?}; mode=open; access=read", filename.display())); } #[test] @@ -920,7 +920,7 @@ mod test { if cfg!(unix) { error!(result, "no such file or directory"); } - error!(result, format!("path={}", filename.display())); + error!(result, format!("path={:?}", filename.display())); } #[test] @@ -1188,7 +1188,7 @@ mod test { error!(result, "couldn't recursively mkdir"); error!(result, "couldn't create directory"); error!(result, "mode=0700"); - error!(result, format!("path={}", file.display())); + error!(result, format!("path={:?}", file.display())); } #[test] @@ -1255,7 +1255,7 @@ mod test { error!(copy(&from, &to), format!("couldn't copy path (the source path is not an \ - existing file; from={}; to={})", + existing file; from={:?}; to={:?})", from.display(), to.display())); match copy(&from, &to) { diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 465c4f9c5c7..010cb814732 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -302,7 +302,7 @@ pub type IoResult<T> = Result<T, IoError>; /// # FIXME /// /// Is something like this sufficient? It's kind of archaic -#[derive(PartialEq, Eq, Clone)] +#[derive(PartialEq, Eq, Clone, Show)] pub struct IoError { /// An enumeration which can be matched against for determining the flavor /// of error. @@ -339,7 +339,7 @@ impl IoError { } } -impl fmt::Show for IoError { +impl fmt::String for IoError { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { match *self { IoError { kind: OtherIoError, desc: "unknown error", detail: Some(ref detail) } => @@ -1656,7 +1656,7 @@ pub fn standard_error(kind: IoErrorKind) -> IoError { /// A mode specifies how a file should be opened or created. These modes are /// passed to `File::open_mode` and are used to control where the file is /// positioned when it is initially opened. -#[derive(Copy, Clone, PartialEq, Eq)] +#[derive(Copy, Clone, PartialEq, Eq, Show)] pub enum FileMode { /// Opens a file positioned at the beginning. Open, @@ -1668,7 +1668,7 @@ pub enum FileMode { /// Access permissions with which the file should be opened. `File`s /// opened with `Read` will return an error if written to. -#[derive(Copy, Clone, PartialEq, Eq)] +#[derive(Copy, Clone, PartialEq, Eq, Show)] pub enum FileAccess { /// Read-only access, requests to write will result in an error Read, @@ -1826,6 +1826,12 @@ impl Default for FilePermission { impl fmt::Show for FilePermission { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::String::fmt(self, f) + } +} + +impl fmt::String for FilePermission { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{:04o}", self.bits) } } diff --git a/src/libstd/io/net/addrinfo.rs b/src/libstd/io/net/addrinfo.rs index 24d45dcd652..7825a4e16e1 100644 --- a/src/libstd/io/net/addrinfo.rs +++ b/src/libstd/io/net/addrinfo.rs @@ -29,7 +29,7 @@ use sys; use vec::Vec; /// Hints to the types of sockets that are desired when looking up hosts -#[derive(Copy)] +#[derive(Copy, Show)] pub enum SocketType { Stream, Datagram, Raw } @@ -38,7 +38,7 @@ pub enum SocketType { /// to manipulate how a query is performed. /// /// The meaning of each of these flags can be found with `man -s 3 getaddrinfo` -#[derive(Copy)] +#[derive(Copy, Show)] pub enum Flag { AddrConfig, All, @@ -51,7 +51,7 @@ pub enum Flag { /// A transport protocol associated with either a hint or a return value of /// `lookup` -#[derive(Copy)] +#[derive(Copy, Show)] pub enum Protocol { TCP, UDP } @@ -61,7 +61,7 @@ pub enum Protocol { /// /// For details on these fields, see their corresponding definitions via /// `man -s 3 getaddrinfo` -#[derive(Copy)] +#[derive(Copy, Show)] pub struct Hint { pub family: uint, pub socktype: Option<SocketType>, @@ -69,7 +69,7 @@ pub struct Hint { pub flags: uint, } -#[derive(Copy)] +#[derive(Copy, Show)] pub struct Info { pub address: SocketAddr, pub family: uint, diff --git a/src/libstd/io/net/ip.rs b/src/libstd/io/net/ip.rs index 6cb2463fcbc..b9f653f86c2 100644 --- a/src/libstd/io/net/ip.rs +++ b/src/libstd/io/net/ip.rs @@ -32,13 +32,13 @@ use vec::Vec; pub type Port = u16; -#[derive(Copy, PartialEq, Eq, Clone, Hash)] +#[derive(Copy, PartialEq, Eq, Clone, Hash, Show)] pub enum IpAddr { Ipv4Addr(u8, u8, u8, u8), Ipv6Addr(u16, u16, u16, u16, u16, u16, u16, u16) } -impl fmt::Show for IpAddr { +impl fmt::String for IpAddr { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { match *self { Ipv4Addr(a, b, c, d) => @@ -63,13 +63,13 @@ impl fmt::Show for IpAddr { } } -#[derive(Copy, PartialEq, Eq, Clone, Hash)] +#[derive(Copy, PartialEq, Eq, Clone, Hash, Show)] pub struct SocketAddr { pub ip: IpAddr, pub port: Port, } -impl fmt::Show for SocketAddr { +impl fmt::String for SocketAddr { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.ip { Ipv4Addr(..) => write!(f, "{}:{}", self.ip, self.port), diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index 5f77ab38d74..efb57341620 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -395,7 +395,14 @@ impl Command { } } +#[cfg(stage0)] impl fmt::Show for Command { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::String::fmt(self, f) + } +} + +impl fmt::String for Command { /// Format the program and arguments of a Command for display. Any /// non-utf8 data is lossily converted using the utf8 replacement /// character. @@ -506,6 +513,14 @@ pub enum ProcessExit { impl fmt::Show for ProcessExit { /// Format a ProcessExit enum, to nicely present the information. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::String::fmt(self, f) + } +} + + +impl fmt::String for ProcessExit { + /// Format a ProcessExit enum, to nicely present the information. + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { ExitStatus(code) => write!(f, "exit code: {}", code), ExitSignal(code) => write!(f, "signal: {}", code), diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index f571bed3ba2..d7bc572106e 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -349,7 +349,7 @@ fn with_task_stdout<F>(f: F) where F: FnOnce(&mut Writer) -> IoResult<()> { }); match result { Ok(()) => {} - Err(e) => panic!("failed printing to stdout: {}", e), + Err(e) => panic!("failed printing to stdout: {:?}", e), } } diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index d96441e09a8..be3e49c0b82 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -111,7 +111,7 @@ macro_rules! assert_eq { if !((*left_val == *right_val) && (*right_val == *left_val)) { panic!("assertion failed: `(left == right) && (right == left)` \ - (left: `{}`, right: `{}`)", *left_val, *right_val) + (left: `{:?}`, right: `{:?}`)", *left_val, *right_val) } } } diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 72ad16e0a5d..5d23f2a9b93 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -93,7 +93,7 @@ pub const TMPBUF_SZ : uint = 1000u; /// /// // We assume that we are in a valid directory. /// let current_working_directory = os::getcwd().unwrap(); -/// println!("The current directory is {}", current_working_directory.display()); +/// println!("The current directory is {:?}", current_working_directory.display()); /// ``` pub fn getcwd() -> IoResult<Path> { sys::os::getcwd() @@ -934,7 +934,7 @@ impl fmt::Show for MapError { impl Error for MapError { fn description(&self) -> &str { "memory map error" } - fn detail(&self) -> Option<String> { Some(self.to_string()) } + fn detail(&self) -> Option<String> { Some(format!("{:?}", self)) } } impl FromError<MapError> for Box<Error> { diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index 87188c0d4a2..0448e6907e3 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -460,7 +460,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # #[cfg(unix)] fn foo() { /// let mut p = Path::new("abc/def.txt"); /// p.set_extension("csv"); - /// assert!(p == Path::new("abc/def.csv")); + /// assert_eq!(p, Path::new("abc/def.csv")); /// # } /// ``` /// @@ -509,7 +509,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # #[cfg(windows)] fn foo() {} /// # #[cfg(unix)] fn foo() { /// let mut p = Path::new("abc/def.txt"); - /// assert!(p.with_filename("foo.dat") == Path::new("abc/foo.dat")); + /// assert_eq!(p.with_filename("foo.dat"), Path::new("abc/foo.dat")); /// # } /// ``` /// @@ -534,7 +534,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # #[cfg(windows)] fn foo() {} /// # #[cfg(unix)] fn foo() { /// let mut p = Path::new("abc/def.txt"); - /// assert!(p.with_extension("csv") == Path::new("abc/def.csv")); + /// assert_eq!(p.with_extension("csv"), Path::new("abc/def.csv")); /// # } /// ``` /// @@ -558,7 +558,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # #[cfg(windows)] fn foo() {} /// # #[cfg(unix)] fn foo() { /// let p = Path::new("abc/def/ghi"); - /// assert!(p.dir_path() == Path::new("abc/def")); + /// assert_eq!(p.dir_path(), Path::new("abc/def")); /// # } /// ``` fn dir_path(&self) -> Self { @@ -576,8 +576,8 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # foo(); /// # #[cfg(windows)] fn foo() {} /// # #[cfg(unix)] fn foo() { - /// assert!(Path::new("abc/def").root_path() == None); - /// assert!(Path::new("/abc/def").root_path() == Some(Path::new("/"))); + /// assert_eq!(Path::new("abc/def").root_path(), None); + /// assert_eq!(Path::new("/abc/def").root_path(), Some(Path::new("/"))); /// # } /// ``` fn root_path(&self) -> Option<Self>; @@ -593,7 +593,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # #[cfg(unix)] fn foo() { /// let mut p = Path::new("foo/bar"); /// p.push("baz.txt"); - /// assert!(p == Path::new("foo/bar/baz.txt")); + /// assert_eq!(p, Path::new("foo/bar/baz.txt")); /// # } /// ``` /// @@ -617,7 +617,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # #[cfg(unix)] fn foo() { /// let mut p = Path::new("foo"); /// p.push_many(&["bar", "baz.txt"]); - /// assert!(p == Path::new("foo/bar/baz.txt")); + /// assert_eq!(p, Path::new("foo/bar/baz.txt")); /// # } /// ``` #[inline] @@ -646,7 +646,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # #[cfg(unix)] fn foo() { /// let mut p = Path::new("foo/bar/baz.txt"); /// p.pop(); - /// assert!(p == Path::new("foo/bar")); + /// assert_eq!(p, Path::new("foo/bar")); /// # } /// ``` fn pop(&mut self) -> bool; @@ -662,7 +662,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # #[cfg(windows)] fn foo() {} /// # #[cfg(unix)] fn foo() { /// let p = Path::new("/foo"); - /// assert!(p.join("bar.txt") == Path::new("/foo/bar.txt")); + /// assert_eq!(p.join("bar.txt"), Path::new("/foo/bar.txt")); /// # } /// ``` /// @@ -688,7 +688,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # #[cfg(unix)] fn foo() { /// let p = Path::new("foo"); /// let fbbq = Path::new("foo/bar/baz/quux.txt"); - /// assert!(p.join_many(&["bar", "baz", "quux.txt"]) == fbbq); + /// assert_eq!(p.join_many(&["bar", "baz", "quux.txt"]), fbbq); /// # } /// ``` #[inline] @@ -765,7 +765,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// let p = Path::new("foo/bar/baz/quux.txt"); /// let fb = Path::new("foo/bar"); /// let bq = Path::new("baz/quux.txt"); - /// assert!(p.path_relative_from(&fb) == Some(bq)); + /// assert_eq!(p.path_relative_from(&fb), Some(bq)); /// # } /// ``` fn path_relative_from(&self, base: &Self) -> Option<Self>; @@ -823,8 +823,15 @@ pub struct Display<'a, P:'a> { filename: bool } +//NOTE(stage0): replace with deriving(Show) after snapshot impl<'a, P: GenericPath> fmt::Show for Display<'a, P> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::String::fmt(self, f) + } +} + +impl<'a, P: GenericPath> fmt::String for Display<'a, P> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.as_cow().fmt(f) } } diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 7f37d3b23c8..7c5455ed3fc 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -12,6 +12,7 @@ use clone::Clone; use cmp::{Ordering, Eq, Ord, PartialEq, PartialOrd}; +use fmt; use hash; use io::Writer; use iter::{AdditiveIterator, Extend}; @@ -57,6 +58,12 @@ pub fn is_sep(c: char) -> bool { c == SEP } +impl fmt::Show for Path { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Path {{ {} }}", self.display()) + } +} + impl PartialEq for Path { #[inline] fn eq(&self, other: &Path) -> bool { @@ -439,13 +446,13 @@ mod tests { (s: $path:expr, $exp:expr) => ( { let path = $path; - assert!(path.as_str() == Some($exp)); + assert_eq!(path.as_str(), Some($exp)); } ); (v: $path:expr, $exp:expr) => ( { let path = $path; - assert!(path.as_vec() == $exp); + assert_eq!(path.as_vec(), $exp); } ) } @@ -459,7 +466,7 @@ mod tests { t!(v: Path::new(b"a/b/c\xFF"), b"a/b/c\xFF"); t!(v: Path::new(b"\xFF/../foo\x80"), b"foo\x80"); let p = Path::new(b"a/b/c\xFF"); - assert!(p.as_str() == None); + assert!(p.as_str().is_none()); t!(s: Path::new(""), "."); t!(s: Path::new("/"), "/"); @@ -489,14 +496,14 @@ mod tests { b"/bar"); let p = Path::new(b"foo/bar\x80"); - assert!(p.as_str() == None); + assert!(p.as_str().is_none()); } #[test] fn test_opt_paths() { - assert!(Path::new_opt(b"foo/bar\0") == None); + assert!(Path::new_opt(b"foo/bar\0").is_none()); t!(v: Path::new_opt(b"foo/bar").unwrap(), b"foo/bar"); - assert!(Path::new_opt("foo/bar\0") == None); + assert!(Path::new_opt("foo/bar\0").is_none()); t!(s: Path::new_opt("foo/bar").unwrap(), "foo/bar"); } @@ -525,7 +532,7 @@ mod tests { ($path:expr, $disp:ident, $exp:expr) => ( { let path = Path::new($path); - assert!(path.$disp().to_string() == $exp); + assert_eq!(path.$disp().to_string(), $exp); } ) } @@ -541,14 +548,14 @@ mod tests { { let path = Path::new($path); let mo = path.display().as_cow(); - assert!(mo.as_slice() == $exp); + assert_eq!(mo.as_slice(), $exp); } ); ($path:expr, $exp:expr, filename) => ( { let path = Path::new($path); let mo = path.filename_display().as_cow(); - assert!(mo.as_slice() == $exp); + assert_eq!(mo.as_slice(), $exp); } ) } @@ -568,9 +575,9 @@ mod tests { { let path = Path::new($path); let f = format!("{}", path.display()); - assert!(f == $exp); + assert_eq!(f, $exp); let f = format!("{}", path.filename_display()); - assert!(f == $expf); + assert_eq!(f, $expf); } ) } @@ -590,21 +597,21 @@ mod tests { (s: $path:expr, $op:ident, $exp:expr) => ( { let path = Path::new($path); - assert!(path.$op() == ($exp).as_bytes()); + assert_eq!(path.$op(), ($exp).as_bytes()); } ); (s: $path:expr, $op:ident, $exp:expr, opt) => ( { let path = Path::new($path); let left = path.$op().map(|x| str::from_utf8(x).unwrap()); - assert!(left == $exp); + assert_eq!(left, $exp); } ); (v: $path:expr, $op:ident, $exp:expr) => ( { let arg = $path; let path = Path::new(arg); - assert!(path.$op() == $exp); + assert_eq!(path.$op(), $exp); } ); } @@ -678,7 +685,7 @@ mod tests { let mut p1 = Path::new(path); let p2 = p1.clone(); p1.push(join); - assert!(p1 == p2.join(join)); + assert_eq!(p1, p2.join(join)); } ) } @@ -697,7 +704,7 @@ mod tests { let mut p = Path::new($path); let push = Path::new($push); p.push(&push); - assert!(p.as_str() == Some($exp)); + assert_eq!(p.as_str(), Some($exp)); } ) } @@ -717,14 +724,14 @@ mod tests { { let mut p = Path::new($path); p.push_many(&$push); - assert!(p.as_str() == Some($exp)); + assert_eq!(p.as_str(), Some($exp)); } ); (v: $path:expr, $push:expr, $exp:expr) => ( { let mut p = Path::new($path); p.push_many(&$push); - assert!(p.as_vec() == $exp); + assert_eq!(p.as_vec(), $exp); } ) } @@ -745,16 +752,16 @@ mod tests { { let mut p = Path::new($path); let result = p.pop(); - assert!(p.as_str() == Some($left)); - assert!(result == $right); + assert_eq!(p.as_str(), Some($left)); + assert_eq!(result, $right); } ); (b: $path:expr, $left:expr, $right:expr) => ( { let mut p = Path::new($path); let result = p.pop(); - assert!(p.as_vec() == $left); - assert!(result == $right); + assert_eq!(p.as_vec(), $left); + assert_eq!(result, $right); } ) } @@ -777,8 +784,8 @@ mod tests { #[test] fn test_root_path() { - assert!(Path::new(b"a/b/c").root_path() == None); - assert!(Path::new(b"/a/b/c").root_path() == Some(Path::new("/"))); + assert_eq!(Path::new(b"a/b/c").root_path(), None); + assert_eq!(Path::new(b"/a/b/c").root_path(), Some(Path::new("/"))); } #[test] @@ -802,7 +809,7 @@ mod tests { let path = Path::new($path); let join = Path::new($join); let res = path.join(&join); - assert!(res.as_str() == Some($exp)); + assert_eq!(res.as_str(), Some($exp)); } ) } @@ -822,14 +829,14 @@ mod tests { { let path = Path::new($path); let res = path.join_many(&$join); - assert!(res.as_str() == Some($exp)); + assert_eq!(res.as_str(), Some($exp)); } ); (v: $path:expr, $join:expr, $exp:expr) => ( { let path = Path::new($path); let res = path.join_many(&$join); - assert!(res.as_vec() == $exp); + assert_eq!(res.as_vec(), $exp); } ) } @@ -903,7 +910,7 @@ mod tests { let mut p1 = Path::new(path); p1.$set(arg); let p2 = Path::new(path); - assert!(p1 == p2.$with(arg)); + assert_eq!(p1, p2.$with(arg)); } ); (v: $path:expr, $set:ident, $with:ident, $arg:expr) => ( @@ -913,7 +920,7 @@ mod tests { let mut p1 = Path::new(path); p1.$set(arg); let p2 = Path::new(path); - assert!(p1 == p2.$with(arg)); + assert_eq!(p1, p2.$with(arg)); } ) } @@ -943,31 +950,19 @@ mod tests { (s: $path:expr, $filename:expr, $dirname:expr, $filestem:expr, $ext:expr) => ( { let path = $path; - let filename = $filename; - assert!(path.filename_str() == filename, - "{}.filename_str(): Expected `{}`, found {}", - path.as_str().unwrap(), filename, path.filename_str()); - let dirname = $dirname; - assert!(path.dirname_str() == dirname, - "`{}`.dirname_str(): Expected `{}`, found `{}`", - path.as_str().unwrap(), dirname, path.dirname_str()); - let filestem = $filestem; - assert!(path.filestem_str() == filestem, - "`{}`.filestem_str(): Expected `{}`, found `{}`", - path.as_str().unwrap(), filestem, path.filestem_str()); - let ext = $ext; - assert!(path.extension_str() == ext, - "`{}`.extension_str(): Expected `{}`, found `{}`", - path.as_str().unwrap(), ext, path.extension_str()); - } + assert_eq!(path.filename_str(), $filename); + assert_eq!(path.dirname_str(), $dirname); + assert_eq!(path.filestem_str(), $filestem); + assert_eq!(path.extension_str(), $ext); + } ); (v: $path:expr, $filename:expr, $dirname:expr, $filestem:expr, $ext:expr) => ( { let path = $path; - assert!(path.filename() == $filename); - assert!(path.dirname() == $dirname); - assert!(path.filestem() == $filestem); - assert!(path.extension() == $ext); + assert_eq!(path.filename(), $filename); + assert_eq!(path.dirname(), $dirname); + assert_eq!(path.filestem(), $filestem); + assert_eq!(path.extension(), $ext); } ) } @@ -1155,12 +1150,10 @@ mod tests { let comps = path.components().collect::<Vec<&[u8]>>(); let exp: &[&str] = &$exp; let exps = exp.iter().map(|x| x.as_bytes()).collect::<Vec<&[u8]>>(); - assert!(comps == exps, "components: Expected {}, found {}", - comps, exps); + assert_eq!(comps, exprs); let comps = path.components().rev().collect::<Vec<&[u8]>>(); let exps = exps.into_iter().rev().collect::<Vec<&[u8]>>(); - assert!(comps == exps, "rev_components: Expected {}, found {}", - comps, exps); + assert_eq!(comps, exps); } ); (b: $arg:expr, [$($exp:expr),*]) => ( diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 97545bc2022..ff269b73476 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -18,6 +18,7 @@ use ascii::AsciiExt; use char::CharExt; use clone::Clone; use cmp::{Ordering, Eq, Ord, PartialEq, PartialOrd}; +use fmt; use hash; use io::Writer; use iter::{AdditiveIterator, Extend}; @@ -84,6 +85,12 @@ pub struct Path { sepidx: Option<uint> // index of the final separator in the non-prefix portion of repr } +impl fmt::Show for Path { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Path {{ {} }}", self.display()) + } +} + impl PartialEq for Path { #[inline] fn eq(&self, other: &Path) -> bool { @@ -1119,13 +1126,13 @@ mod tests { (s: $path:expr, $exp:expr) => ( { let path = $path; - assert!(path.as_str() == Some($exp)); + assert_eq!(path.as_str(), Some($exp)); } ); (v: $path:expr, $exp:expr) => ( { let path = $path; - assert!(path.as_vec() == $exp); + assert_eq!(path.as_vec(), $exp); } ) } @@ -1138,8 +1145,7 @@ mod tests { let path = $path; let exp = $exp; let res = parse_prefix(path); - assert!(res == exp, - "parse_prefix(\"{}\"): expected {}, found {}", path, exp, res); + assert_eq!(res, exp); } ) } @@ -1355,7 +1361,7 @@ mod tests { { let path = $path; let path = Path::new(path); - assert!(path.$op() == Some($exp)); + assert_eq!(path.$op(), Some($exp)); } ); (s: $path:expr, $op:ident, $exp:expr, opt) => ( @@ -1363,14 +1369,14 @@ mod tests { let path = $path; let path = Path::new(path); let left = path.$op(); - assert!(left == $exp); + assert_eq!(left, $exp); } ); (v: $path:expr, $op:ident, $exp:expr) => ( { let path = $path; let path = Path::new(path); - assert!(path.$op() == $exp); + assert_eq!(path.$op(), $exp); } ) } @@ -1481,7 +1487,7 @@ mod tests { let mut p1 = Path::new(path); let p2 = p1.clone(); p1.push(join); - assert!(p1 == p2.join(join)); + assert_eq!(p1, p2.join(join)); } ) } @@ -1495,9 +1501,9 @@ mod tests { // we do want to check one odd case though to ensure the prefix is re-parsed let mut p = Path::new("\\\\?\\C:"); - assert!(prefix(&p) == Some(VerbatimPrefix(2))); + assert_eq!(prefix(&p), Some(VerbatimPrefix(2))); p.push("foo"); - assert!(prefix(&p) == Some(VerbatimDiskPrefix)); + assert_eq!(prefix(&p), Some(VerbatimDiskPrefix)); assert_eq!(p.as_str(), Some("\\\\?\\C:\\foo")); // and another with verbatim non-normalized paths @@ -1596,10 +1602,8 @@ mod tests { let mut p = Path::new(pstr); let result = p.pop(); let left = $left; - assert!(p.as_str() == Some(left), - "`{}`.pop() failed; expected remainder `{}`, found `{}`", - pstr, left, p.as_str().unwrap()); - assert!(result == $right); + assert_eq!(p.as_str(), Some(left)); + assert_eq!(result, $right); } ); (b: $path:expr, $left:expr, $right:expr) => ( @@ -1607,7 +1611,7 @@ mod tests { let mut p = Path::new($path); let result = p.pop(); assert_eq!(p.as_vec(), $left); - assert!(result == $right); + assert_eq!(result, $right); } ) } @@ -1650,16 +1654,16 @@ mod tests { #[test] fn test_root_path() { - assert!(Path::new("a\\b\\c").root_path() == None); - assert!(Path::new("\\a\\b\\c").root_path() == Some(Path::new("\\"))); - assert!(Path::new("C:a").root_path() == Some(Path::new("C:"))); - assert!(Path::new("C:\\a").root_path() == Some(Path::new("C:\\"))); - assert!(Path::new("\\\\a\\b\\c").root_path() == Some(Path::new("\\\\a\\b"))); - assert!(Path::new("\\\\?\\a\\b").root_path() == Some(Path::new("\\\\?\\a"))); - assert!(Path::new("\\\\?\\C:\\a").root_path() == Some(Path::new("\\\\?\\C:\\"))); - assert!(Path::new("\\\\?\\UNC\\a\\b\\c").root_path() == + assert_eq!(Path::new("a\\b\\c").root_path(), None); + assert_eq!(Path::new("\\a\\b\\c").root_path(), Some(Path::new("\\"))); + assert_eq!(Path::new("C:a").root_path(), Some(Path::new("C:"))); + assert_eq!(Path::new("C:\\a").root_path(), Some(Path::new("C:\\"))); + assert_eq!(Path::new("\\\\a\\b\\c").root_path(), Some(Path::new("\\\\a\\b"))); + assert_eq!(Path::new("\\\\?\\a\\b").root_path(), Some(Path::new("\\\\?\\a"))); + assert_eq!(Path::new("\\\\?\\C:\\a").root_path(), Some(Path::new("\\\\?\\C:\\"))); + assert_eq!(Path::new("\\\\?\\UNC\\a\\b\\c").root_path(), Some(Path::new("\\\\?\\UNC\\a\\b"))); - assert!(Path::new("\\\\.\\a\\b").root_path() == Some(Path::new("\\\\.\\a"))); + assert_eq!(Path::new("\\\\.\\a\\b").root_path(), Some(Path::new("\\\\.\\a"))); } #[test] @@ -1737,9 +1741,7 @@ mod tests { let arg = $arg; let res = path.$op(arg); let exp = $res; - assert!(res.as_str() == Some(exp), - "`{}`.{}(\"{}\"): Expected `{}`, found `{}`", - pstr, stringify!($op), arg, exp, res.as_str().unwrap()); + assert_eq!(Path::new($path).$op($arg), $res); } ) } @@ -1822,7 +1824,7 @@ mod tests { let mut p1 = Path::new(path); p1.$set(arg); let p2 = Path::new(path); - assert!(p1 == p2.$with(arg)); + assert_eq!(p1, p2.$with(arg)); } ); (v: $path:expr, $set:ident, $with:ident, $arg:expr) => ( @@ -1832,7 +1834,7 @@ mod tests { let mut p1 = Path::new(path); p1.$set(arg); let p2 = Path::new(path); - assert!(p1 == p2.$with(arg)); + assert_eq!(p1, p2.$with(arg)); } ) } @@ -1863,31 +1865,19 @@ mod tests { (s: $path:expr, $filename:expr, $dirname:expr, $filestem:expr, $ext:expr) => ( { let path = $path; - let filename = $filename; - assert!(path.filename_str() == filename, - "`{}`.filename_str(): Expected `{}`, found `{}`", - path.as_str().unwrap(), filename, path.filename_str()); - let dirname = $dirname; - assert!(path.dirname_str() == dirname, - "`{}`.dirname_str(): Expected `{}`, found `{}`", - path.as_str().unwrap(), dirname, path.dirname_str()); - let filestem = $filestem; - assert!(path.filestem_str() == filestem, - "`{}`.filestem_str(): Expected `{}`, found `{}`", - path.as_str().unwrap(), filestem, path.filestem_str()); - let ext = $ext; - assert!(path.extension_str() == ext, - "`{}`.extension_str(): Expected `{}`, found `{}`", - path.as_str().unwrap(), ext, path.extension_str()); + assert_eq!(path.filename_str(), $filename); + assert_eq!(path.dirname_str(), $dirname); + assert_eq!(path.filestem_str(), $filestem); + assert_eq!(path.extension_str(), $ext); } ); (v: $path:expr, $filename:expr, $dirname:expr, $filestem:expr, $ext:expr) => ( { let path = $path; - assert!(path.filename() == $filename); - assert!(path.dirname() == $dirname); - assert!(path.filestem() == $filestem); - assert!(path.extension() == $ext); + assert_eq!(path.filename(), $filename); + assert_eq!(path.dirname(), $dirname); + assert_eq!(path.filestem(), $filestem); + assert_eq!(path.extension(), $ext); } ) } @@ -1931,17 +1921,10 @@ mod tests { let path = Path::new($path); let (abs, vol, cwd, rel) = ($abs, $vol, $cwd, $rel); let b = path.is_absolute(); - assert!(b == abs, "Path '{}'.is_absolute(): expected {}, found {}", - path.as_str().unwrap(), abs, b); - let b = is_vol_relative(&path); - assert!(b == vol, "is_vol_relative('{}'): expected {}, found {}", - path.as_str().unwrap(), vol, b); - let b = is_cwd_relative(&path); - assert!(b == cwd, "is_cwd_relative('{}'): expected {}, found {}", - path.as_str().unwrap(), cwd, b); - let b = path.is_relative(); - assert!(b == rel, "Path '{}'.is_relativf(): expected {}, found {}", - path.as_str().unwrap(), rel, b); + assert_eq!(path.is_absolute(), asb); + assert_eq!(is_vol_relative(&path), vol); + assert_eq!(is_cwd_relative(&path), cwd); + assert_eq!(path.is_relative(), rel); } ) } @@ -1972,9 +1955,7 @@ mod tests { let dest = Path::new($dest); let exp = $exp; let res = path.is_ancestor_of(&dest); - assert!(res == exp, - "`{}`.is_ancestor_of(`{}`): Expected {}, found {}", - path.as_str().unwrap(), dest.as_str().unwrap(), exp, res); + assert_eq!(Path::new($path).is_ancestor_of(Path::new($dest)), $exp); } ) } @@ -2103,14 +2084,8 @@ mod tests { macro_rules! t { (s: $path:expr, $other:expr, $exp:expr) => ( { - let path = Path::new($path); - let other = Path::new($other); - let res = path.path_relative_from(&other); - let exp = $exp; - assert!(res.as_ref().and_then(|x| x.as_str()) == exp, - "`{}`.path_relative_from(`{}`): Expected {}, got {}", - path.as_str().unwrap(), other.as_str().unwrap(), exp, - res.as_ref().and_then(|x| x.as_str())); + assert_eq!(Path::new($path).path_relative_from(Path::new($other)) + .as_ref().and_then(|x| x.as_str()), $exp); } ) } @@ -2319,7 +2294,7 @@ mod tests { let path = Path::new($path); let exp: Option<&str> = $exp; let exp = exp.map(|s| Path::new(s)); - assert!(make_non_verbatim(&path) == exp); + assert_eq!(make_non_verbatim(&path), exp); } ) } diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index 8855a7e5293..fc257b12bb6 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -303,7 +303,7 @@ impl<'a> SeedableRng<&'a [uint]> for StdRng { pub fn weak_rng() -> XorShiftRng { match OsRng::new() { Ok(mut r) => r.gen(), - Err(e) => panic!("weak_rng: failed to create seeded RNG: {}", e) + Err(e) => panic!("weak_rng: failed to create seeded RNG: {:?}", e) } } @@ -490,7 +490,7 @@ mod test { let mut r = thread_rng(); let a = r.gen::<f64>(); let b = r.gen::<f64>(); - debug!("{}", (a, b)); + debug!("{:?}", (a, b)); } #[test] diff --git a/src/libstd/rand/reader.rs b/src/libstd/rand/reader.rs index 48d7f2e7854..177b7380831 100644 --- a/src/libstd/rand/reader.rs +++ b/src/libstd/rand/reader.rs @@ -67,7 +67,7 @@ impl<R: Reader> Rng for ReaderRng<R> { if v.len() == 0 { return } match self.reader.read_at_least(v.len(), v) { Ok(_) => {} - Err(e) => panic!("ReaderRng.fill_bytes error: {}", e) + Err(e) => panic!("ReaderRng.fill_bytes error: {:?}", e) } } } diff --git a/src/libstd/sys/unix/backtrace.rs b/src/libstd/sys/unix/backtrace.rs index ca268a8f27f..7164931c55a 100644 --- a/src/libstd/sys/unix/backtrace.rs +++ b/src/libstd/sys/unix/backtrace.rs @@ -370,7 +370,7 @@ fn print(w: &mut Writer, idx: int, addr: *mut libc::c_void) -> IoResult<()> { // Finally, after all that work above, we can emit a symbol. fn output(w: &mut Writer, idx: int, addr: *mut libc::c_void, s: Option<&[u8]>) -> IoResult<()> { - try!(write!(w, " {:2}: {:2$} - ", idx, addr, HEX_WIDTH)); + try!(write!(w, " {:2}: {:2$?} - ", idx, addr, HEX_WIDTH)); match s.and_then(|s| str::from_utf8(s).ok()) { Some(string) => try!(demangle(w, string)), None => try!(write!(w, "<unknown>")), diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 1ad775517bb..c53f9d22790 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -381,7 +381,7 @@ mod tests { assert_eq!(buf[2], 's' as u8); assert_eq!(buf[3], 't' as u8); } - r => panic!("invalid read: {}", r), + r => panic!("invalid read: {:?}", r), } assert!(writer.read(&mut buf).is_err()); diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs index 5bc6b0c703b..1357bbdd5a3 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -125,7 +125,7 @@ impl Process { return match input.read(&mut bytes) { Ok(8) => { assert!(combine(CLOEXEC_MSG_FOOTER) == combine(bytes.slice(4, 8)), - "Validation on the CLOEXEC pipe failed: {}", bytes); + "Validation on the CLOEXEC pipe failed: {:?}", bytes); let errno = combine(bytes.slice(0, 4)); assert!(p.wait(0).is_ok(), "wait(0) should either return Ok or panic"); Err(super::decode_error(errno)) @@ -133,7 +133,7 @@ impl Process { Err(ref e) if e.kind == EndOfFile => Ok(p), Err(e) => { assert!(p.wait(0).is_ok(), "wait(0) should either return Ok or panic"); - panic!("the CLOEXEC pipe failed: {}", e) + panic!("the CLOEXEC pipe failed: {:?}", e) }, Ok(..) => { // pipe I/O up to PIPE_BUF bytes should be atomic assert!(p.wait(0).is_ok(), "wait(0) should either return Ok or panic"); @@ -285,7 +285,7 @@ impl Process { let mut status = 0 as c_int; if deadline == 0 { return match retry(|| unsafe { c::waitpid(self.pid, &mut status, 0) }) { - -1 => panic!("unknown waitpid error: {}", super::last_error()), + -1 => panic!("unknown waitpid error: {:?}", super::last_error()), _ => Ok(translate_status(status)), } } @@ -410,7 +410,7 @@ impl Process { continue } - n => panic!("error in select {} ({})", os::errno(), n), + n => panic!("error in select {:?} ({:?})", os::errno(), n), } // Process any pending messages @@ -491,7 +491,7 @@ impl Process { n if n > 0 => { ret = true; } 0 => return true, -1 if wouldblock() => return ret, - n => panic!("bad read {} ({})", os::last_os_error(), n), + n => panic!("bad read {:?} ({:?})", os::last_os_error(), n), } } } @@ -514,7 +514,7 @@ impl Process { } { 1 => {} -1 if wouldblock() => {} // see above comments - n => panic!("bad error on write fd: {} {}", n, os::errno()), + n => panic!("bad error on write fd: {:?} {:?}", n, os::errno()), } } } @@ -526,7 +526,7 @@ impl Process { }) { n if n == self.pid => Some(translate_status(status)), 0 => None, - n => panic!("unknown waitpid error `{}`: {}", n, + n => panic!("unknown waitpid error `{:?}`: {:?}", n, super::last_error()), } } diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index ac1f0c5d803..9bd6f78300e 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -48,7 +48,7 @@ macro_rules! try_opt { /// ISO 8601 time duration with nanosecond precision. /// This also allows for the negative duration; see individual methods for details. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Show)] pub struct Duration { secs: i64, nanos: i32, // Always 0 <= nanos < NANOS_PER_SEC @@ -337,7 +337,7 @@ impl Div<i32> for Duration { } } -impl fmt::Show for Duration { +impl fmt::String for Duration { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { // technically speaking, negative duration is not valid ISO 8601, // but we need to print it anyway. |
