Skip to content

Commit 6655b3c

Browse files
committed
repr: remove trailing {} from unit-like structs
1 parent 874611b commit 6655b3c

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

src/libstd/repr.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,12 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
412412
true
413413
}
414414

415-
fn visit_enter_class(&mut self, name: &str, _n_fields: uint,
415+
fn visit_enter_class(&mut self, name: &str, n_fields: uint,
416416
_sz: uint, _align: uint) -> bool {
417417
self.writer.write(name.as_bytes());
418-
self.writer.write(['{' as u8]);
418+
if n_fields != 0 {
419+
self.writer.write(['{' as u8]);
420+
}
419421
true
420422
}
421423

@@ -431,9 +433,11 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
431433
true
432434
}
433435

434-
fn visit_leave_class(&mut self, _name: &str, _n_fields: uint,
436+
fn visit_leave_class(&mut self, _name: &str, n_fields: uint,
435437
_sz: uint, _align: uint) -> bool {
436-
self.writer.write(['}' as u8]);
438+
if n_fields != 0 {
439+
self.writer.write(['}' as u8]);
440+
}
437441
true
438442
}
439443

@@ -650,5 +654,5 @@ fn test_repr() {
650654
"(10u64, ~\"hello\")");
651655

652656
struct Foo;
653-
exact_test(&(~[Foo, Foo]), "~[repr::test_repr::Foo{}, repr::test_repr::Foo{}]");
657+
exact_test(&(~[Foo, Foo]), "~[repr::test_repr::Foo, repr::test_repr::Foo]");
654658
}

src/libstd/vec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3682,11 +3682,11 @@ mod tests {
36823682

36833683
let xs = ~[Foo, Foo, Foo];
36843684
assert_eq!(fmt!("%?", xs.slice(0, 2).to_owned()),
3685-
~"~[vec::tests::Foo{}, vec::tests::Foo{}]");
3685+
~"~[vec::tests::Foo, vec::tests::Foo]");
36863686
36873687
let xs: [Foo, ..3] = [Foo, Foo, Foo];
36883688
assert_eq!(fmt!("%?", xs.slice(0, 2).to_owned()),
3689-
~"~[vec::tests::Foo{}, vec::tests::Foo{}]");
3689+
~"~[vec::tests::Foo, vec::tests::Foo]");
36903690
cnt = 0;
36913691
for f in xs.iter() {
36923692
assert!(*f == Foo);

src/test/run-pass/ifmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn main() {
2929

3030
// Make sure there's a poly formatter that takes anything
3131
t!(format!("{:?}", 1), "1");
32-
t!(format!("{:?}", A), "A{}");
32+
t!(format!("{:?}", A), "A");
3333
t!(format!("{:?}", ()), "()");
3434
t!(format!("{:?}", @(~1, "foo")), "@(~1, \"foo\")");
3535

0 commit comments

Comments
 (0)