Skip to content

Commit

Permalink
Add regression test for issue 405
Browse files Browse the repository at this point in the history
    error[E0599]: the method `as_display` exists for reference `&<T as FromStr>::Err`, but its trait bounds were not satisfied
       --> tests/test_generics.rs:178:13
        |
    178 |     #[error("couldn't parse entry: {0}")]
        |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^ method cannot be called on `&<T as FromStr>::Err` due to unsatisfied trait bounds
        |
        = note: the following trait bounds were not satisfied:
                `<T as FromStr>::Err: std::fmt::Display`
                which is required by `&<T as FromStr>::Err: AsDisplay<'_>`
  • Loading branch information
dtolnay committed Jan 8, 2025
1 parent c535cec commit 1368591
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/test_generics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(clippy::needless_late_init, clippy::uninlined_format_args)]

use core::fmt::{self, Debug, Display};
use core::str::FromStr;
use thiserror::Error;

pub struct NoFormat;
Expand Down Expand Up @@ -160,6 +161,24 @@ pub struct StructFromGeneric<E> {
#[error(transparent)]
pub struct StructTransparentGeneric<E>(pub E);

// Should expand to:
//
// impl<T: FromStr> Display for AssociatedTypeError<T>
// where
// T::Err: Display;
//
// impl<T: FromStr> Error for AssociatedTypeError<T>
// where
// Self: Debug + Display;
//
#[derive(Error, Debug)]
pub enum AssociatedTypeError<T: FromStr> {
#[error("couldn't parse matrix")]
Other,
#[error("couldn't parse entry: {0}")]
EntryParseError(T::Err),
}

// Regression test for https://github.com/dtolnay/thiserror/issues/345
#[test]
fn test_no_bound_on_named_fmt() {
Expand Down

0 comments on commit 1368591

Please sign in to comment.