Skip to content

Commit d2f49ee

Browse files
committed
Format doctest
1 parent aa853bd commit d2f49ee

File tree

1 file changed

+10
-45
lines changed

1 file changed

+10
-45
lines changed

library/std/src/error.rs

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,8 @@ impl dyn Error + Send + Sync {
811811
/// An error reporter that exposes the entire error chain for printing.
812812
/// It also exposes options for formatting the error chain, either entirely on a single line,
813813
/// or in multi-line format with each cause in the error chain on a new line.
814+
/// `Report` only requires that the wrapped error implements `Error`. It doesn't require that the
815+
/// wrapped error be `Send`, `Sync`, or `'static`.
814816
///
815817
/// # Examples
816818
///
@@ -822,68 +824,31 @@ impl dyn Error + Send + Sync {
822824
/// use std::fmt;
823825
///
824826
/// #[derive(Debug)]
825-
/// struct SuperError {
826-
/// side: SuperErrorSideKick,
827-
/// }
828-
///
829-
/// impl fmt::Display for SuperError {
830-
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
831-
/// write!(f, "SuperError is here!")
832-
/// }
833-
/// }
834-
///
835-
/// impl Error for SuperError {
836-
/// fn source(&self) -> Option<&(dyn Error + 'static)> {
837-
/// Some(&self.side)
838-
/// }
827+
/// struct SuperError<'a> {
828+
/// side: &'a str,
839829
/// }
840830
///
841-
/// #[derive(Debug)]
842-
/// struct SuperErrorSideKick;
843-
///
844-
/// impl fmt::Display for SuperErrorSideKick {
831+
/// impl<'a> fmt::Display for SuperError<'a> {
845832
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
846-
/// write!(f, "SuperErrorSideKick is here!")
833+
/// write!(f, "SuperError is here: {}", self.side)
847834
/// }
848835
/// }
849836
///
850-
/// impl Error for SuperErrorSideKick {}
837+
/// impl<'a> Error for SuperError<'a> {}
851838
///
852839
/// // Note that the error doesn't need to be `Send` or `Sync`.
853840
/// impl !Send for SuperError {}
854841
/// impl !Sync for SuperError {}
855842
///
856843
/// fn main() {
857-
/// let error = SuperError { side: SuperErrorSideKick };
844+
/// let msg = String::from("Huzzah!");
845+
/// let error = SuperError { side: &msg };
858846
/// let report = Report::new(&error).pretty(true);
859847
///
860848
/// println!("{}", report);
861849
/// }
862850
/// ```
863-
///
864-
/// `Report` only requires that the wrapped error implements `Error`. It doesn't require that the
865-
/// wrapped error be `Send`, `Sync`, or `'static`.
866-
///
867-
/// ```rust
868-
/// # #![feature(error_reporter)]
869-
/// # use std::fmt;
870-
/// # use std::error::{Error, Report};
871-
/// #[derive(Debug)]
872-
/// struct SuperError<'a> {
873-
/// side: &'a str,
874-
/// }
875-
/// impl<'a> fmt::Display for SuperError<'a> {
876-
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
877-
/// write!(f, "SuperError is here: {}", self.side)
878-
/// }
879-
/// }
880-
/// impl<'a> Error for SuperError<'a> {}
881-
/// fn main() {
882-
/// let msg = String::from("Huzzah!");
883-
/// let report = Report::new(SuperError { side: &msg });
884-
/// println!("{}", report);
885-
/// }
886-
/// ```
851+
887852
#[unstable(feature = "error_reporter", issue = "90172")]
888853
pub struct Report<E> {
889854
/// The error being reported.

0 commit comments

Comments
 (0)