From 87d7520d0f88f87fa203f2a44d63ea845a46d5d3 Mon Sep 17 00:00:00 2001 From: Vitaly _Vi Shukela Date: Fri, 29 Sep 2017 14:28:25 +0300 Subject: [PATCH 1/5] rustdoc: Extract converter from Impementor to Item to a fn --- src/librustdoc/html/render.rs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 485e75443fe08..d58cfcf18b62a 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2253,6 +2253,18 @@ fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, document(w, cx, it) } +fn implementor2item<'a>(cache: &'a Cache, imp : &Implementor) -> Option<&'a clean::Item> { + if let Some(t_did) = imp.impl_.for_.def_id() { + if let Some(impl_item) = cache.impls.get(&t_did).and_then(|i| i.iter() + .find(|i| i.impl_item.def_id == imp.def_id)) + { + let i = &impl_item.impl_item; + return Some(i); + } + } + None +} + fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, t: &clean::Trait) -> fmt::Result { let mut bounds = String::new(); @@ -2463,19 +2475,13 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, ")?; for implementor in foreign { - // need to get from a clean::Impl to a clean::Item so i can use render_impl - if let Some(t_did) = implementor.impl_.for_.def_id() { - if let Some(impl_item) = cache.impls.get(&t_did).and_then(|i| i.iter() - .find(|i| i.impl_item.def_id == implementor.def_id)) - { - let i = &impl_item.impl_item; - let impl_ = Impl { impl_item: i.clone() }; - let assoc_link = AssocItemLink::GotoSource( - i.def_id, &implementor.impl_.provided_trait_methods - ); - render_impl(w, cx, &impl_, assoc_link, - RenderMode::Normal, i.stable_since(), false)?; - } + if let Some(i) = implementor2item(&cache, implementor) { + let impl_ = Impl { impl_item: i.clone() }; + let assoc_link = AssocItemLink::GotoSource( + i.def_id, &implementor.impl_.provided_trait_methods + ); + render_impl(w, cx, &impl_, assoc_link, + RenderMode::Normal, i.stable_since(), false)?; } } } From 9f02e1a938087153e1d6440e217681ae0d079c69 Mon Sep 17 00:00:00 2001 From: Vitaly _Vi Shukela Date: Fri, 29 Sep 2017 14:29:09 +0300 Subject: [PATCH 2/5] rustdoc: Render [src] links for trait implementors (#43893) --- src/librustdoc/html/render.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index d58cfcf18b62a..a3f446885f96e 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2489,7 +2489,16 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, write!(w, "{}", impl_header)?; for implementor in local { - write!(w, "
  • ")?; + write!(w, "
  • ")?; + if let Some(item) = implementor2item(&cache, implementor) { + if let Some(l) = (Item { cx, item }).src_href() { + write!(w, "
    ")?; + write!(w, "[src]", + l, "goto source code")?; + write!(w, "
    ")?; + } + } + write!(w, "")?; // If there's already another implementor that has the same abbridged name, use the // full path, for example in `std::iter::ExactSizeIterator` let use_absolute = match implementor.impl_.for_ { From d892e985b086214a56146323b356236600809355 Mon Sep 17 00:00:00 2001 From: Vitaly _Vi Shukela Date: Sat, 30 Sep 2017 03:17:51 +0300 Subject: [PATCH 3/5] rustdoc: A test for local and foreign [src] trait impl links --- src/test/rustdoc/issue-43893.rs | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/test/rustdoc/issue-43893.rs diff --git a/src/test/rustdoc/issue-43893.rs b/src/test/rustdoc/issue-43893.rs new file mode 100644 index 0000000000000..b49cffc36aa45 --- /dev/null +++ b/src/test/rustdoc/issue-43893.rs @@ -0,0 +1,34 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// ignore-cross-compile + +#![crate_name = "foo"] + +pub trait SomeTrait {} + +pub struct SomeStruct; + +// + +// dummy +// @has foo/trait.SomeTrait.html '//a/@href' '../src/foo/issue-43893.rs.html#23-26' +impl SomeTrait for usize { + + +} + +// @has foo/trait.SomeTrait.html '//a/@href' '../src/foo/issue-43893.rs.html#29-32' +impl SomeTrait for SomeStruct { + + +} + +// some trailer From 67c9af590d88ae96e612307e4e5b8ef8fe5fe2ab Mon Sep 17 00:00:00 2001 From: Vitaly _Vi Shukela Date: Sun, 1 Oct 2017 15:54:50 +0300 Subject: [PATCH 4/5] rustdoc: Style of [src] link for trait implementors A change suggested by @GuillaumeGomez and @QuietMisdreavus. Also slight reindenting of the appropriate CSS section. --- src/librustdoc/html/static/rustdoc.css | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 1b7232bf1bca8..27574e67bc87b 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -111,7 +111,10 @@ h3.impl, h3.method, h4.method, h3.type, h4.type, h4.associatedconstant { h3.impl, h3.method, h3.type { margin-top: 15px; } -h1, h2, h3, h4, .sidebar, a.source, .search-input, .content table :not(code)>a, .collapse-toggle { + +h1, h2, h3, h4, +.sidebar, a.source, .search-input, .content table :not(code)>a, +.collapse-toggle, ul.item-list > li > .out-of-band { font-family: "Fira Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; } @@ -310,6 +313,10 @@ h4.method > .out-of-band { font-size: 19px; } +ul.item-list > li > .out-of-band { + font-size: 19px; +} + h4 > code, h3 > code, .invisible > code { position: inherit; } From acef039de84d6a98a981a1be6c23f695173d98f3 Mon Sep 17 00:00:00 2001 From: Vitaly _Vi Shukela Date: Mon, 2 Oct 2017 16:54:35 +0300 Subject: [PATCH 5/5] rustdoc: Remove cruft from the test per @GuillaumeGomez's sample, but with one change. --- src/test/rustdoc/issue-43893.rs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/test/rustdoc/issue-43893.rs b/src/test/rustdoc/issue-43893.rs index b49cffc36aa45..96bd9d7dc3cc5 100644 --- a/src/test/rustdoc/issue-43893.rs +++ b/src/test/rustdoc/issue-43893.rs @@ -13,22 +13,12 @@ #![crate_name = "foo"] pub trait SomeTrait {} - pub struct SomeStruct; -// - -// dummy -// @has foo/trait.SomeTrait.html '//a/@href' '../src/foo/issue-43893.rs.html#23-26' -impl SomeTrait for usize { +// @has foo/trait.SomeTrait.html '//a/@href' '../src/foo/issue-43893.rs.html#19' +impl SomeTrait for usize {} - -} - -// @has foo/trait.SomeTrait.html '//a/@href' '../src/foo/issue-43893.rs.html#29-32' +// @has foo/trait.SomeTrait.html '//a/@href' '../src/foo/issue-43893.rs.html#22-24' impl SomeTrait for SomeStruct { - - + // deliberately multi-line impl } - -// some trailer