Skip to content

Commit a300c31

Browse files
committed
---
yaml --- r: 10975 b: refs/heads/master c: 2b67de0 h: refs/heads/master i: 10973: dd672e2 10971: 8304360 10967: 2956278 10959: 6178cc4 10943: 1e9112f v: v3
1 parent 199c455 commit a300c31

File tree

13 files changed

+259
-14
lines changed

13 files changed

+259
-14
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: ae0d49aa06c1ed73320f32896710b6d015bea9c0
2+
refs/heads/master: 2b67de06c8f0436563284e01fe0e925f2ba225b4
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/comp/syntax/print/pprust.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ fn stmt_to_str(s: ast::stmt) -> str { be to_str(s, print_stmt); }
9090

9191
fn item_to_str(i: @ast::item) -> str { be to_str(i, print_item); }
9292

93+
fn typarams_to_str(tps: [ast::ty_param]) -> str {
94+
be to_str(tps, print_type_params)
95+
}
96+
9397
fn path_to_str(&&p: @ast::path) -> str {
9498
be to_str(p, bind print_path(_, _, false));
9599
}
@@ -1253,7 +1257,7 @@ fn print_bounds(s: ps, bounds: @[ast::ty_param_bound]) {
12531257
}
12541258
}
12551259

1256-
fn print_type_params(s: ps, params: [ast::ty_param]) {
1260+
fn print_type_params(s: ps, &&params: [ast::ty_param]) {
12571261
if vec::len(params) > 0u {
12581262
word(s.s, "<");
12591263
fn printParam(s: ps, param: ast::ty_param) {

trunk/src/rustdoc/attr_parser.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import core::tuple;
1111

1212
export crate_attrs, mod_attrs, fn_attrs, arg_attrs,
1313
const_attrs, enum_attrs, variant_attrs, res_attrs,
14-
iface_attrs, method_attrs, impl_attrs;
14+
iface_attrs, method_attrs, impl_attrs, type_attrs;
1515
export parse_crate, parse_mod, parse_fn, parse_const,
1616
parse_enum, parse_variant, parse_res,
17-
parse_iface, parse_method, parse_impl;
17+
parse_iface, parse_method, parse_impl, parse_type;
1818

1919
type crate_attrs = {
2020
name: option<str>
@@ -70,6 +70,11 @@ type impl_attrs = {
7070

7171
type method_attrs = fn_attrs;
7272

73+
type type_attrs = {
74+
brief: option<str>,
75+
desc: option<str>
76+
};
77+
7378
#[cfg(test)]
7479
mod test {
7580

@@ -507,4 +512,8 @@ fn parse_method(attrs: [ast::attribute]) -> method_attrs {
507512

508513
fn parse_impl(attrs: [ast::attribute]) -> impl_attrs {
509514
parse_basic(attrs)
515+
}
516+
517+
fn parse_type(attrs: [ast::attribute]) -> type_attrs {
518+
parse_basic(attrs)
510519
}

trunk/src/rustdoc/attr_pass.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ fn run(
2727
fold_enum: fold_enum,
2828
fold_res: fold_res,
2929
fold_iface: fold_iface,
30-
fold_impl: fold_impl
30+
fold_impl: fold_impl,
31+
fold_type: fold_type
3132
with *fold::default_seq_fold(srv)
3233
});
3334
fold.fold_crate(fold, doc)
@@ -449,6 +450,30 @@ fn should_extract_impl_method_docs() {
449450
assert doc.topmod.impls()[0].methods[0].failure == some("failure");
450451
}
451452

453+
fn fold_type(
454+
fold: fold::fold<astsrv::srv>,
455+
doc: doc::tydoc
456+
) -> doc::tydoc {
457+
let srv = fold.ctxt;
458+
let doc = fold::default_seq_fold_type(fold, doc);
459+
let attrs = parse_item_attrs(srv, doc.id, attr_parser::parse_type);
460+
461+
{
462+
brief: attrs.brief,
463+
desc: attrs.desc
464+
with doc
465+
}
466+
}
467+
468+
#[test]
469+
fn should_extract_type_docs() {
470+
let doc = test::mk_doc(
471+
"#[doc(brief = \"brief\", desc = \"desc\")]\
472+
type t = int;");
473+
assert doc.topmod.types()[0].brief == some("brief");
474+
assert doc.topmod.types()[0].desc == some("desc");
475+
}
476+
452477
#[cfg(test)]
453478
mod test {
454479
fn mk_doc(source: str) -> doc::cratedoc {

trunk/src/rustdoc/desc_pass.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ fn run(
2222
fold_enum: fold_enum,
2323
fold_res: fold_res,
2424
fold_iface: fold_iface,
25-
fold_impl: fold_impl
25+
fold_impl: fold_impl,
26+
fold_type: fold_type
2627
with *fold::default_seq_fold(op)
2728
});
2829
fold.fold_crate(fold, doc)
@@ -140,6 +141,14 @@ fn fold_impl(fold: fold::fold<op>, doc: doc::impldoc) -> doc::impldoc {
140141
}
141142
}
142143

144+
fn fold_type(fold: fold::fold<op>, doc: doc::tydoc) -> doc::tydoc {
145+
{
146+
brief: maybe_apply_op(fold.ctxt, doc.brief),
147+
desc: maybe_apply_op(fold.ctxt, doc.desc)
148+
with doc
149+
}
150+
}
151+
143152
#[test]
144153
fn should_execute_op_on_enum_brief() {
145154
let doc = test::mk_doc("#[doc(brief = \" a \")] enum a { b }");
@@ -274,6 +283,21 @@ fn should_execute_op_on_impl_method_failure_condition() {
274283
assert doc.topmod.impls()[0].methods[0].failure == some("a");
275284
}
276285

286+
287+
#[test]
288+
fn should_execute_op_on_type_brief() {
289+
let doc = test::mk_doc(
290+
"#[doc(brief = \" a \")] type t = int;");
291+
assert doc.topmod.types()[0].brief == some("a");
292+
}
293+
294+
#[test]
295+
fn should_execute_op_on_type_desc() {
296+
let doc = test::mk_doc(
297+
"#[doc(desc = \" a \")] type t = int;");
298+
assert doc.topmod.types()[0].desc == some("a");
299+
}
300+
277301
#[cfg(test)]
278302
mod test {
279303
fn mk_doc(source: str) -> doc::cratedoc {

trunk/src/rustdoc/desc_to_brief_pass.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ fn run(
2424
fold_enum: fold_enum,
2525
fold_res: fold_res,
2626
fold_iface: fold_iface,
27-
fold_impl: fold_impl
27+
fold_impl: fold_impl,
28+
fold_type: fold_type
2829
with *fold::default_seq_fold(())
2930
});
3031
fold.fold_crate(fold, doc)
@@ -125,6 +126,17 @@ fn fold_impl(fold: fold::fold<()>, doc: doc::impldoc) -> doc::impldoc {
125126
}
126127
}
127128

129+
fn fold_type(fold: fold::fold<()>, doc: doc::tydoc) -> doc::tydoc {
130+
let doc = fold::default_seq_fold_type(fold, doc);
131+
let (brief, desc) = modify(doc.brief, doc.desc);
132+
133+
{
134+
brief: brief,
135+
desc: desc
136+
with doc
137+
}
138+
}
139+
128140
#[test]
129141
fn should_promote_mod_desc() {
130142
let doc = test::mk_doc("#[doc(desc = \"desc\")] mod m { }");
@@ -191,6 +203,13 @@ fn should_promote_impl_method_desc() {
191203
assert doc.topmod.impls()[0].methods[0].desc == none;
192204
}
193205

206+
#[test]
207+
fn should_promote_type_desc() {
208+
let doc = test::mk_doc("#[doc(desc = \"desc\")] type t = int;");
209+
assert doc.topmod.types()[0].brief == some("desc");
210+
assert doc.topmod.types()[0].desc == none;
211+
}
212+
194213
#[cfg(test)]
195214
mod test {
196215
fn mk_doc(source: str) -> doc::cratedoc {

trunk/src/rustdoc/doc.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ enum itemtag {
1313
enumtag(enumdoc),
1414
restag(resdoc),
1515
ifacetag(ifacedoc),
16-
impltag(impldoc)
16+
impltag(impldoc),
17+
tytag(tydoc)
1718
}
1819

1920
type moddoc = {
@@ -107,6 +108,14 @@ type impldoc = {
107108
methods: [methoddoc]
108109
};
109110

111+
type tydoc = {
112+
id: ast_id,
113+
name: str,
114+
brief: option<str>,
115+
desc: option<str>,
116+
sig: option<str>
117+
};
118+
110119
#[doc = "Some helper methods on moddoc, mostly for testing"]
111120
impl util for moddoc {
112121

@@ -172,6 +181,15 @@ impl util for moddoc {
172181
}
173182
}
174183
}
184+
185+
fn types() -> [tydoc] {
186+
vec::filter_map(*self.items) {|itemtag|
187+
alt itemtag {
188+
tytag(tydoc) { some(tydoc) }
189+
_ { none }
190+
}
191+
}
192+
}
175193
}
176194

177195
#[doc = "Helper methods on itemtag"]
@@ -185,6 +203,7 @@ impl util for itemtag {
185203
doc::restag({name, _}) { name }
186204
doc::ifacetag({name, _}) { name }
187205
doc::impltag({name, _}) { name }
206+
doc::tytag({name, _}) { name }
188207
}
189208
}
190209
}

trunk/src/rustdoc/extract.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ fn moddoc_from_mod(
8080
impldoc_from_impl(methods, item.ident, item.id)
8181
))
8282
}
83+
ast::item_ty(_, _) {
84+
some(doc::tytag(
85+
tydoc_from_ty(item.ident, item.id)
86+
))
87+
}
8388
_ {
8489
none
8590
}
@@ -317,6 +322,25 @@ fn should_extract_impl_method_args() {
317322
assert doc.topmod.impls()[0].methods[0].args[0].name == "a";
318323
}
319324

325+
fn tydoc_from_ty(
326+
name: str,
327+
id: ast::node_id
328+
) -> doc::tydoc {
329+
{
330+
id: id,
331+
name: name,
332+
brief: none,
333+
desc: none,
334+
sig: none
335+
}
336+
}
337+
338+
#[test]
339+
fn should_extract_tys() {
340+
let doc = test::mk_doc("type a = int;");
341+
assert doc.topmod.types()[0].name == "a";
342+
}
343+
320344
#[cfg(test)]
321345
mod test {
322346

trunk/src/rustdoc/fold.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default_seq_fold_enum;
1212
export default_seq_fold_res;
1313
export default_seq_fold_iface;
1414
export default_seq_fold_impl;
15+
export default_seq_fold_type;
1516

1617
enum fold<T> = t<T>;
1718

@@ -23,6 +24,7 @@ type fold_enum<T> = fn~(fold: fold<T>, doc: doc::enumdoc) -> doc::enumdoc;
2324
type fold_res<T> = fn~(fold: fold<T>, doc: doc::resdoc) -> doc::resdoc;
2425
type fold_iface<T> = fn~(fold: fold<T>, doc: doc::ifacedoc) -> doc::ifacedoc;
2526
type fold_impl<T> = fn~(fold: fold<T>, doc: doc::impldoc) -> doc::impldoc;
27+
type fold_type<T> = fn~(fold: fold<T>, doc: doc::tydoc) -> doc::tydoc;
2628

2729
type t<T> = {
2830
ctxt: T,
@@ -33,7 +35,8 @@ type t<T> = {
3335
fold_enum: fold_enum<T>,
3436
fold_res: fold_res<T>,
3537
fold_iface: fold_iface<T>,
36-
fold_impl: fold_impl<T>
38+
fold_impl: fold_impl<T>,
39+
fold_type: fold_type<T>
3740
};
3841

3942

@@ -48,7 +51,8 @@ fn mk_fold<T:copy>(
4851
fold_enum: fold_enum<T>,
4952
fold_res: fold_res<T>,
5053
fold_iface: fold_iface<T>,
51-
fold_impl: fold_impl<T>
54+
fold_impl: fold_impl<T>,
55+
fold_type: fold_type<T>
5256
) -> fold<T> {
5357
fold({
5458
ctxt: ctxt,
@@ -59,7 +63,8 @@ fn mk_fold<T:copy>(
5963
fold_enum: fold_enum,
6064
fold_res: fold_res,
6165
fold_iface: fold_iface,
62-
fold_impl: fold_impl
66+
fold_impl: fold_impl,
67+
fold_type: fold_type
6368
})
6469
}
6570

@@ -73,7 +78,8 @@ fn default_seq_fold<T:copy>(ctxt: T) -> fold<T> {
7378
{|f, d| default_seq_fold_enum(f, d)},
7479
{|f, d| default_seq_fold_res(f, d)},
7580
{|f, d| default_seq_fold_iface(f, d)},
76-
{|f, d| default_seq_fold_impl(f, d)}
81+
{|f, d| default_seq_fold_impl(f, d)},
82+
{|f, d| default_seq_fold_type(f, d)}
7783
)
7884
}
7985

@@ -114,6 +120,9 @@ fn default_seq_fold_mod<T>(
114120
doc::impltag(impldoc) {
115121
doc::impltag(fold.fold_impl(fold, impldoc))
116122
}
123+
doc::tytag(tydoc) {
124+
doc::tytag(fold.fold_type(fold, tydoc))
125+
}
117126
}
118127
}
119128
with doc
@@ -162,6 +171,13 @@ fn default_seq_fold_impl<T>(
162171
doc
163172
}
164173

174+
fn default_seq_fold_type<T>(
175+
_fold: fold<T>,
176+
doc: doc::tydoc
177+
) -> doc::tydoc {
178+
doc
179+
}
180+
165181
#[test]
166182
fn default_fold_should_produce_same_doc() {
167183
let source = "mod a { fn b() { } mod c { fn d() { } } }";

0 commit comments

Comments
 (0)