Skip to content

Commit c3c417b

Browse files
committed
Auto merge of #13544 - weihanglo:issue-13543, r=epage
fix(rustdoc-map): dedup `--extern-html-too-url` for same unit
2 parents ab1c0e5 + ac750a1 commit c3c417b

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/cargo/core/compiler/rustdoc.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::sources::CRATES_IO_REGISTRY;
77
use crate::util::errors::{internal, CargoResult};
88
use cargo_util::ProcessBuilder;
99
use std::collections::HashMap;
10+
use std::collections::HashSet;
1011
use std::fmt;
1112
use std::hash;
1213
use url::Url;
@@ -113,8 +114,12 @@ fn build_all_urls(
113114
name2url: &HashMap<&String, Url>,
114115
map: &RustdocExternMap,
115116
unstable_opts: &mut bool,
117+
seen: &mut HashSet<Unit>,
116118
) {
117119
for dep in build_runner.unit_deps(unit) {
120+
if !seen.insert(dep.unit.clone()) {
121+
continue;
122+
}
118123
if !dep.unit.target.is_linkable() || dep.unit.mode.is_doc() {
119124
continue;
120125
}
@@ -155,6 +160,7 @@ fn build_all_urls(
155160
name2url,
156161
map,
157162
unstable_opts,
163+
seen,
158164
);
159165
}
160166
}
@@ -199,6 +205,7 @@ pub fn add_root_urls(
199205
&name2url,
200206
map,
201207
&mut unstable_opts,
208+
&mut HashSet::new(),
202209
);
203210
let std_url = match &map.std {
204211
None | Some(RustdocExternMode::Remote) => None,

tests/testsuite/rustdoc_extern_html.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,3 +416,50 @@ fn alt_sparse_registry() {
416416
let gold = p.read_file("target/doc/foo/fn.gold.html");
417417
assert!(gold.contains(r#"href="https://docs.rs/grimm/1.0.0/grimm/struct.Gold.html""#));
418418
}
419+
420+
#[cargo_test(nightly, reason = "--extern-html-root-url is unstable")]
421+
fn same_deps_multi_occurrence_in_dep_tree() {
422+
// rust-lang/cargo#13543
423+
Package::new("baz", "1.0.0")
424+
.file("src/lib.rs", "")
425+
.publish();
426+
Package::new("bar", "1.0.0")
427+
.file("src/lib.rs", "")
428+
.dep("baz", "1.0")
429+
.publish();
430+
431+
let p = project()
432+
.file(
433+
"Cargo.toml",
434+
r#"
435+
[package]
436+
name = "foo"
437+
edition = "2018"
438+
439+
[dependencies]
440+
bar = "1.0"
441+
baz = "1.0"
442+
"#,
443+
)
444+
.file("src/lib.rs", "")
445+
.file(
446+
".cargo/config.toml",
447+
r#"
448+
[doc.extern-map.registries]
449+
crates-io = "https://docs.rs/"
450+
"#,
451+
)
452+
.build();
453+
p.cargo("doc -v --no-deps -Zrustdoc-map")
454+
.masquerade_as_nightly_cargo(&["rustdoc-map"])
455+
.with_stderr_does_not_contain(
456+
"[..]--extern-html-root-url[..]bar=https://docs.rs\
457+
[..]--extern-html-root-url[..]baz=https://docs.rs\
458+
[..]--extern-html-root-url[..]baz=https://docs.rs[..]",
459+
)
460+
.with_stderr_contains(
461+
"[..]--extern-html-root-url[..]bar=https://docs.rs\
462+
[..]--extern-html-root-url[..]baz=https://docs.rs[..]",
463+
)
464+
.run();
465+
}

0 commit comments

Comments
 (0)