Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utilizing Display on a Path could suggest calling display() #38997

Closed
jrmuizel opened this issue Jan 11, 2017 · 3 comments
Closed

Utilizing Display on a Path could suggest calling display() #38997

jrmuizel opened this issue Jan 11, 2017 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@jrmuizel
Copy link
Contributor

    let path = Path::new("/tmp/foo/bar.txt");
    println!("{}", path);

gives

  = note: `std::path::Path` cannot be formatted with the default formatter; try using `:?` instead if you are using a format string
  = note: required because of the requirements on the impl of `std::fmt::Display` for `&std::path::Path`
  = note: required by `std::fmt::Display::fmt`

It would be nice if rustc suggested calling display() on the path.

@GuillaumeGomez
Copy link
Member

Well, no. println! is trying to call the Display trait. It's up to the user to check the docs in such cases. At least, for me there is nothing wrong here.

@jrmuizel
Copy link
Contributor Author

The problem is that most people probably assume that paths are printable and are unaware that they require a lossy conversion to utf-8. Special casing some help to point users at the 'display()' method seems like a nice thing to do to compensate for having to explicitly call display() instead of just implementing Display on path directly.

@Mark-Simulacrum Mark-Simulacrum added the A-diagnostics Area: Messages for errors, warnings, and lints label May 19, 2017
@Mark-Simulacrum Mark-Simulacrum changed the title Error message when println! a path could be more helpful Utilizing Display on a Path could suggest calling display() May 19, 2017
@Mark-Simulacrum
Copy link
Member

I feel like we should deprecate display in favor of to_string_lossy on Path, really. The only difference I think is that display() is lazy. However, this specific issue is something that seems decent to solve, so keeping it.

@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 26, 2017
Centril added a commit to Centril/rust that referenced this issue Dec 16, 2018
Suggest using `.display()` when trying to print a `Path`

Fix rust-lang#38997.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

3 participants