Skip to content

Commit 921ec4b

Browse files
committed
Auto merge of #81313 - LeSeulArtichaut:revert-32558, r=jyn514
Restore linking to itself in implementors section of trait page Reverts #32558 as proposed in [this Zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/Trait.20implementation.20self-links/near/223773273) r? `@jyn514` cc `@camelid`
2 parents 0b96f60 + 1daddb4 commit 921ec4b

File tree

3 files changed

+9
-51
lines changed

3 files changed

+9
-51
lines changed

Diff for: src/librustdoc/html/format.rs

+2-43
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,6 @@ impl Buffer {
102102
self.into_inner()
103103
}
104104

105-
crate fn from_display<T: std::fmt::Display>(&mut self, t: T) {
106-
if self.for_html {
107-
write!(self, "{}", t);
108-
} else {
109-
write!(self, "{:#}", t);
110-
}
111-
}
112-
113105
crate fn is_for_html(&self) -> bool {
114106
self.for_html
115107
}
@@ -900,16 +892,7 @@ impl clean::Type {
900892
}
901893

902894
impl clean::Impl {
903-
crate fn print<'a>(&'a self, cache: &'a Cache) -> impl fmt::Display + 'a {
904-
self.print_inner(true, false, cache)
905-
}
906-
907-
fn print_inner<'a>(
908-
&'a self,
909-
link_trait: bool,
910-
use_absolute: bool,
911-
cache: &'a Cache,
912-
) -> impl fmt::Display + 'a {
895+
crate fn print<'a>(&'a self, cache: &'a Cache, use_absolute: bool) -> impl fmt::Display + 'a {
913896
display_fn(move |f| {
914897
if f.alternate() {
915898
write!(f, "impl{:#} ", self.generics.print(cache))?;
@@ -921,21 +904,7 @@ impl clean::Impl {
921904
if self.negative_polarity {
922905
write!(f, "!")?;
923906
}
924-
925-
if link_trait {
926-
fmt::Display::fmt(&ty.print(cache), f)?;
927-
} else {
928-
match ty {
929-
clean::ResolvedPath {
930-
param_names: None, path, is_generic: false, ..
931-
} => {
932-
let last = path.segments.last().unwrap();
933-
fmt::Display::fmt(&last.name, f)?;
934-
fmt::Display::fmt(&last.args.print(cache), f)?;
935-
}
936-
_ => unreachable!(),
937-
}
938-
}
907+
fmt::Display::fmt(&ty.print(cache), f)?;
939908
write!(f, " for ")?;
940909
}
941910

@@ -952,16 +921,6 @@ impl clean::Impl {
952921
}
953922
}
954923

955-
// The difference from above is that trait is not hyperlinked.
956-
crate fn fmt_impl_for_trait_page(
957-
i: &clean::Impl,
958-
f: &mut Buffer,
959-
use_absolute: bool,
960-
cache: &Cache,
961-
) {
962-
f.from_display(i.print_inner(false, use_absolute, cache))
963-
}
964-
965924
impl clean::Arguments {
966925
crate fn print<'a>(&'a self, cache: &'a Cache) -> impl fmt::Display + 'a {
967926
display_fn(move |f| {

Diff for: src/librustdoc/html/render/mod.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ use crate::formats::cache::Cache;
7373
use crate::formats::item_type::ItemType;
7474
use crate::formats::{AssocItemRender, FormatRenderer, Impl, RenderMode};
7575
use crate::html::escape::Escape;
76-
use crate::html::format::fmt_impl_for_trait_page;
7776
use crate::html::format::Function;
7877
use crate::html::format::{href, print_default_space, print_generic_bounds, WhereClause};
7978
use crate::html::format::{print_abi_with_space, Buffer, PrintWithSpace};
@@ -1138,7 +1137,7 @@ themePicker.onblur = handleThemeButtonsBlur;
11381137
None
11391138
} else {
11401139
Some(Implementor {
1141-
text: imp.inner_impl().print(cx.cache()).to_string(),
1140+
text: imp.inner_impl().print(cx.cache(), false).to_string(),
11421141
synthetic: imp.inner_impl().synthetic,
11431142
types: collect_paths_for_type(imp.inner_impl().for_.clone(), cx.cache()),
11441143
})
@@ -2550,8 +2549,8 @@ fn bounds(t_bounds: &[clean::GenericBound], trait_alias: bool, cache: &Cache) ->
25502549
}
25512550

25522551
fn compare_impl<'a, 'b>(lhs: &'a &&Impl, rhs: &'b &&Impl, cache: &Cache) -> Ordering {
2553-
let lhs = format!("{}", lhs.inner_impl().print(cache));
2554-
let rhs = format!("{}", rhs.inner_impl().print(cache));
2552+
let lhs = format!("{}", lhs.inner_impl().print(cache, false));
2553+
let rhs = format!("{}", rhs.inner_impl().print(cache, false));
25552554

25562555
// lhs and rhs are formatted as HTML, which may be unnecessary
25572556
compare_names(&lhs, &rhs)
@@ -3698,7 +3697,7 @@ fn spotlight_decl(decl: &clean::FnDecl, cache: &Cache) -> String {
36983697
write!(
36993698
&mut out,
37003699
"<span class=\"where fmt-newline\">{}</span>",
3701-
impl_.print(cache)
3700+
impl_.print(cache, false)
37023701
);
37033702
let t_did = impl_.trait_.def_id_full(cache).unwrap();
37043703
for it in &impl_.items {
@@ -3771,7 +3770,7 @@ fn render_impl(
37713770
};
37723771
if let Some(use_absolute) = use_absolute {
37733772
write!(w, "<h3 id=\"{}\" class=\"impl\"{}><code class=\"in-band\">", id, aliases);
3774-
fmt_impl_for_trait_page(&i.inner_impl(), w, use_absolute, cx.cache());
3773+
write!(w, "{}", i.inner_impl().print(cx.cache(), use_absolute));
37753774
if show_def_docs {
37763775
for it in &i.inner_impl().items {
37773776
if let clean::TypedefItem(ref tydef, _) = *it.kind {
@@ -3796,7 +3795,7 @@ fn render_impl(
37963795
"<h3 id=\"{}\" class=\"impl\"{}><code class=\"in-band\">{}</code>",
37973796
id,
37983797
aliases,
3799-
i.inner_impl().print(cx.cache())
3798+
i.inner_impl().print(cx.cache(), false)
38003799
);
38013800
}
38023801
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);

Diff for: src/test/rustdoc/trait-self-link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @!has trait_self_link/trait.Foo.html //a/@href ../trait_self_link/trait.Foo.html
1+
// @has trait_self_link/trait.Foo.html //a/@href ../trait_self_link/trait.Foo.html
22
pub trait Foo {}
33

44
pub struct Bar;

0 commit comments

Comments
 (0)