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

Support Display and Debug of same path in error message #383

Merged
merged 3 commits into from
Nov 10, 2024
Merged

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Nov 10, 2024

Previously, for an error containing a Path or PathBuf, #[error("display:{0} debug:{0:?}")] would work but #[error("debug:{0:?} display:{0}")] would not compile.

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)

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)
@dtolnay dtolnay merged commit a061beb into master Nov 10, 2024
20 checks passed
@dtolnay dtolnay deleted the both branch November 10, 2024 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant