Skip to content

Commit 3a6a3aa

Browse files
authored
Unrolled build for #146150
Rollup merge of #146150 - weihanglo:rustdoc-emit, r=aDotInTheVoid fix(rustdoc): match rustc `--emit` precedence Resolves #141664 This changes rustdoc's `--emit` to allow only one instance of each type, regardless of the actual data that `--emit` carries. This matches rustc's `--emit` behavior. As of the writing, only `dep-info` emit type carries extra data.
2 parents 9385c64 + c5dd32e commit 3a6a3aa

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/librustdoc/config.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,15 +454,22 @@ impl Options {
454454
return None;
455455
}
456456

457-
let mut emit = Vec::new();
457+
let mut emit = FxIndexMap::<_, EmitType>::default();
458458
for list in matches.opt_strs("emit") {
459459
for kind in list.split(',') {
460460
match kind.parse() {
461-
Ok(kind) => emit.push(kind),
461+
Ok(kind) => {
462+
// De-duplicate emit types and the last wins.
463+
// Only one instance for each type is allowed
464+
// regardless the actual data it carries.
465+
// This matches rustc's `--emit` behavior.
466+
emit.insert(std::mem::discriminant(&kind), kind);
467+
}
462468
Err(()) => dcx.fatal(format!("unrecognized emission type: {kind}")),
463469
}
464470
}
465471
}
472+
let emit = emit.into_values().collect::<Vec<_>>();
466473

467474
let show_coverage = matches.opt_present("show-coverage");
468475
let output_format_s = matches.opt_str("output-format");

tests/run-make/rustdoc-dep-info/rmake.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,16 @@ fn main() {
3333
// Now we check that we can provide a file name to the `dep-info` argument.
3434
rustdoc().input("lib.rs").arg("-Zunstable-options").emit("dep-info=bla.d").run();
3535
assert!(path("bla.d").exists());
36+
37+
// The last emit-type wins. The same behavior as rustc.
38+
rustdoc()
39+
.input("lib.rs")
40+
.arg("-Zunstable-options")
41+
.emit("dep-info=precedence1.d")
42+
.emit("dep-info=precedence2.d")
43+
.emit("dep-info=precedence3.d")
44+
.run();
45+
assert!(!path("precedence1.d").exists());
46+
assert!(!path("precedence2.d").exists());
47+
assert!(path("precedence3.d").exists());
3648
}

0 commit comments

Comments
 (0)