Skip to content

Commit 40afbdd

Browse files
authored
Rollup merge of #94240 - compiler-errors:pathbuf-display, r=lcnr
Suggest calling .display() on `PathBuf` too Fixes #94210
2 parents 14ac74d + a08809f commit 40afbdd

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

library/core/src/fmt/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ pub use macros::Debug;
728728
/// ```
729729
#[rustc_on_unimplemented(
730730
on(
731-
_Self = "std::path::Path",
731+
any(_Self = "std::path::Path", _Self = "std::path::PathBuf"),
732732
label = "`{Self}` cannot be formatted with the default formatter; call `.display()` on it",
733733
note = "call `.display()` or `.to_string_lossy()` to safely print paths, \
734734
as they may contain non-Unicode data"
+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
use std::path::Path;
1+
use std::path::{Path, PathBuf};
22

33
fn main() {
44
let path = Path::new("/tmp/foo/bar.txt");
55
println!("{}", path);
66
//~^ ERROR E0277
7+
8+
let path = PathBuf::from("/tmp/foo/bar.txt");
9+
println!("{}", path);
10+
//~^ ERROR E0277
711
}

src/test/ui/suggestions/path-display.stderr

+11-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ LL | println!("{}", path);
88
= note: call `.display()` or `.to_string_lossy()` to safely print paths, as they may contain non-Unicode data
99
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
1010

11-
error: aborting due to previous error
11+
error[E0277]: `PathBuf` doesn't implement `std::fmt::Display`
12+
--> $DIR/path-display.rs:9:20
13+
|
14+
LL | println!("{}", path);
15+
| ^^^^ `PathBuf` cannot be formatted with the default formatter; call `.display()` on it
16+
|
17+
= help: the trait `std::fmt::Display` is not implemented for `PathBuf`
18+
= note: call `.display()` or `.to_string_lossy()` to safely print paths, as they may contain non-Unicode data
19+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
20+
21+
error: aborting due to 2 previous errors
1222

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

0 commit comments

Comments
 (0)