From 520343e37d890e0a4b0c6e1427e8164c43ce1c7d Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 10 Nov 2024 12:57:26 -0800 Subject: [PATCH] Add test of Debug and Display of paths DisplayDebug currently works but DebugDisplay does not. error[E0277]: `PathBuf` doesn't implement `std::fmt::Display` --> tests/test_path.rs:36:13 | 32 | #[derive(Error, Debug)] | ----- in this derive macro expansion ... 36 | #[error("debug:{0:?} display:{0}")] | ^^^^^^^^^^^^^^^^^^^^^^^^^ `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 = help: the trait `std::fmt::Display` is implemented for `Var<'_, T>` = 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) --- tests/test_path.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_path.rs b/tests/test_path.rs index 16881ae..5bb6972 100644 --- a/tests/test_path.rs +++ b/tests/test_path.rs @@ -29,6 +29,14 @@ pub struct UnsizedError { pub tail: str, } +#[derive(Error, Debug)] +pub enum BothError { + #[error("display:{0} debug:{0:?}")] + DisplayDebug(PathBuf), + #[error("debug:{0:?} display:{0}")] + DebugDisplay(PathBuf), +} + fn assert(expected: &str, value: T) { assert_eq!(expected, value.to_string()); }