From e3429d72bdc8bd9aede206ff3056f1c785a7f451 Mon Sep 17 00:00:00 2001 From: Nixon Enraght-Moony Date: Mon, 22 Nov 2021 01:27:44 +0000 Subject: [PATCH 1/3] Hackity Hack hack https://user-images.githubusercontent.com/28781354/142788007-c5e2130c-c5bb-4351-a4aa-a38fa6697b7b.png Needs alot of work --- src/librustdoc/html/render/context.rs | 9 +++-- src/librustdoc/html/render/mod.rs | 44 +++++++++++++++++++++++- src/librustdoc/html/render/print_item.rs | 3 ++ 3 files changed, 53 insertions(+), 3 deletions(-) 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..68d097274b03a 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1531,6 +1531,8 @@ fn render_impl( let mut impl_items = Buffer::empty_from(w); let mut default_impl_items = Buffer::empty_from(w); + // FFFFXXX + for trait_item in &i.inner_impl().items { doc_impl_item( &mut default_impl_items, @@ -1613,6 +1615,8 @@ fn render_impl( ); write!(w, "") } + + write!(w, "{}:{} ", file!(), line!()); render_impl_summary( w, cx, @@ -1624,6 +1628,7 @@ fn render_impl( rendering_params.is_on_foreign_type, aliases, ); + write!(w, "{}:{} ", file!(), line!()); if toggled { write!(w, "") } @@ -1691,6 +1696,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 +1707,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 +2224,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 +2316,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)) }) + // TODO: Dont do the filter map dance .filter_map(|i| extract_for_impl_name(&i.impl_item, cx)) .collect::>(); @@ -2325,7 +2336,38 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean sidebar_assoc_items(cx, buf, it); - buf.push_str("

Implementors

"); + if let Some(implementors) = cache.implementors.get(&it.def_id.expect_def_id()) { + let mut res = implementors + .iter() + .filter(|i| { + i.inner_impl().for_.def_id(cache).map_or(true, |d| cache.paths.contains_key(&d)) + }) + // TODO: 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().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, &[]); } From 386e5cd2c4c0e5f367ec100f4d544b718a8b8058 Mon Sep 17 00:00:00 2001 From: Nixon Enraght-Moony Date: Fri, 26 Nov 2021 17:42:17 +0000 Subject: [PATCH 2/3] Filter out negitive impls --- src/librustdoc/html/render/mod.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 68d097274b03a..48e70709fef2a 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1531,8 +1531,6 @@ fn render_impl( let mut impl_items = Buffer::empty_from(w); let mut default_impl_items = Buffer::empty_from(w); - // FFFFXXX - for trait_item in &i.inner_impl().items { doc_impl_item( &mut default_impl_items, @@ -2336,18 +2334,25 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean sidebar_assoc_items(cx, buf, it); - if let Some(implementors) = cache.implementors.get(&it.def_id.expect_def_id()) { + 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 }) // TODO: 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().clone(), + cx.nixon_hack + .borrow() + .get(&i.impl_item.def_id) + .unwrap_or_else(|| panic!("Not in index {:#?}", i)) + .clone(), ) }) .collect::>(); From 817766a6d48d70e5677ba3651a8f568ec2890f01 Mon Sep 17 00:00:00 2001 From: Nixon Enraght-Moony Date: Fri, 26 Nov 2021 18:37:28 +0000 Subject: [PATCH 3/3] TODO -> FIXME --- src/librustdoc/html/render/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 48e70709fef2a..98bb340d1cbc3 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -2314,7 +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)) }) - // TODO: Dont do the filter map dance + // FIXME: Dont do the filter map dance .filter_map(|i| extract_for_impl_name(&i.impl_item, cx)) .collect::>(); @@ -2343,7 +2343,7 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean i.inner_impl().for_.def_id(cache).map_or(true, |d| cache.paths.contains_key(&d)) && i.inner_impl().polarity == ty::ImplPolarity::Positive }) - // TODO: Dont do the filter map dance + // FIXME: Dont do the filter map dance // .filter_map(|i| extract_for_impl_name(&i.impl_item, cx)) .map(|i| { (