Skip to content

Commit d1e594f

Browse files
committed
Auto merge of #68192 - GuillaumeGomez:remove-inlined-types, r=kinnison
Remove usage of global variable "inlined_types" r? @pietroalbini
2 parents ae66171 + 871e82b commit d1e594f

File tree

3 files changed

+56
-25
lines changed

3 files changed

+56
-25
lines changed

src/librustdoc/html/render.rs

+32-23
Original file line numberDiff line numberDiff line change
@@ -992,13 +992,11 @@ themePicker.onblur = handleThemeButtonsBlur;
992992
writeln!(v, "{}", *implementor).unwrap();
993993
}
994994
v.push_str(
995-
r"
996-
if (window.register_implementors) {
997-
window.register_implementors(implementors);
998-
} else {
999-
window.pending_implementors = implementors;
1000-
}
1001-
",
995+
"if (window.register_implementors) {\
996+
window.register_implementors(implementors);\
997+
} else {\
998+
window.pending_implementors = implementors;\
999+
}",
10021000
);
10031001
v.push_str("})()");
10041002
cx.shared.fs.write(&mydst, &v)?;
@@ -2353,6 +2351,7 @@ fn render_implementor(
23532351
implementor: &Impl,
23542352
w: &mut Buffer,
23552353
implementor_dups: &FxHashMap<&str, (DefId, bool)>,
2354+
aliases: &[String],
23562355
) {
23572356
// If there's already another implementor that has the same abbridged name, use the
23582357
// full path, for example in `std::iter::ExactSizeIterator`
@@ -2375,6 +2374,7 @@ fn render_implementor(
23752374
Some(use_absolute),
23762375
false,
23772376
false,
2377+
aliases,
23782378
);
23792379
}
23802380

@@ -2396,6 +2396,7 @@ fn render_impls(cx: &Context, w: &mut Buffer, traits: &[&&Impl], containing_item
23962396
None,
23972397
false,
23982398
true,
2399+
&[],
23992400
);
24002401
buffer.into_inner()
24012402
})
@@ -2597,8 +2598,6 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait)
25972598
// If there are methods directly on this trait object, render them here.
25982599
render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All);
25992600

2600-
let mut synthetic_types = Vec::new();
2601-
26022601
if let Some(implementors) = cx.cache.implementors.get(&it.def_id) {
26032602
// The DefId is for the first Type found with that name. The bool is
26042603
// if any Types with the same name but different DefId have been found.
@@ -2649,6 +2648,7 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait)
26492648
None,
26502649
true,
26512650
false,
2651+
&[],
26522652
);
26532653
}
26542654
write_loading_content(w, "");
@@ -2661,7 +2661,7 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait)
26612661
"<div class='item-list' id='implementors-list'>",
26622662
);
26632663
for implementor in concrete {
2664-
render_implementor(cx, implementor, w, &implementor_dups);
2664+
render_implementor(cx, implementor, w, &implementor_dups, &[]);
26652665
}
26662666
write_loading_content(w, "</div>");
26672667

@@ -2673,9 +2673,13 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait)
26732673
"<div class='item-list' id='synthetic-implementors-list'>",
26742674
);
26752675
for implementor in synthetic {
2676-
synthetic_types
2677-
.extend(collect_paths_for_type(implementor.inner_impl().for_.clone()));
2678-
render_implementor(cx, implementor, w, &implementor_dups);
2676+
render_implementor(
2677+
cx,
2678+
implementor,
2679+
w,
2680+
&implementor_dups,
2681+
&collect_paths_for_type(implementor.inner_impl().for_.clone()),
2682+
);
26792683
}
26802684
write_loading_content(w, "</div>");
26812685
}
@@ -2700,17 +2704,12 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait)
27002704
write_loading_content(w, "</div>");
27012705
}
27022706
}
2703-
write!(
2704-
w,
2705-
r#"<script type="text/javascript">window.inlined_types=new Set({});</script>"#,
2706-
serde_json::to_string(&synthetic_types).unwrap(),
2707-
);
27082707

27092708
write!(
27102709
w,
2711-
r#"<script type="text/javascript" async
2712-
src="{root_path}/implementors/{path}/{ty}.{name}.js">
2713-
</script>"#,
2710+
"<script type=\"text/javascript\" \
2711+
src=\"{root_path}/implementors/{path}/{ty}.{name}.js\" async>\
2712+
</script>",
27142713
root_path = vec![".."; cx.current.len()].join("/"),
27152714
path = if it.def_id.is_local() {
27162715
cx.current.join("/")
@@ -3392,6 +3391,7 @@ fn render_assoc_items(
33923391
None,
33933392
false,
33943393
true,
3394+
&[],
33953395
);
33963396
}
33973397
}
@@ -3602,6 +3602,9 @@ fn render_impl(
36023602
use_absolute: Option<bool>,
36033603
is_on_foreign_type: bool,
36043604
show_default_items: bool,
3605+
// This argument is used to reference same type with different pathes to avoid duplication
3606+
// in documentation pages for trait with automatic implementations like "Send" and "Sync".
3607+
aliases: &[String],
36053608
) {
36063609
if render_mode == RenderMode::Normal {
36073610
let id = cx.derive_id(match i.inner_impl().trait_ {
@@ -3614,8 +3617,13 @@ fn render_impl(
36143617
}
36153618
None => "impl".to_string(),
36163619
});
3620+
let aliases = if aliases.is_empty() {
3621+
String::new()
3622+
} else {
3623+
format!(" aliases=\"{}\"", aliases.join(","))
3624+
};
36173625
if let Some(use_absolute) = use_absolute {
3618-
write!(w, "<h3 id='{}' class='impl'><code class='in-band'>", id);
3626+
write!(w, "<h3 id='{}' class='impl'{}><code class='in-band'>", id, aliases);
36193627
fmt_impl_for_trait_page(&i.inner_impl(), w, use_absolute);
36203628
if show_def_docs {
36213629
for it in &i.inner_impl().items {
@@ -3637,8 +3645,9 @@ fn render_impl(
36373645
} else {
36383646
write!(
36393647
w,
3640-
"<h3 id='{}' class='impl'><code class='in-band'>{}</code>",
3648+
"<h3 id='{}' class='impl'{}><code class='in-band'>{}</code>",
36413649
id,
3650+
aliases,
36423651
i.inner_impl().print()
36433652
);
36443653
}

src/librustdoc/html/static/main.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -1895,6 +1895,22 @@ function getSearchElement() {
18951895
var implementors = document.getElementById("implementors-list");
18961896
var synthetic_implementors = document.getElementById("synthetic-implementors-list");
18971897

1898+
// This `inlined_types` variable is used to avoid having the same implementation showing
1899+
// up twice. For example "String" in the "Sync" doc page.
1900+
//
1901+
// By the way, this is only used by and useful for traits implemented automatically (like
1902+
// "Send" and "Sync").
1903+
var inlined_types = new Set();
1904+
onEachLazy(synthetic_implementors.getElementsByClassName("impl"), function(el) {
1905+
var aliases = el.getAttribute("aliases");
1906+
if (!aliases) {
1907+
return;
1908+
}
1909+
aliases.split(",").forEach(function(alias) {
1910+
inlined_types.add(alias);
1911+
});
1912+
});
1913+
18981914
var libs = Object.getOwnPropertyNames(imp);
18991915
var llength = libs.length;
19001916
for (var i = 0; i < llength; ++i) {
@@ -1911,10 +1927,10 @@ function getSearchElement() {
19111927
if (struct.synthetic) {
19121928
var stlength = struct.types.length;
19131929
for (var k = 0; k < stlength; k++) {
1914-
if (window.inlined_types.has(struct.types[k])) {
1930+
if (inlined_types.has(struct.types[k])) {
19151931
continue struct_loop;
19161932
}
1917-
window.inlined_types.add(struct.types[k]);
1933+
inlined_types.add(struct.types[k]);
19181934
}
19191935
}
19201936

src/test/rustdoc/auto_aliases.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![feature(optin_builtin_traits)]
2+
3+
// @has auto_aliases/trait.Bar.html '//h3[@aliases="auto_aliases::Foo"]' 'impl Bar for Foo'
4+
pub struct Foo;
5+
6+
pub auto trait Bar {}

0 commit comments

Comments
 (0)