]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #21558 - alexcrichton:result-debug, r=aturon
authorbors <bors@rust-lang.org>
Sun, 25 Jan 2015 05:50:30 +0000 (05:50 +0000)
committerbors <bors@rust-lang.org>
Sun, 25 Jan 2015 05:50:30 +0000 (05:50 +0000)
This commit relaxes the bound on `Result::unwrap` and `Result::unwrap_err` from
the `Display` trait to the `Debug` trait for generating an error message about
the unwrapping operation.

This commit is a breaking change and any breakage should be mitigated by
ensuring that `Debug` is implemented on the relevant type.

[breaking-change]

1  2 
src/libcore/result.rs

diff --combined src/libcore/result.rs
index 4ea3bf8e5bddd334942fa513c10315fd3385b7ef,118f29ccfa4dfa47fe19b7cb6c07a494eb230edf..ab0f447f6c93d79869227022440f5433b0d75ad3
  use self::Result::{Ok, Err};
  
  use clone::Clone;
- use fmt::Display;
+ use fmt::Debug;
  use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator, ExactSizeIterator};
  use ops::{FnMut, FnOnce};
  use option::Option::{self, None, Some};
@@@ -482,8 -482,8 +482,8 @@@ impl<T, E> Result<T, E> 
      /// ```
      /// fn stringify(x: uint) -> String { format!("error code: {}", x) }
      ///
 -    /// let x: Result<uint, uint> = Ok(2u);
 -    /// assert_eq!(x.map_err(stringify), Ok(2u));
 +    /// let x: Result<uint, uint> = Ok(2);
 +    /// assert_eq!(x.map_err(stringify), Ok(2));
      ///
      /// let x: Result<uint, uint> = Err(13);
      /// assert_eq!(x.map_err(stringify), Err("error code: 13".to_string()));
      /// ```
      /// let x: Result<uint, &str> = Ok(5);
      /// let v: Vec<uint> = x.into_iter().collect();
 -    /// assert_eq!(v, vec![5u]);
 +    /// assert_eq!(v, vec![5]);
      ///
      /// let x: Result<uint, &str> = Err("nothing!");
      /// let v: Vec<uint> = x.into_iter().collect();
      /// # Example
      ///
      /// ```
 -    /// let optb = 2u;
 -    /// let x: Result<uint, &str> = Ok(9u);
 -    /// assert_eq!(x.unwrap_or(optb), 9u);
 +    /// let optb = 2;
 +    /// let x: Result<uint, &str> = Ok(9);
 +    /// assert_eq!(x.unwrap_or(optb), 9);
      ///
      /// let x: Result<uint, &str> = Err("error");
      /// assert_eq!(x.unwrap_or(optb), optb);
      /// ```
      /// fn count(x: &str) -> uint { x.len() }
      ///
 -    /// assert_eq!(Ok(2u).unwrap_or_else(count), 2u);
 -    /// assert_eq!(Err("foo").unwrap_or_else(count), 3u);
 +    /// assert_eq!(Ok(2).unwrap_or_else(count), 2);
 +    /// assert_eq!(Err("foo").unwrap_or_else(count), 3);
      /// ```
      #[inline]
      #[stable]
  }
  
  #[stable]
- impl<T, E: Display> Result<T, E> {
+ impl<T, E: Debug> Result<T, E> {
      /// Unwraps a result, yielding the content of an `Ok`.
      ///
      /// # Panics
      /// # Example
      ///
      /// ```
 -    /// let x: Result<uint, &str> = Ok(2u);
 -    /// assert_eq!(x.unwrap(), 2u);
 +    /// let x: Result<uint, &str> = Ok(2);
 +    /// assert_eq!(x.unwrap(), 2);
      /// ```
      ///
      /// ```{.should_fail}
          match self {
              Ok(t) => t,
              Err(e) =>
-                 panic!("called `Result::unwrap()` on an `Err` value: {}", e)
+                 panic!("called `Result::unwrap()` on an `Err` value: {:?}", e)
          }
      }
  }
  
  #[stable]
- impl<T: Display, E> Result<T, E> {
+ impl<T: Debug, E> Result<T, E> {
      /// Unwraps a result, yielding the content of an `Err`.
      ///
      /// # Panics
      /// # Example
      ///
      /// ```{.should_fail}
 -    /// let x: Result<uint, &str> = Ok(2u);
 +    /// let x: Result<uint, &str> = Ok(2);
      /// x.unwrap_err(); // panics with `2`
      /// ```
      ///
      pub fn unwrap_err(self) -> E {
          match self {
              Ok(t) =>
-                 panic!("called `Result::unwrap_err()` on an `Ok` value: {}", t),
+                 panic!("called `Result::unwrap_err()` on an `Ok` value: {:?}", t),
              Err(e) => e
          }
      }
@@@ -897,12 -897,12 +897,12 @@@ impl<A, E, V: FromIterator<A>> FromIter
      /// ```rust
      /// use std::uint;
      ///
 -    /// let v = vec!(1u, 2u);
 +    /// let v = vec!(1, 2);
      /// let res: Result<Vec<uint>, &'static str> = v.iter().map(|&x: &uint|
      ///     if x == uint::MAX { Err("Overflow!") }
      ///     else { Ok(x + 1) }
      /// ).collect();
 -    /// assert!(res == Ok(vec!(2u, 3u)));
 +    /// assert!(res == Ok(vec!(2, 3)));
      /// ```
      #[inline]
      fn from_iter<I: Iterator<Item=Result<A, E>>>(iter: I) -> Result<V, E> {