Skip to content

Commit cac9107

Browse files
committed
rustdoc: Clickable links on methods themselves
Useful for getting the link to a method or function. Closes #10332
1 parent 68d576f commit cac9107

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

src/librustdoc/html/render.rs

+12-17
Original file line numberDiff line numberDiff line change
@@ -1111,15 +1111,15 @@ fn item_trait(w: &mut Writer, it: &clean::Item,
11111111
if_ok!(write!(w, "\\{\n"));
11121112
for m in required.iter() {
11131113
if_ok!(write!(w, " "));
1114-
if_ok!(render_method(w, m.item(), true));
1114+
if_ok!(render_method(w, m.item()));
11151115
if_ok!(write!(w, ";\n"));
11161116
}
11171117
if required.len() > 0 && provided.len() > 0 {
11181118
if_ok!(w.write("\n".as_bytes()));
11191119
}
11201120
for m in provided.iter() {
11211121
if_ok!(write!(w, " "));
1122-
if_ok!(render_method(w, m.item(), true));
1122+
if_ok!(render_method(w, m.item()));
11231123
if_ok!(write!(w, " \\{ ... \\}\n"));
11241124
}
11251125
if_ok!(write!(w, "\\}"));
@@ -1133,7 +1133,7 @@ fn item_trait(w: &mut Writer, it: &clean::Item,
11331133
if_ok!(write!(w, "<h3 id='{}.{}' class='method'><code>",
11341134
shortty(m.item()),
11351135
*m.item().name.get_ref()));
1136-
if_ok!(render_method(w, m.item(), false));
1136+
if_ok!(render_method(w, m.item()));
11371137
if_ok!(write!(w, "</code></h3>"));
11381138
if_ok!(document(w, m.item()));
11391139
Ok(())
@@ -1188,32 +1188,27 @@ fn item_trait(w: &mut Writer, it: &clean::Item,
11881188
})
11891189
}
11901190

1191-
fn render_method(w: &mut Writer, meth: &clean::Item,
1192-
withlink: bool) -> fmt::Result {
1191+
fn render_method(w: &mut Writer, meth: &clean::Item) -> fmt::Result {
11931192
fn fun(w: &mut Writer, it: &clean::Item, purity: ast::Purity,
1194-
g: &clean::Generics, selfty: &clean::SelfTy, d: &clean::FnDecl,
1195-
withlink: bool) -> fmt::Result {
1196-
write!(w, "{}fn {withlink, select,
1197-
true{<a href='\\#{ty}.{name}'
1198-
class='fnname'>{name}</a>}
1199-
other{<span class='fnname'>{name}</span>}
1200-
}{generics}{decl}",
1193+
g: &clean::Generics, selfty: &clean::SelfTy,
1194+
d: &clean::FnDecl) -> fmt::Result {
1195+
write!(w, "{}fn <a href='\\#{ty}.{name}' class='fnname'>{name}</a>\
1196+
{generics}{decl}",
12011197
match purity {
12021198
ast::UnsafeFn => "unsafe ",
12031199
_ => "",
12041200
},
12051201
ty = shortty(it),
12061202
name = it.name.get_ref().as_slice(),
12071203
generics = *g,
1208-
decl = Method(selfty, d),
1209-
withlink = if withlink {"true"} else {"false"})
1204+
decl = Method(selfty, d))
12101205
}
12111206
match meth.inner {
12121207
clean::TyMethodItem(ref m) => {
1213-
fun(w, meth, m.purity, &m.generics, &m.self_, &m.decl, withlink)
1208+
fun(w, meth, m.purity, &m.generics, &m.self_, &m.decl)
12141209
}
12151210
clean::MethodItem(ref m) => {
1216-
fun(w, meth, m.purity, &m.generics, &m.self_, &m.decl, withlink)
1211+
fun(w, meth, m.purity, &m.generics, &m.self_, &m.decl)
12171212
}
12181213
_ => unreachable!()
12191214
}
@@ -1444,7 +1439,7 @@ fn render_impl(w: &mut Writer, i: &clean::Impl,
14441439
fn docmeth(w: &mut Writer, item: &clean::Item) -> io::IoResult<bool> {
14451440
if_ok!(write!(w, "<h4 id='method.{}' class='method'><code>",
14461441
*item.name.get_ref()));
1447-
if_ok!(render_method(w, item, false));
1442+
if_ok!(render_method(w, item));
14481443
if_ok!(write!(w, "</code></h4>\n"));
14491444
match item.doc_value() {
14501445
Some(s) => {

0 commit comments

Comments
 (0)