Skip to content

Commit

Permalink
Add regression test for issue 335
Browse files Browse the repository at this point in the history
    error[E0277]: `PathBuf` doesn't implement `std::fmt::Display`
       --> tests/test_expr.rs:105:14
        |
    104 |     #[derive(Error, Debug)]
        |              ----- in this derive macro expansion
    105 |     #[error("{A} {b}", b = &0 as &dyn Trait<i32, A = i32>)]
        |              ^^^ `PathBuf` cannot be formatted with the default formatter; call `.display()` on it
        |
        = help: the trait `std::fmt::Display` is not implemented for `PathBuf`
        = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
        = note: call `.display()` or `.to_string_lossy()` to safely print paths, as they may contain non-Unicode data
        = note: this error originates in the macro `$crate::format_args` which comes from the expansion of the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info)
  • Loading branch information
dtolnay committed Nov 2, 2024
1 parent 751dc63 commit 561e29e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/test_expr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(clippy::iter_cloned_collect, clippy::uninlined_format_args)]

use core::fmt::Display;
use std::path::PathBuf;
use thiserror::Error;

// Some of the elaborate cases from the rcc codebase, which is a C compiler in
Expand Down Expand Up @@ -87,3 +88,29 @@ fn test_rustup() {
},
);
}

// Regression test for https://github.com/dtolnay/thiserror/issues/335
#[test]
#[allow(non_snake_case)]
fn test_assoc_type_equality_constraint() {
pub trait Trait<T>: Display {
type A;
}

impl<T> Trait<T> for i32 {
type A = i32;
}

#[derive(Error, Debug)]
#[error("{A} {b}", b = &0 as &dyn Trait<i32, A = i32>)]
pub struct Error {
pub A: PathBuf,
}

assert(
"... 0",
Error {
A: PathBuf::from("..."),
},
);
}

0 comments on commit 561e29e

Please sign in to comment.