Skip to content

Commit 181c726

Browse files
committed
Respect request_kind
1 parent 1adb8c1 commit 181c726

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/cargo/ops/cargo_doc.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,19 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> {
2020
let compilation = ops::compile(ws, &options.compile_opts)?;
2121

2222
if options.open_result {
23+
// The open behavior is as follows:
24+
// cargo doc --open:
25+
// - Pick the first root unit that was built for host.
26+
// - If none found, pick the first one(whatever it's target is).
27+
// cargo doc --target TARGET --open:
28+
// - Pick the first root unit for the given target.
29+
// - If none found, pick the first one(whatever it's target is).
30+
let request_kind = options.compile_opts.build_config.single_requested_kind()?;
2331
let (name, kind) = &compilation
2432
.root_crate_names
25-
.get(0)
33+
.iter()
34+
.find(|(_, kind)| *kind == request_kind)
35+
.or_else(|| compilation.root_crate_names.get(0))
2636
.ok_or_else(|| anyhow::anyhow!("no crates with documentation"))?;
2737

2838
let path = compilation.root_output[&kind]

0 commit comments

Comments
 (0)