Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore linking to itself in implementors section of trait page #81313

Merged
merged 1 commit into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 2 additions & 43 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,6 @@ impl Buffer {
self.into_inner()
}

crate fn from_display<T: std::fmt::Display>(&mut self, t: T) {
if self.for_html {
write!(self, "{}", t);
} else {
write!(self, "{:#}", t);
}
}

crate fn is_for_html(&self) -> bool {
self.for_html
}
Expand Down Expand Up @@ -900,16 +892,7 @@ impl clean::Type {
}

impl clean::Impl {
crate fn print<'a>(&'a self, cache: &'a Cache) -> impl fmt::Display + 'a {
self.print_inner(true, false, cache)
}

fn print_inner<'a>(
&'a self,
link_trait: bool,
use_absolute: bool,
cache: &'a Cache,
) -> impl fmt::Display + 'a {
crate fn print<'a>(&'a self, cache: &'a Cache, use_absolute: bool) -> impl fmt::Display + 'a {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this ever called with use_absolute: true? If not, can you remove the parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used here:

write!(w, "{}", i.inner_impl().print(cx.cache(), use_absolute));

Where AFAICT use_absolute can be true from

let use_absolute = match implementor.inner_impl().for_ {
clean::ResolvedPath { ref path, is_generic: false, .. }
| clean::BorrowedRef {
type_: box clean::ResolvedPath { ref path, is_generic: false, .. },
..
} => implementor_dups[&path.last()].1,
_ => false,
};

display_fn(move |f| {
if f.alternate() {
write!(f, "impl{:#} ", self.generics.print(cache))?;
Expand All @@ -921,21 +904,7 @@ impl clean::Impl {
if self.negative_polarity {
write!(f, "!")?;
}

if link_trait {
fmt::Display::fmt(&ty.print(cache), f)?;
} else {
match ty {
clean::ResolvedPath {
param_names: None, path, is_generic: false, ..
} => {
let last = path.segments.last().unwrap();
fmt::Display::fmt(&last.name, f)?;
fmt::Display::fmt(&last.args.print(cache), f)?;
}
_ => unreachable!(),
}
}
fmt::Display::fmt(&ty.print(cache), f)?;
write!(f, " for ")?;
}

Expand All @@ -952,16 +921,6 @@ impl clean::Impl {
}
}

// The difference from above is that trait is not hyperlinked.
crate fn fmt_impl_for_trait_page(
i: &clean::Impl,
f: &mut Buffer,
use_absolute: bool,
cache: &Cache,
) {
f.from_display(i.print_inner(false, use_absolute, cache))
}

impl clean::Arguments {
crate fn print<'a>(&'a self, cache: &'a Cache) -> impl fmt::Display + 'a {
display_fn(move |f| {
Expand Down
13 changes: 6 additions & 7 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ use crate::formats::cache::Cache;
use crate::formats::item_type::ItemType;
use crate::formats::{AssocItemRender, FormatRenderer, Impl, RenderMode};
use crate::html::escape::Escape;
use crate::html::format::fmt_impl_for_trait_page;
use crate::html::format::Function;
use crate::html::format::{href, print_default_space, print_generic_bounds, WhereClause};
use crate::html::format::{print_abi_with_space, Buffer, PrintWithSpace};
Expand Down Expand Up @@ -1138,7 +1137,7 @@ themePicker.onblur = handleThemeButtonsBlur;
None
} else {
Some(Implementor {
text: imp.inner_impl().print(cx.cache()).to_string(),
text: imp.inner_impl().print(cx.cache(), false).to_string(),
synthetic: imp.inner_impl().synthetic,
types: collect_paths_for_type(imp.inner_impl().for_.clone(), cx.cache()),
})
Expand Down Expand Up @@ -2550,8 +2549,8 @@ fn bounds(t_bounds: &[clean::GenericBound], trait_alias: bool, cache: &Cache) ->
}

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

// lhs and rhs are formatted as HTML, which may be unnecessary
compare_names(&lhs, &rhs)
Expand Down Expand Up @@ -3698,7 +3697,7 @@ fn spotlight_decl(decl: &clean::FnDecl, cache: &Cache) -> String {
write!(
&mut out,
"<span class=\"where fmt-newline\">{}</span>",
impl_.print(cache)
impl_.print(cache, false)
);
let t_did = impl_.trait_.def_id_full(cache).unwrap();
for it in &impl_.items {
Expand Down Expand Up @@ -3771,7 +3770,7 @@ fn render_impl(
};
if let Some(use_absolute) = use_absolute {
write!(w, "<h3 id=\"{}\" class=\"impl\"{}><code class=\"in-band\">", id, aliases);
fmt_impl_for_trait_page(&i.inner_impl(), w, use_absolute, cx.cache());
write!(w, "{}", i.inner_impl().print(cx.cache(), use_absolute));
if show_def_docs {
for it in &i.inner_impl().items {
if let clean::TypedefItem(ref tydef, _) = *it.kind {
Expand All @@ -3796,7 +3795,7 @@ fn render_impl(
"<h3 id=\"{}\" class=\"impl\"{}><code class=\"in-band\">{}</code>",
id,
aliases,
i.inner_impl().print(cx.cache())
i.inner_impl().print(cx.cache(), false)
);
}
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/trait-self-link.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @!has trait_self_link/trait.Foo.html //a/@href ../trait_self_link/trait.Foo.html
LeSeulArtichaut marked this conversation as resolved.
Show resolved Hide resolved
// @has trait_self_link/trait.Foo.html //a/@href ../trait_self_link/trait.Foo.html
pub trait Foo {}

pub struct Bar;
Expand Down