Skip to content

Commit c5e03be

Browse files
committed
rustdoc: Don't emit redirect pages for variants/fields
It's just a waste of disk space and it can be done just as well in JS.
1 parent 10e7f12 commit c5e03be

File tree

2 files changed

+45
-56
lines changed

2 files changed

+45
-56
lines changed

src/librustdoc/html/render.rs

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,9 @@ impl<'self> DocFolder for Cache {
248248
match item.name {
249249
Some(ref s) => {
250250
let parent = match item.inner {
251-
clean::TyMethodItem(*) | clean::VariantItem(*) => {
251+
clean::TyMethodItem(*) |
252+
clean::StructFieldItem(*) |
253+
clean::VariantItem(*) => {
252254
Some((Some(*self.parent_stack.last()),
253255
self.stack.slice_to(self.stack.len() - 1)))
254256

@@ -299,7 +301,7 @@ impl<'self> DocFolder for Cache {
299301

300302
// Maintain the parent stack
301303
let parent_pushed = match item.inner {
302-
clean::TraitItem(*) | clean::EnumItem(*) => {
304+
clean::TraitItem(*) | clean::EnumItem(*) | clean::StructItem(*) => {
303305
self.parent_stack.push(item.id); true
304306
}
305307
clean::ImplItem(ref i) => {
@@ -510,28 +512,6 @@ impl Context {
510512
let dst = self.dst.push(item_path(&item));
511513
let writer = dst.open_writer(io::CreateOrTruncate);
512514
render(writer.unwrap(), self, &item, true);
513-
514-
// recurse if necessary
515-
let name = item.name.get_ref().clone();
516-
match item.inner {
517-
clean::EnumItem(e) => {
518-
let mut it = e.variants.move_iter();
519-
do self.recurse(name) |this| {
520-
for item in it {
521-
f(this, item);
522-
}
523-
}
524-
}
525-
clean::StructItem(s) => {
526-
let mut it = s.fields.move_iter();
527-
do self.recurse(name) |this| {
528-
for item in it {
529-
f(this, item);
530-
}
531-
}
532-
}
533-
_ => {}
534-
}
535515
}
536516

537517
_ => {}
@@ -613,9 +593,6 @@ impl<'self> fmt::Default for Item<'self> {
613593
clean::StructItem(ref s) => item_struct(fmt.buf, it.item, s),
614594
clean::EnumItem(ref e) => item_enum(fmt.buf, it.item, e),
615595
clean::TypedefItem(ref t) => item_typedef(fmt.buf, it.item, t),
616-
clean::VariantItem(*) => item_variant(fmt.buf, it.cx, it.item),
617-
clean::StructFieldItem(*) => item_struct_field(fmt.buf, it.cx,
618-
it.item),
619596
_ => {}
620597
}
621598
}
@@ -862,7 +839,8 @@ fn item_trait(w: &mut io::Writer, it: &clean::Item, t: &clean::Trait) {
862839
document(w, it);
863840

864841
fn meth(w: &mut io::Writer, m: &clean::TraitMethod) {
865-
write!(w, "<h3 id='fn.{}' class='method'><code>",
842+
write!(w, "<h3 id='{}.{}' class='method'><code>",
843+
shortty(m.item()),
866844
*m.item().name.get_ref());
867845
render_method(w, m.item(), false);
868846
write!(w, "</code></h3>");
@@ -923,13 +901,15 @@ fn render_method(w: &mut io::Writer, meth: &clean::Item, withlink: bool) {
923901
g: &clean::Generics, selfty: &clean::SelfTy, d: &clean::FnDecl,
924902
withlink: bool) {
925903
write!(w, "{}fn {withlink, select,
926-
true{<a href='\\#fn.{name}' class='fnname'>{name}</a>}
904+
true{<a href='\\#{ty}.{name}'
905+
class='fnname'>{name}</a>}
927906
other{<span class='fnname'>{name}</span>}
928907
}{generics}{decl}",
929908
match purity {
930909
ast::unsafe_fn => "unsafe ",
931910
_ => "",
932911
},
912+
ty = shortty(it),
933913
name = it.name.get_ref().as_slice(),
934914
generics = *g,
935915
decl = Method(selfty, d),
@@ -1014,7 +994,7 @@ fn render_struct(w: &mut io::Writer, it: &clean::Item,
1014994
for field in fields.iter() {
1015995
match field.inner {
1016996
clean::StructFieldItem(ref ty) => {
1017-
write!(w, " {}<a name='field.{name}'>{name}</a>: \
997+
write!(w, " {}<a name='structfield.{name}'>{name}</a>: \
1018998
{},\n{}",
1019999
VisSpace(field.visibility),
10201000
ty.type_,
@@ -1089,7 +1069,7 @@ fn render_impl(w: &mut io::Writer, i: &clean::Impl) {
10891069
write!(w, "{}</code></h3>", i.for_);
10901070
write!(w, "<div class='methods'>");
10911071
for meth in i.methods.iter() {
1092-
write!(w, "<h4 id='fn.{}' class='method'><code>",
1072+
write!(w, "<h4 id='method.{}' class='method'><code>",
10931073
*meth.name.get_ref());
10941074
render_method(w, meth, false);
10951075
write!(w, "</code></h4>\n");
@@ -1196,21 +1176,3 @@ fn build_sidebar(m: &clean::Module) -> HashMap<~str, ~[~str]> {
11961176
}
11971177
return map;
11981178
}
1199-
1200-
fn item_variant(w: &mut io::Writer, cx: &Context, it: &clean::Item) {
1201-
write!(w, "<DOCTYPE html><html><head>\
1202-
<meta http-equiv='refresh' content='0; \
1203-
url=../enum.{}.html\\#variant.{}'>\
1204-
</head><body></body></html>",
1205-
*cx.current.last(),
1206-
it.name.get_ref().as_slice());
1207-
}
1208-
1209-
fn item_struct_field(w: &mut io::Writer, cx: &Context, it: &clean::Item) {
1210-
write!(w, "<DOCTYPE html><html><head>\
1211-
<meta http-equiv='refresh' content='0; \
1212-
url=../struct.{}.html\\#field.{}'>\
1213-
</head><body></body></html>",
1214-
*cx.current.last(),
1215-
it.name.get_ref().as_slice());
1216-
}

src/librustdoc/html/static/main.js

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,25 +265,52 @@
265265
output += '<tr class="' + type + ' result"><td>';
266266

267267
if (type === 'mod') {
268-
output += item.path + '::<a href="' + rootPath + item.path.replace(/::/g, '/') + '/' + name + '/index.html" class="' + type + '">' + name + '</a>';
268+
output += item.path +
269+
'::<a href="' + rootPath +
270+
item.path.replace(/::/g, '/') + '/' +
271+
name + '/index.html" class="' +
272+
type + '">' + name + '</a>';
269273
} else if (type === 'static' || type === 'reexport') {
270-
output += item.path + '::<a href="' + rootPath + item.path.replace(/::/g, '/') + '/index.html" class="' + type + '">' + name + '</a>';
274+
output += item.path +
275+
'::<a href="' + rootPath +
276+
item.path.replace(/::/g, '/') +
277+
'/index.html" class="' + type +
278+
'">' + name + '</a>';
271279
} else if (item.parent !== undefined) {
280+
console.log(item);
272281
var myparent = allPaths[item.parent];
273-
output += item.path + '::' + myparent.name + '::<a href="' + rootPath + item.path.replace(/::/g, '/') + '/' + myparent.type + '.' + myparent.name + '.html" class="' + type + '">' + name + '</a>';
282+
var anchor = '#' + type + '.' + name;
283+
output += item.path + '::' + myparent.name +
284+
'::<a href="' + rootPath +
285+
item.path.replace(/::/g, '/') +
286+
'/' + myparent.type +
287+
'.' + myparent.name +
288+
'.html' + anchor +
289+
'" class="' + type +
290+
'">' + name + '</a>';
274291
} else {
275-
output += item.path + '::<a href="' + rootPath + item.path.replace(/::/g, '/') + '/' + type + '.' + name + '.html" class="' + type + '">' + name + '</a>';
292+
output += item.path +
293+
'::<a href="' + rootPath +
294+
item.path.replace(/::/g, '/') +
295+
'/' + type +
296+
'.' + name +
297+
'.html" class="' + type +
298+
'">' + name + '</a>';
276299
}
277300

278-
output += '</td><td><span class="desc">' + item.desc + '</span></td></tr>';
301+
output += '</td><td><span class="desc">' + item.desc +
302+
'</span></td></tr>';
279303
});
280304
} else {
281-
output += 'No results :( <a href="https://duckduckgo.com/?q=' + encodeURIComponent('rust ' + query.query) + '">Try on DuckDuckGo?</a>';
305+
output += 'No results :( <a href="https://duckduckgo.com/?q=' +
306+
encodeURIComponent('rust ' + query.query) +
307+
'">Try on DuckDuckGo?</a>';
282308
}
283309

284310
output += "</p>";
285311
$('.content').html(output);
286-
$('.search-results .desc').width($('.content').width() - 40 - $('.content td:first-child').first().width());
312+
$('.search-results .desc').width($('.content').width() - 40 -
313+
$('.content td:first-child').first().width());
287314
initSearchNav();
288315
}
289316

0 commit comments

Comments
 (0)