]> git.lizzy.rs Git - rust.git/commitdiff
Suggest calling .display() on PathBuf too
authorMichael Goulet <michael@errs.io>
Tue, 22 Feb 2022 00:58:12 +0000 (16:58 -0800)
committerMichael Goulet <michael@errs.io>
Tue, 22 Feb 2022 00:58:12 +0000 (16:58 -0800)
library/core/src/fmt/mod.rs
src/test/ui/suggestions/path-display.rs
src/test/ui/suggestions/path-display.stderr

index e1ea98813031aac5b15b675c995e7eb32756f3ac..90c5719f486cb7674f9cd3c7ec5f5fe5a01ed378 100644 (file)
@@ -728,7 +728,7 @@ pub(crate) mod macros {
 /// ```
 #[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"
index 62fc9e79f7aa23537de36ec3ec1be43bb973f4ca..3a022e6b02fa4d648124f69478ad7d7d09bd79d5 100644 (file)
@@ -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
 }
index 25c73c4c8741af5b8ddf32949e18601f80e50bc0..5e718d79307a81f3e63678fe486fd27a40d4d5c2 100644 (file)
@@ -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`.