Skip to content

Commit 9801ab6

Browse files
committed
---
yaml --- r: 140681 b: refs/heads/try2 c: cdc266e h: refs/heads/master i: 140679: 0ecb0b6 v: v3
1 parent 602fdf2 commit 9801ab6

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: b01a40d45930f97e83753150dc1b39b26b3b398f
8+
refs/heads/try2: cdc266e47d8ee63a1eaf29c775f2cbc5f3a61bb4
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libsyntax/ext/deriving/iter_bytes.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use ast::{meta_item, item, expr};
11+
use ast::{meta_item, item, expr, and};
1212
use codemap::span;
1313
use ext::base::ext_ctxt;
1414
use ext::build;
@@ -31,7 +31,7 @@ pub fn expand_deriving_iter_bytes(cx: @ext_ctxt,
3131
Literal(Path::new(~[~"bool"])),
3232
Literal(Path::new(~[~"core", ~"to_bytes", ~"Cb"]))
3333
],
34-
ret_ty: nil_ty(),
34+
ret_ty: Literal(Path::new(~[~"bool"])),
3535
const_nonmatching: false,
3636
combine_substructure: iter_bytes_substructure
3737
}
@@ -58,13 +58,11 @@ fn iter_bytes_substructure(cx: @ext_ctxt, span: span, substr: &Substructure) ->
5858
};
5959
let iter_bytes_ident = substr.method_ident;
6060
let call_iterbytes = |thing_expr| {
61-
build::mk_stmt(
62-
cx, span,
63-
build::mk_method_call(cx, span,
64-
thing_expr, iter_bytes_ident,
65-
copy lsb0_f))
61+
build::mk_method_call(cx, span,
62+
thing_expr, iter_bytes_ident,
63+
copy lsb0_f)
6664
};
67-
let mut stmts = ~[];
65+
let mut exprs = ~[];
6866
let fields;
6967
match *substr.fields {
7068
Struct(ref fs) => {
@@ -78,16 +76,22 @@ fn iter_bytes_substructure(cx: @ext_ctxt, span: span, substr: &Substructure) ->
7876
None => build::mk_uint(cx, span, index)
7977
};
8078

81-
stmts.push(call_iterbytes(discriminant));
79+
exprs.push(call_iterbytes(discriminant));
8280

8381
fields = fs;
8482
}
8583
_ => cx.span_bug(span, "Impossible substructure in `deriving(IterBytes)`")
8684
}
8785

8886
for fields.each |&(_, field, _)| {
89-
stmts.push(call_iterbytes(field));
87+
exprs.push(call_iterbytes(field));
9088
}
9189

92-
build::mk_block(cx, span, ~[], stmts, None)
90+
if exprs.len() == 0 {
91+
cx.span_bug(span, "#[deriving(IterBytes)] needs at least one field");
92+
}
93+
94+
do vec::foldl(exprs[0], exprs.slice(1, exprs.len())) |prev, me| {
95+
build::mk_binary(cx, span, and, prev, *me)
96+
}
9397
}

0 commit comments

Comments
 (0)