Skip to content

--emit KIND=PATH cannot handle paths containing commas #159743

Description

@weihanglo

I tried this code:

#!/usr/bin/env bash
set -eu

rustc=$(rustup which rustc)
rustdoc=$(rustup which rustdoc)
tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT
out="$tmp/with,comma"; mkdir "$out"
echo '' > "$tmp/lib.rs"

check() {  # $1=label; rest=command
  echo "### $1"; shift
  "$@" 2>&1 | sed 's/^/    /'
  echo
}

"$rustc" --version; echo
check "rustc" \
  "$rustc" --crate-name t --crate-type lib --out-dir "$out" \
  --emit=dep-info="$out/t.d" "$tmp/lib.rs"

check "rustdoc" \
  "$rustdoc" --crate-name t -o "$out" \
  --emit=html-non-static-files,dep-info="$out/t.d" "$tmp/lib.rs"

I expected to see this happen:

rustc 1.99.0-nightly (9f36de775 2026-07-19)

### rustc

### rustdoc

(all three invocations succeed and write dep-info file to the path under with,comma/)

Instead, this happened:

rustc 1.99.0-nightly (9f36de775 2026-07-19)

### rustc: single kind
    error: unknown emission type: `comma/t.d` - expected one of: `asm`, `llvm-bc`, `dep-info`, `link`, `llvm-ir`, `metadata`, `mir`, `obj`, `thin-link-bitcode`

### rustdoc
    error: unrecognized emission type: comma/t.d

Both rustc and rustdoc split the entire --emit value on commas before recognizing the KIND=PATH form,
so everything after a comma inside PATH is misparsed as another emission type.

There is no escape mechanism btw.
Isolating a single KIND=PATH in its own --emit also doesn't help.

Meta

rustc --version --verbose:

rustc 1.99.0-nightly (9f36de775 2026-07-19)
binary: rustc
commit-hash: 9f36de775bc636c8e88c31a173c2bcb6995956a0
commit-date: 2026-07-19
host: aarch64-apple-darwin
release: 1.99.0-nightly
LLVM version: 22.1.8

How this was discovered

While stabilizing -Zrustdoc-depinfo,
Cargo started passing --emit=html-static-files,html-non-static-files,dep-info=<path> to rustdoc,
where <path> is an absolute path under the target directory.
If there is a comma in the target-dir path,
cargo doc would fail with unrecognized emission type.

Thanks @0xPoe for catching that in rust-lang/cargo#17020 (comment)!

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-CLIArea: Command-line interface (CLI) to the compilerC-bugCategory: This is a bug.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions