Add regression test for issue 335

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)
This commit is contained in:
David Tolnay 2024-11-02 09:39:37 -07:00
parent 751dc63a8e
commit 561e29eb80
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82

View file

@ -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
@ -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("..."),
},
);
}