rustdoc: Add more semantic information to impl ids
Instead of generating `#impl`, `#impl-1`, etc., generate IDs like `#impl-Foo<M>`. Co-authored-by: Noah Lev <camelidcamel@gmail.com>
This commit is contained in:
parent
54f79babae
commit
499e024ac9
18 changed files with 49 additions and 68 deletions
|
@ -634,7 +634,6 @@ fn render_impls(
|
|||
&[],
|
||||
ImplRenderingParameters {
|
||||
show_def_docs: true,
|
||||
is_on_foreign_type: false,
|
||||
show_default_items: true,
|
||||
show_non_assoc_items: true,
|
||||
toggle_open_by_default,
|
||||
|
@ -1071,7 +1070,6 @@ fn render_assoc_items_inner(
|
|||
&[],
|
||||
ImplRenderingParameters {
|
||||
show_def_docs: true,
|
||||
is_on_foreign_type: false,
|
||||
show_default_items: true,
|
||||
show_non_assoc_items: true,
|
||||
toggle_open_by_default: true,
|
||||
|
@ -1287,7 +1285,6 @@ fn notable_traits_decl(decl: &clean::FnDecl, cx: &Context<'_>) -> String {
|
|||
#[derive(Clone, Copy, Debug)]
|
||||
struct ImplRenderingParameters {
|
||||
show_def_docs: bool,
|
||||
is_on_foreign_type: bool,
|
||||
show_default_items: bool,
|
||||
/// Whether or not to show methods.
|
||||
show_non_assoc_items: bool,
|
||||
|
@ -1603,7 +1600,6 @@ fn render_impl(
|
|||
parent,
|
||||
rendering_params.show_def_docs,
|
||||
use_absolute,
|
||||
rendering_params.is_on_foreign_type,
|
||||
aliases,
|
||||
);
|
||||
if toggled {
|
||||
|
@ -1688,21 +1684,12 @@ pub(crate) fn render_impl_summary(
|
|||
containing_item: &clean::Item,
|
||||
show_def_docs: bool,
|
||||
use_absolute: Option<bool>,
|
||||
is_on_foreign_type: bool,
|
||||
// This argument is used to reference same type with different paths to avoid duplication
|
||||
// in documentation pages for trait with automatic implementations like "Send" and "Sync".
|
||||
aliases: &[String],
|
||||
) {
|
||||
let id = cx.derive_id(match i.inner_impl().trait_ {
|
||||
Some(ref t) => {
|
||||
if is_on_foreign_type {
|
||||
get_id_for_impl_on_foreign_type(&i.inner_impl().for_, t, cx)
|
||||
} else {
|
||||
format!("impl-{}", small_url_encode(format!("{:#}", t.print(cx))))
|
||||
}
|
||||
}
|
||||
None => "impl".to_string(),
|
||||
});
|
||||
let id =
|
||||
cx.derive_id(get_id_for_impl(&i.inner_impl().for_, i.inner_impl().trait_.as_ref(), cx));
|
||||
let aliases = if aliases.is_empty() {
|
||||
String::new()
|
||||
} else {
|
||||
|
@ -2147,12 +2134,11 @@ fn sidebar_struct(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, s: &clea
|
|||
}
|
||||
}
|
||||
|
||||
fn get_id_for_impl_on_foreign_type(
|
||||
for_: &clean::Type,
|
||||
trait_: &clean::Path,
|
||||
cx: &Context<'_>,
|
||||
) -> String {
|
||||
small_url_encode(format!("impl-{:#}-for-{:#}", trait_.print(cx), for_.print(cx)))
|
||||
fn get_id_for_impl(for_: &clean::Type, trait_: Option<&clean::Path>, cx: &Context<'_>) -> String {
|
||||
match trait_ {
|
||||
Some(t) => small_url_encode(format!("impl-{:#}-for-{:#}", t.print(cx), for_.print(cx))),
|
||||
None => small_url_encode(format!("impl-{:#}", for_.print(cx))),
|
||||
}
|
||||
}
|
||||
|
||||
fn extract_for_impl_name(item: &clean::Item, cx: &Context<'_>) -> Option<(String, String)> {
|
||||
|
@ -2161,10 +2147,7 @@ fn extract_for_impl_name(item: &clean::Item, cx: &Context<'_>) -> Option<(String
|
|||
i.trait_.as_ref().map(|trait_| {
|
||||
// Alternative format produces no URLs,
|
||||
// so this parameter does nothing.
|
||||
(
|
||||
format!("{:#}", i.for_.print(cx)),
|
||||
get_id_for_impl_on_foreign_type(&i.for_, trait_, cx),
|
||||
)
|
||||
(format!("{:#}", i.for_.print(cx)), get_id_for_impl(&i.for_, Some(trait_), cx))
|
||||
})
|
||||
}
|
||||
_ => None,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue