Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate trait bounds on associated types #408

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add regression test for issue 405
    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
commit 136859154b88758e33a5cbe57d7bd70f1d31615f
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