Skip to content

Pushing an empty path to a verbatim path no longer adds a separator #89658

Closed
@dylni

Description

@dylni

Code

I tried this code:

use std::path::Path;

fn main() {
    let mut path = Path::new(r"C:\Users").to_owned();
    path.push("");
    assert_eq!(r"C:\Users\", path.as_os_str());

    path = Path::new(r"\\?\C:\Users").to_owned();
    path.push("");
    assert_eq!(r"\\?\C:\Users\", path.as_os_str());
}

I expected to see this happen: Both assertions succeed.

Instead, this happened: The second assertion fails, likely due to #89270:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `"\\\\?\\C:\\Users\\"`,
 right: `"\\\\?\\C:\\Users"`', src\main.rs:10:5

Although adding a separator when pushing an empty path is debatable, the behavior should probably be consistent for verbatim and non-verbatim paths.

This change caused normpath to break. I can add an inefficient workaround, but is this change intentional?

Version it worked on

It most recently worked on: 1.56.0-beta.4

Version with regression

rustc --version --verbose:

rustc 1.57.0-nightly (485ced56b 2021-10-07)
binary: rustc
commit-hash: 485ced56b8753ec86936903f2a8c95e9be8996a1
commit-date: 2021-10-07
host: x86_64-pc-windows-msvc
release: 1.57.0-nightly
LLVM version: 13.0.0

@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged +O-windows

cc @seanyoung

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.O-windowsOperating system: WindowsP-highHigh priorityT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions