Skip to content

Commit ad5555a

Browse files
committed
Do not abuse PathBuf::push("") for appending directory separator
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 <[email protected]>
1 parent 41be749 commit ad5555a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/windows/normalize.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ fn get_prefix(base: &BasePath) -> PrefixComponent<'_> {
143143
}
144144

145145
fn push_separator(base: &mut BasePathBuf) {
146-
base.replace_with(|mut base| {
147-
// Add a separator if necessary.
148-
base.push("");
149-
base
150-
});
146+
// Add a separator if necessary.
147+
let s = base.0.to_string_lossy();
148+
if !s.ends_with('\\') && !s.ends_with(':') {
149+
base.0.push(OsString::from(r"\"));
150+
}
151151
}
152152

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

0 commit comments

Comments
 (0)