Skip to content

Commit 0c1026f

Browse files
committed
---
yaml --- r: 58298 b: refs/heads/auto c: cdc266e h: refs/heads/master v: v3
1 parent eb48f53 commit 0c1026f

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
@@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: b01a40d45930f97e83753150dc1b39b26b3b398f
17+
refs/heads/auto: cdc266e47d8ee63a1eaf29c775f2cbc5f3a61bb4
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1919
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c

branches/auto/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)