Skip to content

Commit 8922264

Browse files
committed
Remove match checks in rustdoc
1 parent 9f59131 commit 8922264

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/rustdoc/attr_pass.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ fn fold_enum(
145145
{
146146
variants: do par::map(doc.variants) |variant| {
147147
let desc = do astsrv::exec(srv) |ctxt| {
148-
match check ctxt.ast_map.get(doc_id) {
148+
match ctxt.ast_map.get(doc_id) {
149149
ast_map::node_item(@{
150150
node: ast::item_enum(enum_definition, _), _
151151
}, _) => {
@@ -156,6 +156,8 @@ fn fold_enum(
156156

157157
attr_parser::parse_desc(ast_variant.node.attrs)
158158
}
159+
_ => fail #fmt("Enum variant %s has id that's not bound \
160+
to an enum item", variant.name)
159161
}
160162
};
161163

src/rustdoc/tystr_pass.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn fold_fn(
4747

4848
fn get_fn_sig(srv: astsrv::srv, fn_id: doc::ast_id) -> option<~str> {
4949
do astsrv::exec(srv) |ctxt| {
50-
match check ctxt.ast_map.get(fn_id) {
50+
match ctxt.ast_map.get(fn_id) {
5151
ast_map::node_item(@{
5252
ident: ident,
5353
node: ast::item_fn(decl, tys, _), _
@@ -58,6 +58,7 @@ fn get_fn_sig(srv: astsrv::srv, fn_id: doc::ast_id) -> option<~str> {
5858
}, _, _) => {
5959
some(pprust::fun_to_str(decl, ident, tys, extract::interner()))
6060
}
61+
_ => fail ~"get_fn_sig: fn_id not bound to a fn item"
6162
}
6263
}
6364
}
@@ -82,12 +83,13 @@ fn fold_const(
8283

8384
{
8485
sig: some(do astsrv::exec(srv) |ctxt| {
85-
match check ctxt.ast_map.get(doc.id()) {
86+
match ctxt.ast_map.get(doc.id()) {
8687
ast_map::node_item(@{
8788
node: ast::item_const(ty, _), _
8889
}, _) => {
8990
pprust::ty_to_str(ty, extract::interner())
9091
}
92+
_ => fail ~"fold_const: id not bound to a const item"
9193
}
9294
})
9395
with doc
@@ -110,7 +112,7 @@ fn fold_enum(
110112
{
111113
variants: do par::map(doc.variants) |variant| {
112114
let sig = do astsrv::exec(srv) |ctxt| {
113-
match check ctxt.ast_map.get(doc_id) {
115+
match ctxt.ast_map.get(doc_id) {
114116
ast_map::node_item(@{
115117
node: ast::item_enum(enum_definition, _), _
116118
}, _) => {
@@ -121,6 +123,7 @@ fn fold_enum(
121123

122124
pprust::variant_to_str(ast_variant, extract::interner())
123125
}
126+
_ => fail ~"enum variant not bound to an enum item"
124127
}
125128
};
126129

@@ -168,11 +171,11 @@ fn get_method_sig(
168171
method_name: ~str
169172
) -> option<~str> {
170173
do astsrv::exec(srv) |ctxt| {
171-
match check ctxt.ast_map.get(item_id) {
174+
match ctxt.ast_map.get(item_id) {
172175
ast_map::node_item(@{
173176
node: ast::item_trait(_, _, methods), _
174177
}, _) => {
175-
match check vec::find(methods, |method| {
178+
match vec::find(methods, |method| {
176179
match method {
177180
ast::required(ty_m) => to_str(ty_m.ident) == method_name,
178181
ast::provided(m) => to_str(m.ident) == method_name,
@@ -198,12 +201,13 @@ fn get_method_sig(
198201
}
199202
}
200203
}
204+
_ => fail ~"method not found"
201205
}
202206
}
203207
ast_map::node_item(@{
204208
node: ast::item_impl(_, _, _, methods), _
205209
}, _) => {
206-
match check vec::find(methods, |method| {
210+
match vec::find(methods, |method| {
207211
to_str(method.ident) == method_name
208212
}) {
209213
some(method) => {
@@ -214,8 +218,10 @@ fn get_method_sig(
214218
extract::interner()
215219
))
216220
}
221+
none => fail ~"method not found"
217222
}
218223
}
224+
_ => fail ~"get_method_sig: item ID not bound to trait or impl"
219225
}
220226
}
221227
}

0 commit comments

Comments
 (0)