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

Implement Display for Path and PathBuf #49868

Closed
wants to merge 3 commits into from

Commits on Apr 11, 2018

  1. Deprecate Path::display, implement Display for Path

    In [RFC rust-lang#474][rfc474], the issue of how to handle Displaying a
    Path was left as an open question. The problem is that a Path
    may contain non-UTF-8 data on most platforms. In the
    implementation of the RFC, a `display` method was added, which
    returns an adapter that implements `Display` by replacing
    non-UTF8 data with a unicode replacement character.
    
    Though I can't find a record of the discussion around this
    issue, I believe there were two primary reasons not to just
    implement this behavior as the `Display` impl of `Path`:
    
    1. The adapter allocated in the non-UTF8 case, and Rust as a
       rule tries to avoid allocations that are not explicit in code.
    2. The user may prefer an alternative solution than using the
       unicode replacement character for handling non-UTF8 data.
    
    In my view, the choice to provide an adapter rather than
    implement Display has had a high cost in terms of user experience:
    
    * I almost never remember that I need an adapter, forcing me to
      go back and edit my code after compiling it and getting an error.
    * It makes my code more noisy to have the display adapter; this
      detail is rarely important.
    * It is extremely uncommon to actually do something other than call
      the display adapter when trying to display a path (I have never
      wanted anything else myself).
    * For new users, it is Yet Another Compiler Error that they have to
      figure out how to solve, contributing to the sense that Rust nags
      nags and obstructs rather than assists & guides.
    
    Therefore, I think time has shown that this has been a detriment to
    user experience, rather than a helpful reminder. That leaves only
    the first reason not to implement this: implicit allocations. That
    problem was happily resolved in June 2017: rust-lang#42613 provided an
    alternative implementation which efficiently avoids allocations.
    
    Given that, I think it is time that we implement `Display` for both
    `Path` and `PathBuf` and deprecate the `Path::display` method.
    
    r? @alexcrichton
    cc @rust-lang/libs
    
    [rfc474]: https://github.com/rust-lang/rfcs/blob/master/text/0474-path-reform.md)
    boats committed Apr 11, 2018
    Configuration menu
    Copy the full SHA
    07e61cd View commit details
    Browse the repository at this point in the history
  2. Remove deprecation.

    boats committed Apr 11, 2018
    Configuration menu
    Copy the full SHA
    a204487 View commit details
    Browse the repository at this point in the history
  3. Correct feature name.

    boats committed Apr 11, 2018
    Configuration menu
    Copy the full SHA
    980c5ec View commit details
    Browse the repository at this point in the history