Skip to content

Rustdoc: disambiguate Implementors when the type name is not unique #38414

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

Merged
merged 5 commits into from
Jan 4, 2017
Merged
Changes from 1 commit
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
31 changes: 17 additions & 14 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2110,24 +2110,27 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
<h2 id='implementors'>Implementors</h2>
<ul class='item-list' id='implementors-list'>
")?;
let mut implementor_count: FxHashMap<String, usize> = FxHashMap();
for (_, implementors) in cache.implementors.iter() {
Copy link
Member

Choose a reason for hiding this comment

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

It's counting far too many.. all implementors instead of just the ones for this trait(!). I tested a fix.

for implementor in implementors {
if let clean::Type::ResolvedPath {ref path, ..} = implementor.impl_.for_ {
*implementor_count.entry(path.last_name()).or_insert(0) += 1;
}
}
}
if let Some(implementors) = cache.implementors.get(&it.def_id) {
for k in implementors.iter() {
for implementor in implementors.iter() {
write!(w, "<li><code>")?;
// If there's already another implementor that has the same abbridged name, use the
// full path, for example in `std::iter::ExactSizeIterator`
let mut dissambiguate = false;
for l in implementors.iter() {
match (k.impl_.for_.clone(), l.impl_.for_.clone()) {
(clean::Type::ResolvedPath {path: path_a, ..},
clean::Type::ResolvedPath {path: path_b, ..}) => {
if k.def_id != l.def_id && path_a.last_name() == path_b.last_name() {
dissambiguate = true;
}
}
_ => (),
}
}
fmt_impl_for_trait_page(&k.impl_, w, dissambiguate)?;
let dissambiguate = if let clean::Type::ResolvedPath {
Copy link
Member

Choose a reason for hiding this comment

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

Extra s in the spelling here. It's another of the ones that should have the same name across the patch, though.

ref path, ..
} = implementor.impl_.for_ {
*implementor_count.get(&path.last_name()).unwrap_or(&0) > 1
} else {
false
};
fmt_impl_for_trait_page(&implementor.impl_, w, dissambiguate)?;
writeln!(w, "</code></li>")?;
}
}
Expand Down