From: Guillaume Gomez Date: Fri, 27 Jul 2018 20:59:16 +0000 (+0200) Subject: Don't display full blanket implementation and put it into its own section X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=7a3c7b2097961138a92a771145dba7012f5c70f8;p=rust.git Don't display full blanket implementation and put it into its own section --- diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 556d8462d3b..d0d5713ec0a 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -198,7 +198,7 @@ pub fn get_auto_trait_impls( .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), @@ -218,7 +218,9 @@ pub fn get_auto_trait_impls( .collect::>() .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); @@ -345,6 +347,7 @@ fn get_auto_trait_impl_for( items: Vec::new(), polarity, synthetic: true, + blanket_impl: None, }), }); } diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index fe93dd16ffd..9245ef3cf50 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -414,6 +414,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec) { items: trait_items, polarity: Some(polarity.clean(cx)), synthetic: false, + blanket_impl: None, }), source: tcx.def_span(did).clean(cx), name: None, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 68842522223..89f328016ec 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -3881,6 +3881,7 @@ pub struct Impl { pub items: Vec, pub polarity: Option, pub synthetic: bool, + pub blanket_impl: Option, } pub fn get_auto_traits_with_node_id(cx: &DocContext, id: ast::NodeId, name: String) -> Vec { @@ -3948,6 +3949,7 @@ fn clean(&self, cx: &DocContext) -> Vec { items, polarity: Some(self.polarity.clean(cx)), synthetic: false, + blanket_impl: None, }) }); ret diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 2377354b85f..9c7354a7c63 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -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(()) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index fd39202b87c..200c961cf5d 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -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, } @@ -2900,18 +2900,18 @@ fn trait_item(w: &mut fmt::Formatter, cx: &Context, m: &clean::Item, t: &clean:: render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All)?; let cache = cache(); - let impl_header = " -

- Implementors -

-
    + let impl_header = "\ +

    \ + Implementors\ +

    \ +
      \ "; - let synthetic_impl_header = " -

      - Auto implementors -

      -
        + let synthetic_impl_header = "\ +

        \ + Auto implementors\ +

        \ +
          \ "; let mut synthetic_types = Vec::new(); @@ -2942,9 +2942,9 @@ fn trait_item(w: &mut fmt::Formatter, cx: &Context, m: &clean::Item, t: &clean:: .map_or(true, |d| cache.paths.contains_key(&d))); - let (synthetic, concrete) = local.iter() - .partition::, _>(|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, " @@ -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::, _>(|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); @@ -3658,6 +3661,18 @@ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { render_impls(cx, w, &synthetic, containing_item)?; write!(w, "")?; } + + if !blanket_impl.is_empty() { + write!(w, "\ +

          \ + Blanket Implementations\ + \ +

          \ +
          \ + ")?; + render_impls(cx, w, &blanket_impl, containing_item)?; + write!(w, "
          ")?; + } } Ok(()) } @@ -4203,12 +4218,16 @@ fn sidebar_assoc_items(it: &clean::Item) -> String { .collect::() }; - let (synthetic, concrete) = v + let (synthetic, concrete): (Vec<&Impl>, Vec<&Impl>) = v .iter() .partition::, _>(|i| i.inner_impl().synthetic); + let (blanket_impl, concrete): (Vec<&Impl>, Vec<&Impl>) = concrete + .into_iter() + .partition::, _>(|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("\ @@ -4221,6 +4240,12 @@ fn sidebar_assoc_items(it: &clean::Item) -> String { Auto Trait Implementations"); out.push_str(&format!("
          {}
          ", synthetic_format)); } + + if !blanket_format.is_empty() { + out.push_str("\ + Blanket Implementations"); + out.push_str(&format!("
          {}
          ", blanket_format)); + } } } diff --git a/src/test/rustdoc/generic-impl.rs b/src/test/rustdoc/generic-impl.rs index e69a3277d7f..e2665fd8f37 100644 --- a/src/test/rustdoc/generic-impl.rs +++ b/src/test/rustdoc/generic-impl.rs @@ -12,10 +12,10 @@ use std::fmt; -// @!has foo/struct.Bar.html '//h3[@id="impl-ToString"]//code' 'impl ToString for Bar' +// @!has foo/struct.Bar.html '//h3[@id="impl-ToString"]//code' 'impl ToString for T' pub struct Bar; -// @has foo/struct.Foo.html '//h3[@id="impl-ToString"]//code' 'impl ToString for Foo' +// @has foo/struct.Foo.html '//h3[@id="impl-ToString"]//code' 'impl ToString for T' pub struct Foo; impl fmt::Display for Foo { diff --git a/src/test/rustdoc/synthetic_auto/basic.rs b/src/test/rustdoc/synthetic_auto/basic.rs index f9a6c2607cd..8ff84d11a50 100644 --- a/src/test/rustdoc/synthetic_auto/basic.rs +++ b/src/test/rustdoc/synthetic_auto/basic.rs @@ -12,7 +12,7 @@ // @has - '//code' 'impl Send for Foo where T: Send' // @has - '//code' 'impl Sync for Foo 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 { field: T, } diff --git a/src/test/rustdoc/synthetic_auto/manual.rs b/src/test/rustdoc/synthetic_auto/manual.rs index 8c7f9d8cc65..ef6797ecf3c 100644 --- a/src/test/rustdoc/synthetic_auto/manual.rs +++ b/src/test/rustdoc/synthetic_auto/manual.rs @@ -16,7 +16,7 @@ // 'impl Send for Foo' // // @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 { field: T, }