Skip to content

Commit 9b5d523

Browse files
committed
auto merge of #7683 : alexcrichton/rust/issue-7625, r=thestinger
Closes #7625
2 parents e7040e8 + 6d4d2c9 commit 9b5d523

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/libstd/repr.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,13 @@ impl ReprVisitor {
206206
inner: *TyDesc)
207207
-> bool {
208208
let mut p = ptr;
209-
let end = ptr::offset(p, len);
210209
let (sz, al) = unsafe { ((*inner).size, (*inner).align) };
211210
self.writer.write_char('[');
212211
let mut first = true;
213-
while (p as uint) < (end as uint) {
212+
let mut left = len;
213+
// unit structs have 0 size, and don't loop forever.
214+
let dec = if sz == 0 {1} else {sz};
215+
while left > 0 {
214216
if first {
215217
first = false;
216218
} else {
@@ -219,6 +221,7 @@ impl ReprVisitor {
219221
self.write_mut_qualifier(mtbl);
220222
self.visit_ptr_inner(p as *c_void, inner);
221223
p = align(ptr::offset(p, sz) as uint, al) as *u8;
224+
left -= dec;
222225
}
223226
self.writer.write_char(']');
224227
true
@@ -635,4 +638,7 @@ fn test_repr() {
635638
"(10, ~\"hello\")");
636639
exact_test(&(10_u64, ~"hello"),
637640
"(10, ~\"hello\")");
641+
642+
struct Foo;
643+
exact_test(&(~[Foo, Foo, Foo]), "~[{}, {}, {}]");
638644
}

0 commit comments

Comments
 (0)