From 181c7262f4cd6296c9ca6a1ed93fb69b5ce29642 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Wed, 8 Mar 2023 10:13:11 +0800 Subject: [PATCH] Respect request_kind --- src/cargo/ops/cargo_doc.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_doc.rs b/src/cargo/ops/cargo_doc.rs index 22f1e0514d91..168d78c2eff5 100644 --- a/src/cargo/ops/cargo_doc.rs +++ b/src/cargo/ops/cargo_doc.rs @@ -20,9 +20,19 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> { let compilation = ops::compile(ws, &options.compile_opts)?; if options.open_result { + // The open behavior is as follows: + // cargo doc --open: + // - Pick the first root unit that was built for host. + // - If none found, pick the first one(whatever it's target is). + // cargo doc --target TARGET --open: + // - Pick the first root unit for the given target. + // - If none found, pick the first one(whatever it's target is). + let request_kind = options.compile_opts.build_config.single_requested_kind()?; let (name, kind) = &compilation .root_crate_names - .get(0) + .iter() + .find(|(_, kind)| *kind == request_kind) + .or_else(|| compilation.root_crate_names.get(0)) .ok_or_else(|| anyhow::anyhow!("no crates with documentation"))?; let path = compilation.root_output[&kind]