Skip to content

Commit c5dd32e

Browse files
committed
fix(rustdoc): match rustc --emit precedence
Change 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. See <#141664>
1 parent 43873db commit c5dd32e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,14 @@ fn main() {
3535
assert!(path("bla.d").exists());
3636

3737
// The last emit-type wins. The same behavior as rustc.
38-
// TODO: this shows the wrong behavior as a MRE, which will be fixed in the next commit
3938
rustdoc()
4039
.input("lib.rs")
4140
.arg("-Zunstable-options")
4241
.emit("dep-info=precedence1.d")
4342
.emit("dep-info=precedence2.d")
4443
.emit("dep-info=precedence3.d")
4544
.run();
46-
assert!(path("precedence1.d").exists());
45+
assert!(!path("precedence1.d").exists());
4746
assert!(!path("precedence2.d").exists());
48-
assert!(!path("precedence3.d").exists());
47+
assert!(path("precedence3.d").exists());
4948
}

0 commit comments

Comments
 (0)