Skip to content

Commit

Permalink
Don't display full blanket implementation and put it into its own sec…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
GuillaumeGomez committed Jul 28, 2018
1 parent ef7d6fc commit 7a3c7b2
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 24 deletions.
7 changes: 5 additions & 2 deletions src/librustdoc/clean/auto_trait.rs
Expand Up @@ -198,7 +198,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
.collect();

let ty = self.get_real_ty(def_id, def_ctor, &real_name, generics);
let predicates = infcx.tcx.predicates_of(def_id);
let predicates = infcx.tcx.predicates_of(impl_def_id);

traits.push(Item {
source: infcx.tcx.def_span(impl_def_id).clean(self.cx),
Expand All @@ -218,7 +218,9 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
.collect::<Vec<_>>()
.clean(self.cx),
polarity: None,
synthetic: true,
synthetic: false,
blanket_impl: Some(infcx.tcx.type_of(impl_def_id)
.clean(self.cx)),
}),
});
debug!("{:?} => {}", trait_ref, may_apply);
Expand Down Expand Up @@ -345,6 +347,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
items: Vec::new(),
polarity,
synthetic: true,
blanket_impl: None,
}),
});
}
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/clean/inline.rs
Expand Up @@ -414,6 +414,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec<clean::Item>) {
items: trait_items,
polarity: Some(polarity.clean(cx)),
synthetic: false,
blanket_impl: None,
}),
source: tcx.def_span(did).clean(cx),
name: None,
Expand Down
2 changes: 2 additions & 0 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -3881,6 +3881,7 @@ pub struct Impl {
pub items: Vec<Item>,
pub polarity: Option<ImplPolarity>,
pub synthetic: bool,
pub blanket_impl: Option<Type>,
}

pub fn get_auto_traits_with_node_id(cx: &DocContext, id: ast::NodeId, name: String) -> Vec<Item> {
Expand Down Expand Up @@ -3948,6 +3949,7 @@ impl Clean<Vec<Item>> for doctree::Impl {
items,
polarity: Some(self.polarity.clean(cx)),
synthetic: false,
blanket_impl: None,
})
});
ret
Expand Down
6 changes: 5 additions & 1 deletion src/librustdoc/html/format.rs
Expand Up @@ -769,7 +769,11 @@ fn fmt_impl(i: &clean::Impl,
write!(f, " for ")?;
}

fmt_type(&i.for_, f, use_absolute)?;
if let Some(ref ty) = i.blanket_impl {
fmt_type(ty, f, use_absolute)?;
} else {
fmt_type(&i.for_, f, use_absolute)?;
}

fmt::Display::fmt(&WhereClause { gens: &i.generics, indent: 0, end_newline: true }, f)?;
Ok(())
Expand Down
59 changes: 42 additions & 17 deletions src/librustdoc/html/render.rs
Expand Up @@ -177,7 +177,7 @@ pub enum ExternalLocation {
}

/// Metadata about implementations for a type or trait.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct Impl {
pub impl_item: clean::Item,
}
Expand Down Expand Up @@ -2900,18 +2900,18 @@ fn item_trait(
render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All)?;

let cache = cache();
let impl_header = "
<h2 id='implementors' class='small-section-header'>
Implementors<a href='#implementors' class='anchor'></a>
</h2>
<ul class='item-list' id='implementors-list'>
let impl_header = "\
<h2 id='implementors' class='small-section-header'>\
Implementors<a href='#implementors' class='anchor'></a>\
</h2>\
<ul class='item-list' id='implementors-list'>\
";

let synthetic_impl_header = "
<h2 id='synthetic-implementors' class='small-section-header'>
Auto implementors<a href='#synthetic-implementors' class='anchor'></a>
</h2>
<ul class='item-list' id='synthetic-implementors-list'>
let synthetic_impl_header = "\
<h2 id='synthetic-implementors' class='small-section-header'>\
Auto implementors<a href='#synthetic-implementors' class='anchor'></a>\
</h2>\
<ul class='item-list' id='synthetic-implementors-list'>\
";

let mut synthetic_types = Vec::new();
Expand Down Expand Up @@ -2942,9 +2942,9 @@ fn item_trait(
.map_or(true, |d| cache.paths.contains_key(&d)));


let (synthetic, concrete) = local.iter()
.partition::<Vec<_>, _>(|i| i.inner_impl().synthetic);

let (synthetic, concrete): (Vec<&&Impl>, Vec<&&Impl>) = local.iter()
.filter(|i| i.inner_impl().blanket_impl.is_none())
.partition(|i| i.inner_impl().synthetic);

if !foreign.is_empty() {
write!(w, "
Expand Down Expand Up @@ -3626,9 +3626,12 @@ fn render_assoc_items(w: &mut fmt::Formatter,
render_deref_methods(w, cx, impl_, containing_item, has_deref_mut)?;
}

let (synthetic, concrete) = traits
let (synthetic, concrete): (Vec<&&Impl>, Vec<&&Impl>) = traits
.iter()
.partition::<Vec<_>, _>(|t| t.inner_impl().synthetic);
.partition(|t| t.inner_impl().synthetic);
let (blanket_impl, concrete) = concrete
.into_iter()
.partition(|t| t.inner_impl().blanket_impl.is_some());

struct RendererStruct<'a, 'b, 'c>(&'a Context, Vec<&'b &'b Impl>, &'c clean::Item);

Expand Down Expand Up @@ -3658,6 +3661,18 @@ fn render_assoc_items(w: &mut fmt::Formatter,
render_impls(cx, w, &synthetic, containing_item)?;
write!(w, "</div>")?;
}

if !blanket_impl.is_empty() {
write!(w, "\
<h2 id='blanket-implementations' class='small-section-header'>\
Blanket Implementations\
<a href='#blanket-implementations' class='anchor'></a>\
</h2>\
<div id='blanket-implementations-list'>\
")?;
render_impls(cx, w, &blanket_impl, containing_item)?;
write!(w, "</div>")?;
}
}
Ok(())
}
Expand Down Expand Up @@ -4203,12 +4218,16 @@ fn sidebar_assoc_items(it: &clean::Item) -> String {
.collect::<String>()
};

let (synthetic, concrete) = v
let (synthetic, concrete): (Vec<&Impl>, Vec<&Impl>) = v
.iter()
.partition::<Vec<_>, _>(|i| i.inner_impl().synthetic);
let (blanket_impl, concrete): (Vec<&Impl>, Vec<&Impl>) = concrete
.into_iter()
.partition::<Vec<_>, _>(|i| i.inner_impl().blanket_impl.is_some());

let concrete_format = format_impls(concrete);
let synthetic_format = format_impls(synthetic);
let blanket_format = format_impls(blanket_impl);

if !concrete_format.is_empty() {
out.push_str("<a class=\"sidebar-title\" href=\"#implementations\">\
Expand All @@ -4221,6 +4240,12 @@ fn sidebar_assoc_items(it: &clean::Item) -> String {
Auto Trait Implementations</a>");
out.push_str(&format!("<div class=\"sidebar-links\">{}</div>", synthetic_format));
}

if !blanket_format.is_empty() {
out.push_str("<a class=\"sidebar-title\" href=\"#blanket-implementations\">\
Blanket Implementations</a>");
out.push_str(&format!("<div class=\"sidebar-links\">{}</div>", blanket_format));
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/rustdoc/generic-impl.rs
Expand Up @@ -12,10 +12,10 @@

use std::fmt;

// @!has foo/struct.Bar.html '//h3[@id="impl-ToString"]//code' 'impl<T> ToString for Bar'
// @!has foo/struct.Bar.html '//h3[@id="impl-ToString"]//code' 'impl<T> ToString for T'
pub struct Bar;

// @has foo/struct.Foo.html '//h3[@id="impl-ToString"]//code' 'impl<T> ToString for Foo'
// @has foo/struct.Foo.html '//h3[@id="impl-ToString"]//code' 'impl<T> ToString for T'
pub struct Foo;

impl fmt::Display for Foo {
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/synthetic_auto/basic.rs
Expand Up @@ -12,7 +12,7 @@
// @has - '//code' 'impl<T> Send for Foo<T> where T: Send'
// @has - '//code' 'impl<T> Sync for Foo<T> where T: Sync'
// @count - '//*[@id="implementations-list"]/*[@class="impl"]' 0
// @count - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]' 9
// @count - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]' 2
pub struct Foo<T> {
field: T,
}
2 changes: 1 addition & 1 deletion src/test/rustdoc/synthetic_auto/manual.rs
Expand Up @@ -16,7 +16,7 @@
// 'impl<T> Send for Foo<T>'
//
// @count - '//*[@id="implementations-list"]/*[@class="impl"]' 1
// @count - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]' 8
// @count - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]' 1
pub struct Foo<T> {
field: T,
}
Expand Down

0 comments on commit 7a3c7b2

Please sign in to comment.