diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
commit | 218caa410aa38c29984be31a5229b9fa717560ee (patch) | |
tree | c54bd55eeb6e4c508940a30e94c0032fbd45d677 /vendor/thiserror/tests | |
parent | Releasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/thiserror/tests')
-rw-r--r-- | vendor/thiserror/tests/test_display.rs | 31 | ||||
-rw-r--r-- | vendor/thiserror/tests/ui/no-display.stderr | 30 | ||||
-rw-r--r-- | vendor/thiserror/tests/ui/source-enum-not-error.stderr | 2 | ||||
-rw-r--r-- | vendor/thiserror/tests/ui/source-struct-not-error.stderr | 38 |
4 files changed, 65 insertions, 36 deletions
diff --git a/vendor/thiserror/tests/test_display.rs b/vendor/thiserror/tests/test_display.rs index 8917bb054..99ce2fded 100644 --- a/vendor/thiserror/tests/test_display.rs +++ b/vendor/thiserror/tests/test_display.rs @@ -1,4 +1,4 @@ -use std::fmt::Display; +use std::fmt::{self, Display}; use thiserror::Error; fn assert<T: Display>(expected: &str, value: T) { @@ -142,6 +142,35 @@ fn test_match() { } #[test] +fn test_nested_display() { + // Same behavior as the one in `test_match`, but without String allocations. + #[derive(Error, Debug)] + #[error("{}", { + struct Msg<'a>(&'a String, &'a Option<usize>); + impl<'a> Display for Msg<'a> { + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + match self.1 { + Some(n) => write!(formatter, "error occurred with {}", n), + None => write!(formatter, "there was an empty error"), + }?; + write!(formatter, ": {}", self.0) + } + } + Msg(.0, .1) + })] + struct Error(String, Option<usize>); + + assert( + "error occurred with 1: ...", + Error("...".to_owned(), Some(1)), + ); + assert( + "there was an empty error: ...", + Error("...".to_owned(), None), + ); +} + +#[test] fn test_void() { #[allow(clippy::empty_enum)] #[derive(Error, Debug)] diff --git a/vendor/thiserror/tests/ui/no-display.stderr b/vendor/thiserror/tests/ui/no-display.stderr index 82c3eea1c..76818e1e5 100644 --- a/vendor/thiserror/tests/ui/no-display.stderr +++ b/vendor/thiserror/tests/ui/no-display.stderr @@ -1,17 +1,17 @@ error[E0599]: the method `as_display` exists for reference `&NoDisplay`, but its trait bounds were not satisfied - --> tests/ui/no-display.rs:7:9 - | -4 | struct NoDisplay; - | ---------------- doesn't satisfy `NoDisplay: std::fmt::Display` + --> tests/ui/no-display.rs:7:9 + | +4 | struct NoDisplay; + | ---------------- doesn't satisfy `NoDisplay: std::fmt::Display` ... -7 | #[error("thread: {thread}")] - | ^^^^^^^^^^^^^^^^^^ method cannot be called on `&NoDisplay` due to unsatisfied trait bounds - | - = note: the following trait bounds were not satisfied: - `NoDisplay: std::fmt::Display` - which is required by `&NoDisplay: DisplayAsDisplay` -note: the following trait must be implemented - --> $RUST/core/src/fmt/mod.rs - | - | pub trait Display { - | ^^^^^^^^^^^^^^^^^ +7 | #[error("thread: {thread}")] + | ^^^^^^^^^^^^^^^^^^ method cannot be called on `&NoDisplay` due to unsatisfied trait bounds + | + = note: the following trait bounds were not satisfied: + `NoDisplay: std::fmt::Display` + which is required by `&NoDisplay: DisplayAsDisplay` +note: the trait `std::fmt::Display` must be implemented + --> $RUST/core/src/fmt/mod.rs + | + | pub trait Display { + | ^^^^^^^^^^^^^^^^^ diff --git a/vendor/thiserror/tests/ui/source-enum-not-error.stderr b/vendor/thiserror/tests/ui/source-enum-not-error.stderr index 29ee54600..750c69eb3 100644 --- a/vendor/thiserror/tests/ui/source-enum-not-error.stderr +++ b/vendor/thiserror/tests/ui/source-enum-not-error.stderr @@ -15,7 +15,7 @@ error[E0599]: the method `as_dyn_error` exists for reference `&NotError`, but it which is required by `NotError: AsDynError<'_>` `&NotError: std::error::Error` which is required by `&NotError: AsDynError<'_>` -note: the following trait must be implemented +note: the trait `std::error::Error` must be implemented --> $RUST/core/src/error.rs | | pub trait Error: Debug + Display { diff --git a/vendor/thiserror/tests/ui/source-struct-not-error.stderr b/vendor/thiserror/tests/ui/source-struct-not-error.stderr index efa40281d..b98460fcb 100644 --- a/vendor/thiserror/tests/ui/source-struct-not-error.stderr +++ b/vendor/thiserror/tests/ui/source-struct-not-error.stderr @@ -1,21 +1,21 @@ error[E0599]: the method `as_dyn_error` exists for struct `NotError`, but its trait bounds were not satisfied - --> tests/ui/source-struct-not-error.rs:9:5 - | -4 | struct NotError; - | --------------- - | | - | method `as_dyn_error` not found for this struct - | doesn't satisfy `NotError: AsDynError<'_>` - | doesn't satisfy `NotError: std::error::Error` + --> tests/ui/source-struct-not-error.rs:9:5 + | +4 | struct NotError; + | --------------- + | | + | method `as_dyn_error` not found for this struct + | doesn't satisfy `NotError: AsDynError<'_>` + | doesn't satisfy `NotError: std::error::Error` ... -9 | source: NotError, - | ^^^^^^ method cannot be called on `NotError` due to unsatisfied trait bounds - | - = note: the following trait bounds were not satisfied: - `NotError: std::error::Error` - which is required by `NotError: AsDynError<'_>` -note: the following trait must be implemented - --> $RUST/core/src/error.rs - | - | pub trait Error: Debug + Display { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +9 | source: NotError, + | ^^^^^^ method cannot be called on `NotError` due to unsatisfied trait bounds + | + = note: the following trait bounds were not satisfied: + `NotError: std::error::Error` + which is required by `NotError: AsDynError<'_>` +note: the trait `std::error::Error` must be implemented + --> $RUST/core/src/error.rs + | + | pub trait Error: Debug + Display { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |