mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 02:33:55 +00:00
Auto merge of #44920 - vi:rustdoc_implementors_src_link, r=GuillaumeGomez
rustdoc: Render [src] links for trait implementors Should close #43893. <s>No tests [yet].</s> r? @QuietMisdreavus
This commit is contained in:
commit
61bad301f1
@ -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)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2483,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, "<li><code>")?;
|
||||
write!(w, "<li>")?;
|
||||
if let Some(item) = implementor2item(&cache, implementor) {
|
||||
if let Some(l) = (Item { cx, item }).src_href() {
|
||||
write!(w, "<div class='out-of-band'>")?;
|
||||
write!(w, "<a class='srclink' href='{}' title='{}'>[src]</a>",
|
||||
l, "goto source code")?;
|
||||
write!(w, "</div>")?;
|
||||
}
|
||||
}
|
||||
write!(w, "<code>")?;
|
||||
// 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_ {
|
||||
|
@ -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;
|
||||
}
|
||||
|
24
src/test/rustdoc/issue-43893.rs
Normal file
24
src/test/rustdoc/issue-43893.rs
Normal file
@ -0,0 +1,24 @@
|
||||
// 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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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;
|
||||
|
||||
// @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#22-24'
|
||||
impl SomeTrait for SomeStruct {
|
||||
// deliberately multi-line impl
|
||||
}
|
Loading…
Reference in New Issue
Block a user