about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--library/core/src/fmt/mod.rs2
-rw-r--r--src/test/ui/suggestions/path-display.rs6
-rw-r--r--src/test/ui/suggestions/path-display.stderr12
3 files changed, 17 insertions, 3 deletions
diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs
index e1ea9881303..90c5719f486 100644
--- a/library/core/src/fmt/mod.rs
+++ b/library/core/src/fmt/mod.rs
@@ -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"
diff --git a/src/test/ui/suggestions/path-display.rs b/src/test/ui/suggestions/path-display.rs
index 62fc9e79f7a..3a022e6b02f 100644
--- a/src/test/ui/suggestions/path-display.rs
+++ b/src/test/ui/suggestions/path-display.rs
@@ -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
 }
diff --git a/src/test/ui/suggestions/path-display.stderr b/src/test/ui/suggestions/path-display.stderr
index 25c73c4c874..5e718d79307 100644
--- a/src/test/ui/suggestions/path-display.stderr
+++ b/src/test/ui/suggestions/path-display.stderr
@@ -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`.