Skip to content

Commit e3429d7

Browse files
committed
1 parent 65f3f8b commit e3429d7

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

src/librustdoc/html/render/context.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ crate struct Context<'tcx> {
5959
pub(super) deref_id_map: RefCell<FxHashMap<DefId, String>>,
6060
/// The map used to ensure all generated 'id=' attributes are unique.
6161
pub(super) id_map: RefCell<IdMap>,
62+
63+
pub(super) nixon_hack: RefCell<FxHashMap<clean::ItemId, String>>,
6264
/// Shared mutable state.
6365
///
6466
/// Issue for improving the situation: [#82381][]
@@ -72,8 +74,9 @@ crate struct Context<'tcx> {
7274
}
7375

7476
// `Context` is cloned a lot, so we don't want the size to grow unexpectedly.
75-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
76-
rustc_data_structures::static_assert_size!(Context<'_>, 144);
77+
// FIXME: Reenable before asking for review
78+
// #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
79+
// rustc_data_structures::static_assert_size!(Context<'_>, 144);
7780

7881
/// Shared mutable state used in [`Context`] and elsewhere.
7982
crate struct SharedContext<'tcx> {
@@ -517,6 +520,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
517520
render_redirect_pages: false,
518521
id_map: RefCell::new(id_map),
519522
deref_id_map: RefCell::new(FxHashMap::default()),
523+
nixon_hack: RefCell::new(FxHashMap::default()),
520524
shared: Rc::new(scx),
521525
include_sources,
522526
};
@@ -541,6 +545,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
541545
dst: self.dst.clone(),
542546
render_redirect_pages: self.render_redirect_pages,
543547
deref_id_map: RefCell::new(FxHashMap::default()),
548+
nixon_hack: RefCell::new(FxHashMap::default()),
544549
id_map: RefCell::new(IdMap::new()),
545550
shared: Rc::clone(&self.shared),
546551
include_sources: self.include_sources,

src/librustdoc/html/render/mod.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,8 @@ fn render_impl(
15311531
let mut impl_items = Buffer::empty_from(w);
15321532
let mut default_impl_items = Buffer::empty_from(w);
15331533

1534+
// FFFFXXX
1535+
15341536
for trait_item in &i.inner_impl().items {
15351537
doc_impl_item(
15361538
&mut default_impl_items,
@@ -1613,6 +1615,8 @@ fn render_impl(
16131615
);
16141616
write!(w, "<summary>")
16151617
}
1618+
1619+
write!(w, "{}:{} ", file!(), line!());
16161620
render_impl_summary(
16171621
w,
16181622
cx,
@@ -1624,6 +1628,7 @@ fn render_impl(
16241628
rendering_params.is_on_foreign_type,
16251629
aliases,
16261630
);
1631+
write!(w, "{}:{} ", file!(), line!());
16271632
if toggled {
16281633
write!(w, "</summary>")
16291634
}
@@ -1691,6 +1696,7 @@ pub(crate) fn render_impl_summary(
16911696
// in documentation pages for trait with automatic implementations like "Send" and "Sync".
16921697
aliases: &[String],
16931698
) {
1699+
// This is where the ID is created
16941700
let id = cx.derive_id(match i.inner_impl().trait_ {
16951701
Some(ref t) => {
16961702
if is_on_foreign_type {
@@ -1701,6 +1707,9 @@ pub(crate) fn render_impl_summary(
17011707
}
17021708
None => "impl".to_string(),
17031709
});
1710+
1711+
cx.nixon_hack.borrow_mut().insert(i.impl_item.def_id, id.clone());
1712+
17041713
let aliases = if aliases.is_empty() {
17051714
String::new()
17061715
} else {
@@ -2215,6 +2224,7 @@ fn get_id_for_impl_on_foreign_type(
22152224
}
22162225

22172226
fn extract_for_impl_name(item: &clean::Item, cx: &Context<'_>) -> Option<(String, String)> {
2227+
//
22182228
match *item.kind {
22192229
clean::ItemKind::ImplItem(ref i) => {
22202230
i.trait_.as_ref().map(|trait_| {
@@ -2306,6 +2316,7 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
23062316
.filter(|i| {
23072317
i.inner_impl().for_.def_id(cache).map_or(false, |d| !cache.paths.contains_key(&d))
23082318
})
2319+
// TODO: Dont do the filter map dance
23092320
.filter_map(|i| extract_for_impl_name(&i.impl_item, cx))
23102321
.collect::<Vec<_>>();
23112322

@@ -2325,7 +2336,38 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
23252336

23262337
sidebar_assoc_items(cx, buf, it);
23272338

2328-
buf.push_str("<h3 class=\"sidebar-title\"><a href=\"#implementors\">Implementors</a></h3>");
2339+
if let Some(implementors) = cache.implementors.get(&it.def_id.expect_def_id()) {
2340+
let mut res = implementors
2341+
.iter()
2342+
.filter(|i| {
2343+
i.inner_impl().for_.def_id(cache).map_or(true, |d| cache.paths.contains_key(&d))
2344+
})
2345+
// TODO: Dont do the filter map dance
2346+
// .filter_map(|i| extract_for_impl_name(&i.impl_item, cx))
2347+
.map(|i| {
2348+
(
2349+
format!("{:#}", i.inner_impl().for_.print(cx)),
2350+
cx.nixon_hack.borrow().get(&i.impl_item.def_id).unwrap().clone(),
2351+
)
2352+
})
2353+
.collect::<Vec<_>>();
2354+
2355+
if !res.is_empty() {
2356+
res.sort_unstable();
2357+
2358+
buf.push_str(
2359+
"<h3 class=\"sidebar-title\">\
2360+
<a href=\"#implementors\">Implementors</a>\
2361+
</h3>
2362+
<div class=\"sidebar-links\">",
2363+
);
2364+
for (name, id) in res.into_iter() {
2365+
write!(buf, "<a href=\"#{}\">{}</a>", id, Escape(&name));
2366+
}
2367+
buf.push_str("</div>");
2368+
}
2369+
}
2370+
23292371
if t.is_auto {
23302372
buf.push_str(
23312373
"<h3 class=\"sidebar-title\"><a \

src/librustdoc/html/render/print_item.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,9 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
784784
"Implementors",
785785
"<div class=\"item-list\" id=\"implementors-list\">",
786786
);
787+
788+
write!(w, "<!-- {}:{} -->", file!(), line!());
789+
787790
for implementor in concrete {
788791
render_implementor(cx, implementor, it, w, &implementor_dups, &[]);
789792
}

0 commit comments

Comments
 (0)