Skip to content

Commit 40f99d5

Browse files
brsonclaude
andcommitted
Fix type display names, cross-crate re-export links, and derive macro paths
Three fixes for broken links in generated API docs: 1. Strip internal module paths from type signatures - use only the last segment of path.path (e.g., "JoinHandle" not "super::join_handle::JoinHandle"). Fixes 328 pages. 2. Update global index to redirect canonical (definition) path lookups to re-export locations. Prefers shorter re-export paths to avoid prelude locations. Fixes cross-crate links like FnOnce pointing to core/ops/function/ instead of core/ops/. 3. Add ProcDerive/ProcAttribute handling to all kind-prefix mappings (types.rs, mod.rs, output.rs) so derive macro pages are written as derive.Clone.html and links match. Fixes 82 pages with broken derive macro links. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent da2f59d commit 40f99d5

5 files changed

Lines changed: 48 additions & 4 deletions

File tree

crates/rustmax-rustdoc/src/lib.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,35 @@ impl RustDocSet {
327327
};
328328

329329
// Only insert if not already present (prefer canonical paths).
330-
index.items.entry(path_str).or_insert_with(|| ItemLocation {
331-
crate_name: target_crate,
332-
path: target_path,
330+
index.items.entry(path_str.clone()).or_insert_with(|| ItemLocation {
331+
crate_name: target_crate.clone(),
332+
path: target_path.clone(),
333333
kind,
334334
});
335+
336+
// For local re-exports, also update the canonical (definition)
337+
// path entry to point to the re-export location. This ensures
338+
// cross-crate lookups by definition path (e.g.,
339+
// "core::ops::function::FnOnce") resolve to the public re-export
340+
// location (e.g., "core::ops::FnOnce" → core/ops/trait.FnOnce.html).
341+
// Prefer shorter re-export paths to avoid prelude re-exports.
342+
if path_info.crate_id == 0 {
343+
let canonical_path_str = path_info.path.join("::");
344+
if canonical_path_str != path_str {
345+
let new_loc = ItemLocation {
346+
crate_name: target_crate,
347+
path: target_path,
348+
kind,
349+
};
350+
index.items.entry(canonical_path_str)
351+
.and_modify(|existing| {
352+
if new_loc.path.len() < existing.path.len() {
353+
*existing = new_loc.clone();
354+
}
355+
})
356+
.or_insert(new_loc);
357+
}
358+
}
335359
}
336360
}
337361
}

crates/rustmax-rustdoc/src/output.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ fn build_reexport_html_path(path: &[String], inner: &ItemEnum) -> PathBuf {
120120
ItemEnum::Constant { .. } => Some(ItemKind::Constant),
121121
ItemEnum::Static(_) => Some(ItemKind::Static),
122122
ItemEnum::Macro(_) => Some(ItemKind::Macro),
123+
ItemEnum::ProcMacro(pm) => Some(match pm.kind {
124+
rustdoc_types::MacroKind::Derive => ItemKind::ProcDerive,
125+
rustdoc_types::MacroKind::Attr => ItemKind::ProcAttribute,
126+
rustdoc_types::MacroKind::Bang => ItemKind::Macro,
127+
}),
123128
ItemEnum::Union(_) => Some(ItemKind::Union),
124129
_ => None,
125130
};
@@ -133,6 +138,8 @@ fn build_reexport_html_path(path: &[String], inner: &ItemEnum) -> PathBuf {
133138
Some(ItemKind::Constant) => "constant.",
134139
Some(ItemKind::Static) => "static.",
135140
Some(ItemKind::Macro) => "macro.",
141+
Some(ItemKind::ProcDerive) => "derive.",
142+
Some(ItemKind::ProcAttribute) => "attr.",
136143
Some(ItemKind::Union) => "union.",
137144
_ => "",
138145
};

crates/rustmax-rustdoc/src/render/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ impl<'a> RenderContext<'a> {
135135
ItemKind::Constant => "constant.",
136136
ItemKind::Static => "static.",
137137
ItemKind::Macro => "macro.",
138+
ItemKind::ProcDerive => "derive.",
139+
ItemKind::ProcAttribute => "attr.",
138140
ItemKind::Module => "",
139141
_ => return None, // Don't link to other kinds.
140142
};

crates/rustmax-rustdoc/src/render/signature.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,11 @@ impl<'a, 'ctx> LinkedRenderer<'a, 'ctx> {
467467
}
468468

469469
fn render_resolved_path(&self, path: &Path) -> String {
470-
let name = html_escape(&path.path);
470+
// Use only the last segment as the display name. Rustdoc JSON
471+
// stores source-level paths like "super::join_handle::JoinHandle"
472+
// but we want to show just "JoinHandle".
473+
let simple_name = path.path.rsplit("::").next().unwrap_or(&path.path);
474+
let name = html_escape(simple_name);
471475
let args = path.args.as_ref()
472476
.map(|a| self.render_generic_args(a))
473477
.unwrap_or_default();

crates/rustmax-rustdoc/src/types.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ fn path_to_html(path: &[String], kind: Option<ItemKind>) -> PathBuf {
208208
Some(ItemKind::Static) => "static.",
209209
Some(ItemKind::Macro) => "macro.",
210210
Some(ItemKind::Union) => "union.",
211+
Some(ItemKind::ProcDerive) => "derive.",
212+
Some(ItemKind::ProcAttribute) => "attr.",
211213
_ => "",
212214
};
213215

@@ -240,6 +242,11 @@ fn item_kind(inner: &ItemEnum) -> Option<ItemKind> {
240242
ItemEnum::Constant { .. } => Some(ItemKind::Constant),
241243
ItemEnum::Static(_) => Some(ItemKind::Static),
242244
ItemEnum::Macro(_) => Some(ItemKind::Macro),
245+
ItemEnum::ProcMacro(pm) => Some(match pm.kind {
246+
rustdoc_types::MacroKind::Derive => ItemKind::ProcDerive,
247+
rustdoc_types::MacroKind::Attr => ItemKind::ProcAttribute,
248+
rustdoc_types::MacroKind::Bang => ItemKind::Macro,
249+
}),
243250
ItemEnum::Union(_) => Some(ItemKind::Union),
244251
_ => None,
245252
}

0 commit comments

Comments
 (0)