Skip to content

Commit e0f5f25

Browse files
committed
rustdoc: Don't print struct drop blocks
1 parent 38595e6 commit e0f5f25

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/rustdoc/tystr_pass.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ fn fold_struct(
333333
sig: do astsrv::exec(srv) |ctxt| {
334334
match ctxt.ast_map.get(doc.id()) {
335335
ast_map::node_item(item, _) => {
336+
let item = strip_struct_drop_block(item);
336337
Some(pprust::item_to_str(item,
337338
extract::interner()))
338339
}
@@ -343,12 +344,39 @@ fn fold_struct(
343344
}
344345
}
345346

347+
/// Removes the drop block from structs so that they aren't displayed
348+
/// as part of the type
349+
fn strip_struct_drop_block(item: @ast::item) -> @ast::item {
350+
let node = match item.node {
351+
ast::item_class(def, tys) => {
352+
let def = @{
353+
dtor: None,
354+
.. *def
355+
};
356+
ast::item_class(def, tys)
357+
}
358+
_ => fail ~"not a struct"
359+
};
360+
361+
@{
362+
node: node,
363+
.. *item
364+
}
365+
}
366+
346367
#[test]
347368
fn should_add_struct_defs() {
348369
let doc = test::mk_doc(~"struct S { field: () }");
349370
assert doc.cratemod().structs()[0].sig.get().contains("struct S {");
350371
}
351372

373+
#[test]
374+
fn should_not_serialize_struct_drop_blocks() {
375+
// All we care about are the fields
376+
let doc = test::mk_doc(~"struct S { field: (), drop { } }");
377+
assert !doc.cratemod().structs()[0].sig.get().contains("drop");
378+
}
379+
352380
#[cfg(test)]
353381
mod test {
354382
fn mk_doc(source: ~str) -> doc::Doc {

0 commit comments

Comments
 (0)