#17540·cargo

Invalid backslash escaping in dependency file

Author: jethrogbCreated Sep 30, 2026Updated Oct 1, 2026
LabelsC-bugS-needs-designA-dep-info

Problem

The Makefile-style dependency file generated by cargo doesn't escape backslashes in filenames properly.

Create the following source tree in an empty cargo project:

src/main.rs

rust
include!("a\\ b.rs"); // file name: `a\ b.rs` (backslash, then a space)
include!("c\\"); // file name: `c\` (ends in a backslash)
include!("d.rs");

fn main() {
    println!("{}", A + C + D);
}

src/a\ b.rs

rust
const A: u8 = 1;

src/d.rs

rust
const D: u8 = 3;

src/c\

rust
const C: u8 = 2;

This generates a .d file as follows:

.../target/debug/depinfo-repro: .../src/a\\ b.rs .../src/c\ src/d.rs .../src/main.rs

make parses this as a file named a, another file named b.rs, and another file named c src/d.rs. Perhaps there are two separate bugs, because I think a full path should've been printed for d.rs.

The correct escaping (as interpreted by make) is that every backslash and space in a filename should be escaped with a backslash. This way the escaping is unambiguous.

Steps

No response

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.98.1 (797e8a9bc 2026-08-05)