Skip to content

Commit

Permalink
Suggest calling .display() on PathBuf too
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Feb 22, 2022
1 parent 03a8cc7 commit a08809f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion library/core/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ pub use macros::Debug;
/// ```
#[rustc_on_unimplemented(
on(
_Self = "std::path::Path",
any(_Self = "std::path::Path", _Self = "std::path::PathBuf"),
label = "`{Self}` cannot be formatted with the default formatter; call `.display()` on it",
note = "call `.display()` or `.to_string_lossy()` to safely print paths, \
as they may contain non-Unicode data"
Expand Down
6 changes: 5 additions & 1 deletion src/test/ui/suggestions/path-display.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use std::path::Path;
use std::path::{Path, PathBuf};

fn main() {
let path = Path::new("/tmp/foo/bar.txt");
println!("{}", path);
//~^ ERROR E0277

let path = PathBuf::from("/tmp/foo/bar.txt");
println!("{}", path);
//~^ ERROR E0277
}
12 changes: 11 additions & 1 deletion src/test/ui/suggestions/path-display.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ LL | println!("{}", path);
= 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_nl` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error
error[E0277]: `PathBuf` doesn't implement `std::fmt::Display`
--> $DIR/path-display.rs:9:20
|
LL | println!("{}", path);
| ^^^^ `PathBuf` cannot be formatted with the default formatter; call `.display()` on it
|
= help: the trait `std::fmt::Display` is not implemented for `PathBuf`
= 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_nl` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.

0 comments on commit a08809f

Please sign in to comment.