rustdoc: fix --emit=dep-info on scraped examples by notriddle · Pull Request #148268 · rust-lang/rust (original) (raw)

Lacking any other resource to work with, I checked Cargo's dep info parser and the GNU Make docs. Both of these seem to imply that backslashes are fine, as long as they don't immediately precede a special character (like another backslash, a newline, or an asterisk):

https://doc.rust-lang.org/1.91.0/nightly-rustc/src/cargo/core/compiler/fingerprint/dep_info.rs.html#401-418

    } else if let Some(pos) = line.find(": ") {
        if found_deps {
            continue;
        }
        found_deps = true;
        let mut deps = line[pos + 2..].split_whitespace();

        while let Some(s) = deps.next() {
            let mut file = s.to_string();
            while file.ends_with('\\') {
                file.pop();
                file.push(' ');
                file.push_str(deps.next().ok_or_else(|| {
                    crate::util::internal("malformed dep-info format, trailing \\")
                })?);
            }
            ret.files.entry(file.into()).or_default();
        }

https://www.gnu.org/software/make/manual/make.html#Wildcard-Pitfall

Microsoft operating systems (MS-DOS and MS-Windows) use backslashes to separate directories in pathnames, like so:

This is equivalent to the Unix-style c:/foo/bar/baz.c (the c: part is the so-called drive letter). When make runs on these systems, it supports backslashes as well as the Unix-style forward slashes in pathnames.