Skip to content

Commit f762204

Browse files
jyn514Joshua Nelson
authored andcommitted
Use -Z rustdoc-map instead of rewriting it
1 parent ed329f5 commit f762204

File tree

3 files changed

+9
-36
lines changed

3 files changed

+9
-36
lines changed

crates/metadata/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ impl Metadata {
229229
/// For example, the links may point somewhere different than they would on docs.rs.
230230
/// However, rustdoc will see exactly the same code as it would on docs.rs, even counting `cfg`s.
231231
pub fn cargo_args(&self, additional_args: &[String], rustdoc_args: &[String]) -> Vec<String> {
232-
let mut cargo_args: Vec<String> = vec!["rustdoc".into(), "--lib".into()];
232+
let mut cargo_args: Vec<String> =
233+
vec!["rustdoc".into(), "--lib".into(), "-Zrustdoc-map".into()];
233234

234235
if let Some(features) = &self.features {
235236
cargo_args.push("--features".into());

src/docbuilder/rustwide_builder.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -518,16 +518,6 @@ impl RustwideBuilder {
518518

519519
let mut rustdoc_flags = Vec::new();
520520

521-
for dep in &cargo_metadata.root_dependencies() {
522-
rustdoc_flags.push("--extern-html-root-url".to_string());
523-
rustdoc_flags.push(format!(
524-
"{}=https://docs.rs/{}/{}",
525-
dep.name.replace("-", "_"),
526-
dep.name,
527-
dep.version
528-
));
529-
}
530-
531521
rustdoc_flags.extend(vec![
532522
"--resource-suffix".to_string(),
533523
format!("-{}", parse_rustc_version(&self.rustc_version)?),

src/utils/cargo_metadata.rs

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
use crate::error::Result;
22
use rustwide::{cmd::Command, Toolchain, Workspace};
33
use serde::{Deserialize, Serialize};
4-
use std::collections::{HashMap, HashSet};
4+
use std::collections::HashMap;
55
use std::path::Path;
66

77
pub(crate) struct CargoMetadata {
8-
packages: HashMap<String, Package>,
9-
deps_graph: HashMap<String, HashSet<String>>,
10-
root_id: String,
8+
root: Package,
119
}
1210

1311
impl CargoMetadata {
@@ -31,34 +29,18 @@ impl CargoMetadata {
3129
));
3230
};
3331

34-
// Convert from Vecs to HashMaps and HashSets to get more efficient lookups
32+
let root = metadata.resolve.root;
3533
Ok(CargoMetadata {
36-
packages: metadata
34+
root: metadata
3735
.packages
3836
.into_iter()
39-
.map(|pkg| (pkg.id.clone(), pkg))
40-
.collect(),
41-
deps_graph: metadata
42-
.resolve
43-
.nodes
44-
.into_iter()
45-
.map(|node| (node.id, node.deps.into_iter().map(|d| d.pkg).collect()))
46-
.collect(),
47-
root_id: metadata.resolve.root,
37+
.find(|pkg| pkg.id == root)
38+
.unwrap(),
4839
})
4940
}
5041

51-
pub(crate) fn root_dependencies(&self) -> Vec<&Package> {
52-
let ids = &self.deps_graph[&self.root_id];
53-
self.packages
54-
.iter()
55-
.filter(|(id, _pkg)| ids.contains(id.as_str()))
56-
.map(|(_id, pkg)| pkg)
57-
.collect()
58-
}
59-
6042
pub(crate) fn root(&self) -> &Package {
61-
&self.packages[&self.root_id]
43+
&self.root
6244
}
6345
}
6446

0 commit comments

Comments
 (0)