diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index 069862efde640..54c9d1f6a8354 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -59,6 +59,8 @@ crate struct Context<'tcx> { pub(super) deref_id_map: RefCell>, /// The map used to ensure all generated 'id=' attributes are unique. pub(super) id_map: RefCell, + + pub(super) nixon_hack: RefCell>, /// Shared mutable state. /// /// Issue for improving the situation: [#82381][] @@ -72,8 +74,9 @@ crate struct Context<'tcx> { } // `Context` is cloned a lot, so we don't want the size to grow unexpectedly. -#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -rustc_data_structures::static_assert_size!(Context<'_>, 144); +// FIXME: Reenable before asking for review +// #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] +// rustc_data_structures::static_assert_size!(Context<'_>, 144); /// Shared mutable state used in [`Context`] and elsewhere. crate struct SharedContext<'tcx> { @@ -517,6 +520,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { render_redirect_pages: false, id_map: RefCell::new(id_map), deref_id_map: RefCell::new(FxHashMap::default()), + nixon_hack: RefCell::new(FxHashMap::default()), shared: Rc::new(scx), include_sources, }; @@ -541,6 +545,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { dst: self.dst.clone(), render_redirect_pages: self.render_redirect_pages, deref_id_map: RefCell::new(FxHashMap::default()), + nixon_hack: RefCell::new(FxHashMap::default()), id_map: RefCell::new(IdMap::new()), shared: Rc::clone(&self.shared), include_sources: self.include_sources, diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index ffd09663f8240..98bb340d1cbc3 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1613,6 +1613,8 @@ fn render_impl( ); write!(w, "") } + + write!(w, "{}:{} ", file!(), line!()); render_impl_summary( w, cx, @@ -1624,6 +1626,7 @@ fn render_impl( rendering_params.is_on_foreign_type, aliases, ); + write!(w, "{}:{} ", file!(), line!()); if toggled { write!(w, "") } @@ -1691,6 +1694,7 @@ pub(crate) fn render_impl_summary( // in documentation pages for trait with automatic implementations like "Send" and "Sync". aliases: &[String], ) { + // This is where the ID is created let id = cx.derive_id(match i.inner_impl().trait_ { Some(ref t) => { if is_on_foreign_type { @@ -1701,6 +1705,9 @@ pub(crate) fn render_impl_summary( } None => "impl".to_string(), }); + + cx.nixon_hack.borrow_mut().insert(i.impl_item.def_id, id.clone()); + let aliases = if aliases.is_empty() { String::new() } else { @@ -2215,6 +2222,7 @@ fn get_id_for_impl_on_foreign_type( } fn extract_for_impl_name(item: &clean::Item, cx: &Context<'_>) -> Option<(String, String)> { + // match *item.kind { clean::ItemKind::ImplItem(ref i) => { i.trait_.as_ref().map(|trait_| { @@ -2306,6 +2314,7 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean .filter(|i| { i.inner_impl().for_.def_id(cache).map_or(false, |d| !cache.paths.contains_key(&d)) }) + // FIXME: Dont do the filter map dance .filter_map(|i| extract_for_impl_name(&i.impl_item, cx)) .collect::>(); @@ -2325,7 +2334,45 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean sidebar_assoc_items(cx, buf, it); - buf.push_str("

Implementors

"); + let did = it.def_id.expect_def_id(); + + if let Some(implementors) = cache.implementors.get(&did) { + let mut res = implementors + .iter() + .filter(|i| { + i.inner_impl().for_.def_id(cache).map_or(true, |d| cache.paths.contains_key(&d)) + && i.inner_impl().polarity == ty::ImplPolarity::Positive + }) + // FIXME: Dont do the filter map dance + // .filter_map(|i| extract_for_impl_name(&i.impl_item, cx)) + .map(|i| { + ( + format!("{:#}", i.inner_impl().for_.print(cx)), + cx.nixon_hack + .borrow() + .get(&i.impl_item.def_id) + .unwrap_or_else(|| panic!("Not in index {:#?}", i)) + .clone(), + ) + }) + .collect::>(); + + if !res.is_empty() { + res.sort_unstable(); + + buf.push_str( + "

\ + Implementors\ +

+
", + ); + for (name, id) in res.into_iter() { + write!(buf, "{}", id, Escape(&name)); + } + buf.push_str("
"); + } + } + if t.is_auto { buf.push_str( "

, it: &clean::Item, t: &clean::Tra "Implementors", "
", ); + + write!(w, "", file!(), line!()); + for implementor in concrete { render_implementor(cx, implementor, it, w, &implementor_dups, &[]); }