From c7f1b977ed807d987da0350133b1443fd2caa21f Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Wed, 12 Dec 2018 16:54:27 -0800 Subject: Suggest using `.display()` when trying to print a `Path` --- src/test/ui/suggestions/path-display.rs | 7 +++++++ src/test/ui/suggestions/path-display.stderr | 14 ++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/test/ui/suggestions/path-display.rs create mode 100644 src/test/ui/suggestions/path-display.stderr (limited to 'src/test/ui/suggestions') diff --git a/src/test/ui/suggestions/path-display.rs b/src/test/ui/suggestions/path-display.rs new file mode 100644 index 00000000000..62fc9e79f7a --- /dev/null +++ b/src/test/ui/suggestions/path-display.rs @@ -0,0 +1,7 @@ +use std::path::Path; + +fn main() { + let path = Path::new("/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 new file mode 100644 index 00000000000..b0493a559f9 --- /dev/null +++ b/src/test/ui/suggestions/path-display.stderr @@ -0,0 +1,14 @@ +error[E0277]: `std::path::Path` doesn't implement `std::fmt::Display` + --> $DIR/path-display.rs:5:20 + | +LL | println!("{}", path); + | ^^^^ `std::path::Path` cannot be formatted with the default formatter, call `.display()` on it + | + = help: the trait `std::fmt::Display` is not implemented for `std::path::Path` + = note: you need to call `.display()` or `.to_string_lossy()` for safely printing paths as they may contain non-Unicode data + = note: required because of the requirements on the impl of `std::fmt::Display` for `&std::path::Path` + = note: required by `std::fmt::Display::fmt` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. -- cgit 1.4.1-3-g733a5 From 33a34b06ac8828ffddc91b822fdec9f862658600 Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Thu, 13 Dec 2018 09:55:16 -0800 Subject: Wording changes --- src/libcore/fmt/mod.rs | 6 +++--- src/test/ui/suggestions/path-display.stderr | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/test/ui/suggestions') diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index de936515698..8e0caa5ae33 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -611,9 +611,9 @@ pub trait Debug { #[rustc_on_unimplemented( on( _Self="std::path::Path", - label="`{Self}` cannot be formatted with the default formatter, call `.display()` on it", - note="you need to call `.display()` or `.to_string_lossy()` for safely printing paths as \ - they may contain non-Unicode data" + 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" ), message="`{Self}` doesn't implement `{Display}`", label="`{Self}` cannot be formatted with the default formatter", diff --git a/src/test/ui/suggestions/path-display.stderr b/src/test/ui/suggestions/path-display.stderr index b0493a559f9..39d236af4f3 100644 --- a/src/test/ui/suggestions/path-display.stderr +++ b/src/test/ui/suggestions/path-display.stderr @@ -2,10 +2,10 @@ error[E0277]: `std::path::Path` doesn't implement `std::fmt::Display` --> $DIR/path-display.rs:5:20 | LL | println!("{}", path); - | ^^^^ `std::path::Path` cannot be formatted with the default formatter, call `.display()` on it + | ^^^^ `std::path::Path` cannot be formatted with the default formatter; call `.display()` on it | = help: the trait `std::fmt::Display` is not implemented for `std::path::Path` - = note: you need to call `.display()` or `.to_string_lossy()` for safely printing paths as they may contain non-Unicode data + = note: call `.display()` or `.to_string_lossy()` to safely print paths, as they may contain non-Unicode data = note: required because of the requirements on the impl of `std::fmt::Display` for `&std::path::Path` = note: required by `std::fmt::Display::fmt` -- cgit 1.4.1-3-g733a5