Skip to content

Commit 2dd9526

Browse files
committed
---
yaml --- r: 83515 b: refs/heads/try c: 74dfd93 h: refs/heads/master i: 83513: da1c15b 83511: 0fc6df5 v: v3
1 parent 71c4845 commit 2dd9526

File tree

9 files changed

+205
-44
lines changed

9 files changed

+205
-44
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 0e4d1fc8cae42e15e00f71d9f439b01bb25a86ae
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6c08cc2db4f98e9f07ae7d50338396c4123c2f0a
5-
refs/heads/try: ae8a2ff37976b069b24bd0558c7af3474dab5854
5+
refs/heads/try: 74dfd93bad2a2343f330cbea38c702192095210a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/librustdoc/clean.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use its = syntax::parse::token::ident_to_str;
1616
use syntax;
1717
use syntax::ast;
1818
use syntax::ast_util;
19+
use syntax::attr;
1920
use syntax::attr::AttributeMethods;
2021

2122
use std;
@@ -149,6 +150,8 @@ pub enum ItemEnum {
149150
MethodItem(Method),
150151
StructFieldItem(StructField),
151152
VariantItem(Variant),
153+
ForeignFunctionItem(Function),
154+
ForeignStaticItem(Static),
152155
}
153156

154157
#[deriving(Clone, Encodable, Decodable)]
@@ -172,6 +175,7 @@ impl Clean<Item> for doctree::Module {
172175
inner: ModuleItem(Module {
173176
items: std::vec::concat(&[self.structs.clean(),
174177
self.enums.clean(), self.fns.clean(),
178+
std::vec::concat(self.foreigns.clean()),
175179
self.mods.clean(), self.typedefs.clean(),
176180
self.statics.clean(), self.traits.clean(),
177181
self.impls.clean(), self.view_items.clean()])
@@ -203,6 +207,25 @@ impl Clean<Attribute> for ast::Attribute {
203207
}
204208
}
205209

210+
// This is a rough approximation that gets us what we want.
211+
impl<'self> attr::AttrMetaMethods for &'self Attribute {
212+
fn name(&self) -> @str {
213+
match **self {
214+
Word(ref n) | List(ref n, _) | NameValue(ref n, _) =>
215+
n.to_managed()
216+
}
217+
}
218+
219+
fn value_str(&self) -> Option<@str> {
220+
match **self {
221+
NameValue(_, ref v) => Some(v.to_managed()),
222+
_ => None,
223+
}
224+
}
225+
fn meta_item_list<'a>(&'a self) -> Option<&'a [@ast::MetaItem]> { None }
226+
fn name_str_pair(&self) -> Option<(@str, @str)> { None }
227+
}
228+
206229
#[deriving(Clone, Encodable, Decodable)]
207230
pub struct TyParam {
208231
name: ~str,
@@ -968,6 +991,41 @@ impl Clean<ViewListIdent> for ast::path_list_ident {
968991
}
969992
}
970993

994+
impl Clean<~[Item]> for ast::foreign_mod {
995+
fn clean(&self) -> ~[Item] {
996+
self.items.clean()
997+
}
998+
}
999+
1000+
impl Clean<Item> for ast::foreign_item {
1001+
fn clean(&self) -> Item {
1002+
let inner = match self.node {
1003+
ast::foreign_item_fn(ref decl, ref generics) => {
1004+
ForeignFunctionItem(Function {
1005+
decl: decl.clean(),
1006+
generics: generics.clean(),
1007+
purity: ast::extern_fn,
1008+
})
1009+
}
1010+
ast::foreign_item_static(ref ty, mutbl) => {
1011+
ForeignStaticItem(Static {
1012+
type_: ty.clean(),
1013+
mutability: if mutbl {Mutable} else {Immutable},
1014+
expr: ~"",
1015+
})
1016+
}
1017+
};
1018+
Item {
1019+
name: Some(self.ident.clean()),
1020+
attrs: self.attrs.clean(),
1021+
source: self.span.clean(),
1022+
id: self.id,
1023+
visibility: self.vis.clean(),
1024+
inner: inner,
1025+
}
1026+
}
1027+
}
1028+
9711029
// Utilities
9721030

9731031
trait ToSource {

branches/try/src/librustdoc/doctree.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub struct Module {
3030
traits: ~[Trait],
3131
vis: ast::visibility,
3232
impls: ~[Impl],
33+
foreigns: ~[ast::foreign_mod],
3334
view_items: ~[ast::view_item],
3435
}
3536

@@ -50,6 +51,7 @@ impl Module {
5051
traits : ~[],
5152
impls : ~[],
5253
view_items : ~[],
54+
foreigns : ~[],
5355
}
5456
}
5557
}

branches/try/src/librustdoc/html/render.rs

Lines changed: 76 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use extra::json::ToJson;
2828
use extra::sort;
2929

3030
use syntax::ast;
31+
use syntax::attr;
3132

3233
use clean;
3334
use doctree;
@@ -521,6 +522,14 @@ impl Context {
521522
}
522523
}
523524
}
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+
}
524533
_ => {}
525534
}
526535
}
@@ -532,19 +541,21 @@ impl Context {
532541

533542
fn shortty(item: &clean::Item) -> &'static str {
534543
match item.inner {
535-
clean::ModuleItem(*) => "mod",
536-
clean::StructItem(*) => "struct",
537-
clean::EnumItem(*) => "enum",
538-
clean::FunctionItem(*) => "fn",
539-
clean::TypedefItem(*) => "typedef",
540-
clean::StaticItem(*) => "static",
541-
clean::TraitItem(*) => "trait",
542-
clean::ImplItem(*) => "impl",
543-
clean::ViewItemItem(*) => "viewitem",
544-
clean::TyMethodItem(*) => "tymethod",
545-
clean::MethodItem(*) => "method",
546-
clean::StructFieldItem(*) => "structfield",
547-
clean::VariantItem(*) => "variant",
544+
clean::ModuleItem(*) => "mod",
545+
clean::StructItem(*) => "struct",
546+
clean::EnumItem(*) => "enum",
547+
clean::FunctionItem(*) => "fn",
548+
clean::TypedefItem(*) => "typedef",
549+
clean::StaticItem(*) => "static",
550+
clean::TraitItem(*) => "trait",
551+
clean::ImplItem(*) => "impl",
552+
clean::ViewItemItem(*) => "viewitem",
553+
clean::TyMethodItem(*) => "tymethod",
554+
clean::MethodItem(*) => "method",
555+
clean::StructFieldItem(*) => "structfield",
556+
clean::VariantItem(*) => "variant",
557+
clean::ForeignFunctionItem(*) => "ffi",
558+
clean::ForeignStaticItem(*) => "ffs",
548559
}
549560
}
550561

@@ -558,6 +569,18 @@ impl<'self> Item<'self> {
558569

559570
impl<'self> fmt::Default for Item<'self> {
560571
fn fmt(it: &Item<'self>, fmt: &mut fmt::Formatter) {
572+
match attr::find_stability(it.item.attrs.iter()) {
573+
Some(stability) => {
574+
write!(fmt.buf,
575+
"<a class='stability {lvl}' title='{reason}'>{lvl}</a>",
576+
lvl = stability.level.to_str(),
577+
reason = match stability.text {
578+
Some(s) => s, None => @"",
579+
});
580+
}
581+
None => {}
582+
}
583+
561584
// Write the breadcrumb trail header for the top
562585
write!(fmt.buf, "<h1 class='fqn'>");
563586
match it.item.inner {
@@ -584,12 +607,15 @@ impl<'self> fmt::Default for Item<'self> {
584607
match it.item.inner {
585608
clean::ModuleItem(ref m) => item_module(fmt.buf, it.cx,
586609
it.item, m.items),
587-
clean::FunctionItem(ref f) => item_function(fmt.buf, it.item, f),
610+
clean::FunctionItem(ref f) | clean::ForeignFunctionItem(ref f) =>
611+
item_function(fmt.buf, it.item, f),
588612
clean::TraitItem(ref t) => item_trait(fmt.buf, it.item, t),
589613
clean::StructItem(ref s) => item_struct(fmt.buf, it.item, s),
590614
clean::EnumItem(ref e) => item_enum(fmt.buf, it.item, e),
591615
clean::TypedefItem(ref t) => item_typedef(fmt.buf, it.item, t),
592616
clean::VariantItem(*) => item_variant(fmt.buf, it.cx, it.item),
617+
clean::StructFieldItem(*) => item_struct_field(fmt.buf, it.cx,
618+
it.item),
593619
_ => {}
594620
}
595621
}
@@ -663,6 +689,10 @@ fn item_module(w: &mut io::Writer, cx: &Context,
663689
(_, &clean::EnumItem(*)) => false,
664690
(&clean::StaticItem(*), _) => true,
665691
(_, &clean::StaticItem(*)) => false,
692+
(&clean::ForeignFunctionItem(*), _) => true,
693+
(_, &clean::ForeignFunctionItem(*)) => false,
694+
(&clean::ForeignStaticItem(*), _) => true,
695+
(_, &clean::ForeignStaticItem(*)) => false,
666696
(&clean::TraitItem(*), _) => true,
667697
(_, &clean::TraitItem(*)) => false,
668698
(&clean::FunctionItem(*), _) => true,
@@ -690,27 +720,31 @@ fn item_module(w: &mut io::Writer, cx: &Context,
690720
}
691721
curty = myty;
692722
write!(w, "<h2>{}</h2>\n<table>", match myitem.inner {
693-
clean::ModuleItem(*) => "Modules",
694-
clean::StructItem(*) => "Structs",
695-
clean::EnumItem(*) => "Enums",
696-
clean::FunctionItem(*) => "Functions",
697-
clean::TypedefItem(*) => "Type Definitions",
698-
clean::StaticItem(*) => "Statics",
699-
clean::TraitItem(*) => "Traits",
700-
clean::ImplItem(*) => "Implementations",
701-
clean::ViewItemItem(*) => "Reexports",
702-
clean::TyMethodItem(*) => "Type Methods",
703-
clean::MethodItem(*) => "Methods",
704-
clean::StructFieldItem(*) => "Struct Fields",
705-
clean::VariantItem(*) => "Variants",
723+
clean::ModuleItem(*) => "Modules",
724+
clean::StructItem(*) => "Structs",
725+
clean::EnumItem(*) => "Enums",
726+
clean::FunctionItem(*) => "Functions",
727+
clean::TypedefItem(*) => "Type Definitions",
728+
clean::StaticItem(*) => "Statics",
729+
clean::TraitItem(*) => "Traits",
730+
clean::ImplItem(*) => "Implementations",
731+
clean::ViewItemItem(*) => "Reexports",
732+
clean::TyMethodItem(*) => "Type Methods",
733+
clean::MethodItem(*) => "Methods",
734+
clean::StructFieldItem(*) => "Struct Fields",
735+
clean::VariantItem(*) => "Variants",
736+
clean::ForeignFunctionItem(*) => "Foreign Functions",
737+
clean::ForeignStaticItem(*) => "Foreign Statics",
706738
});
707739
}
708740

709741
match myitem.inner {
710-
clean::StaticItem(ref s) => {
742+
clean::StaticItem(ref s) | clean::ForeignStaticItem(ref s) => {
711743
struct Initializer<'self>(&'self str);
712744
impl<'self> fmt::Default for Initializer<'self> {
713745
fn fmt(s: &Initializer<'self>, f: &mut fmt::Formatter) {
746+
if s.len() == 0 { return; }
747+
write!(f.buf, "<code> = </code>");
714748
let tag = if s.contains("\n") { "pre" } else { "code" };
715749
write!(f.buf, "<{tag}>{}</{tag}>",
716750
s.as_slice(), tag=tag);
@@ -719,7 +753,7 @@ fn item_module(w: &mut io::Writer, cx: &Context,
719753

720754
write!(w, "
721755
<tr>
722-
<td><code>{}static {}: {} = </code>{}</td>
756+
<td><code>{}static {}: {}</code>{}</td>
723757
<td class='docblock'>{}&nbsp;</td>
724758
</tr>
725759
",
@@ -980,11 +1014,12 @@ fn render_struct(w: &mut io::Writer, it: &clean::Item,
9801014
for field in fields.iter() {
9811015
match field.inner {
9821016
clean::StructFieldItem(ref ty) => {
983-
write!(w, " {}{}: {},\n{}",
1017+
write!(w, " {}<a name='field.{name}'>{name}</a>: \
1018+
{},\n{}",
9841019
VisSpace(field.visibility),
985-
field.name.get_ref().as_slice(),
9861020
ty.type_,
987-
tab);
1021+
tab,
1022+
name = field.name.get_ref().as_slice());
9881023
}
9891024
_ => unreachable!()
9901025
}
@@ -1170,3 +1205,12 @@ fn item_variant(w: &mut io::Writer, cx: &Context, it: &clean::Item) {
11701205
*cx.current.last(),
11711206
it.name.get_ref().as_slice());
11721207
}
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+
}

branches/try/src/librustdoc/html/static/main.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,18 @@ a {
269269
float: left;
270270
padding: 20px;
271271
}
272+
273+
.stability {
274+
border-left: 5px solid #000;
275+
border-radius: 3px;
276+
padding: 0 3px;
277+
float: right;
278+
background: #fff;
279+
text-transform: lowercase;
280+
}
281+
.stability.Deprecated { border-color: #D60027; color: #880017; }
282+
.stability.Experimental { border-color: #EC5315; color: #a53c0e; }
283+
.stability.Unstable { border-color: #FFD700; color: #b39800; }
284+
.stability.Stable { border-color: #AEC516; color: #7c8b10; }
285+
.stability.Frozen { border-color: #009431; color: #007726; }
286+
.stability.Locked { border-color: #0084B6; color: #00668c; }

0 commit comments

Comments
 (0)