Skip to content

Commit

Permalink
Add regression test for issue 345
Browse files Browse the repository at this point in the history
    error[E0599]: `test_no_bound_on_named_fmt::Error<DebugOnly>` doesn't implement `std::fmt::Display`
       --> tests/test_generics.rs:173:22
        |
    168 |     struct Error<T> {
        |     --------------- method `to_string` not found for this struct because it doesn't satisfy `_: Display` or `_: ToString`
    ...
    173 |     assert_eq!(error.to_string(), "...");
        |                      ^^^^^^^^^ `test_no_bound_on_named_fmt::Error<DebugOnly>` cannot be formatted with the default formatter
        |
        = note: the following trait bounds were not satisfied:
                `test_no_bound_on_named_fmt::Error<DebugOnly>: std::fmt::Display`
                which is required by `test_no_bound_on_named_fmt::Error<DebugOnly>: ToString`
        = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
    note: the trait `std::fmt::Display` must be implemented
       --> $RUSTUP_HOME/toolchains/nightly-aarch64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:727:1
        |
    727 | pub trait Display {
        | ^^^^^^^^^^^^^^^^^
        = help: items from traits can only be used if the trait is implemented and in scope
        = note: the following trait defines an item `to_string`, perhaps you need to implement it:
                candidate #1: `ToString`
  • Loading branch information
dtolnay committed Nov 4, 2024
1 parent 6683511 commit 67faae4
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/test_generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,16 @@ pub struct StructFromGeneric<E> {
#[derive(Error, Debug)]
#[error(transparent)]
pub struct StructTransparentGeneric<E>(pub E);

// Regression test for https://github.com/dtolnay/thiserror/issues/345
#[test]
fn test_no_bound_on_named_fmt() {
#[derive(Error, Debug)]
#[error("{thing}", thing = "...")]
struct Error<T> {
thing: T,
}

let error = Error { thing: DebugOnly };
assert_eq!(error.to_string(), "...");
}

0 comments on commit 67faae4

Please sign in to comment.