From 43873db3b31b46280287d0797679f04d1407ddee Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Tue, 2 Sep 2025 18:30:16 -0400 Subject: [PATCH 1/2] test(rustdoc): show the wrong `--emit` precedence It should have the same behavior as rustc, which the last wins. --- tests/run-make/rustdoc-dep-info/rmake.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/run-make/rustdoc-dep-info/rmake.rs b/tests/run-make/rustdoc-dep-info/rmake.rs index 625f81fd428ef..956809909d92f 100644 --- a/tests/run-make/rustdoc-dep-info/rmake.rs +++ b/tests/run-make/rustdoc-dep-info/rmake.rs @@ -33,4 +33,17 @@ fn main() { // Now we check that we can provide a file name to the `dep-info` argument. rustdoc().input("lib.rs").arg("-Zunstable-options").emit("dep-info=bla.d").run(); assert!(path("bla.d").exists()); + + // The last emit-type wins. The same behavior as rustc. + // TODO: this shows the wrong behavior as a MRE, which will be fixed in the next commit + rustdoc() + .input("lib.rs") + .arg("-Zunstable-options") + .emit("dep-info=precedence1.d") + .emit("dep-info=precedence2.d") + .emit("dep-info=precedence3.d") + .run(); + assert!(path("precedence1.d").exists()); + assert!(!path("precedence2.d").exists()); + assert!(!path("precedence3.d").exists()); } From c5dd32e483593ab9751cfac50b907e4ce06f1249 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Tue, 2 Sep 2025 19:00:39 -0400 Subject: [PATCH 2/2] 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 --- src/librustdoc/config.rs | 11 +++++++++-- tests/run-make/rustdoc-dep-info/rmake.rs | 5 ++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 450ac04b40d91..1220a05e45853 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -454,15 +454,22 @@ impl Options { return None; } - let mut emit = Vec::new(); + let mut emit = FxIndexMap::<_, EmitType>::default(); for list in matches.opt_strs("emit") { for kind in list.split(',') { match kind.parse() { - Ok(kind) => emit.push(kind), + Ok(kind) => { + // De-duplicate emit types and the last wins. + // Only one instance for each type is allowed + // regardless the actual data it carries. + // This matches rustc's `--emit` behavior. + emit.insert(std::mem::discriminant(&kind), kind); + } Err(()) => dcx.fatal(format!("unrecognized emission type: {kind}")), } } } + let emit = emit.into_values().collect::>(); let show_coverage = matches.opt_present("show-coverage"); let output_format_s = matches.opt_str("output-format"); diff --git a/tests/run-make/rustdoc-dep-info/rmake.rs b/tests/run-make/rustdoc-dep-info/rmake.rs index 956809909d92f..166e8d5702fc3 100644 --- a/tests/run-make/rustdoc-dep-info/rmake.rs +++ b/tests/run-make/rustdoc-dep-info/rmake.rs @@ -35,7 +35,6 @@ fn main() { assert!(path("bla.d").exists()); // The last emit-type wins. The same behavior as rustc. - // TODO: this shows the wrong behavior as a MRE, which will be fixed in the next commit rustdoc() .input("lib.rs") .arg("-Zunstable-options") @@ -43,7 +42,7 @@ fn main() { .emit("dep-info=precedence2.d") .emit("dep-info=precedence3.d") .run(); - assert!(path("precedence1.d").exists()); + assert!(!path("precedence1.d").exists()); assert!(!path("precedence2.d").exists()); - assert!(!path("precedence3.d").exists()); + assert!(path("precedence3.d").exists()); }