Skip to content

Commit

Permalink
Do not abuse PathBuf::push("") for appending directory separator
Browse files Browse the repository at this point in the history
Since rust-lang/rust#89270 rust's pathbuf
push() normalizes the path if it is a verbatim path, so that the result
is still a valid verbatim path. This involves parsing reconstructing the
path.

Appending a path separator using push("") will no longer work, and if
it did, it would be very inefficient.

rust-lang/rust#89658

Signed-off-by: Sean Young <sean@mess.org>
  • Loading branch information
seanyoung committed Oct 8, 2021
1 parent 41be749 commit ad5555a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/windows/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ fn get_prefix(base: &BasePath) -> PrefixComponent<'_> {
}

fn push_separator(base: &mut BasePathBuf) {
base.replace_with(|mut base| {
// Add a separator if necessary.
base.push("");
base
});
// Add a separator if necessary.
let s = base.0.to_string_lossy();
if !s.ends_with('\\') && !s.ends_with(':') {
base.0.push(OsString::from(r"\"));
}
}

pub(super) fn push(base: &mut BasePathBuf, initial_path: &Path) {
Expand Down

0 comments on commit ad5555a

Please sign in to comment.