1
Fork 0

repr: remove trailing {} from unit-like structs

This commit is contained in:
Daniel Micay 2013-08-31 01:28:59 -04:00
parent 874611b348
commit 6655b3c462
3 changed files with 12 additions and 8 deletions

View file

@ -412,10 +412,12 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
true
}
fn visit_enter_class(&mut self, name: &str, _n_fields: uint,
fn visit_enter_class(&mut self, name: &str, n_fields: uint,
_sz: uint, _align: uint) -> bool {
self.writer.write(name.as_bytes());
self.writer.write(['{' as u8]);
if n_fields != 0 {
self.writer.write(['{' as u8]);
}
true
}
@ -431,9 +433,11 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
true
}
fn visit_leave_class(&mut self, _name: &str, _n_fields: uint,
fn visit_leave_class(&mut self, _name: &str, n_fields: uint,
_sz: uint, _align: uint) -> bool {
self.writer.write(['}' as u8]);
if n_fields != 0 {
self.writer.write(['}' as u8]);
}
true
}
@ -650,5 +654,5 @@ fn test_repr() {
"(10u64, ~\"hello\")");
struct Foo;
exact_test(&(~[Foo, Foo]), "~[repr::test_repr::Foo{}, repr::test_repr::Foo{}]");
exact_test(&(~[Foo, Foo]), "~[repr::test_repr::Foo, repr::test_repr::Foo]");
}

View file

@ -3682,11 +3682,11 @@ mod tests {
let xs = ~[Foo, Foo, Foo];
assert_eq!(fmt!("%?", xs.slice(0, 2).to_owned()),
~"~[vec::tests::Foo{}, vec::tests::Foo{}]");
~"~[vec::tests::Foo, vec::tests::Foo]");
let xs: [Foo, ..3] = [Foo, Foo, Foo];
assert_eq!(fmt!("%?", xs.slice(0, 2).to_owned()),
~"~[vec::tests::Foo{}, vec::tests::Foo{}]");
~"~[vec::tests::Foo, vec::tests::Foo]");
cnt = 0;
for f in xs.iter() {
assert!(*f == Foo);

View file

@ -29,7 +29,7 @@ pub fn main() {
// Make sure there's a poly formatter that takes anything
t!(format!("{:?}", 1), "1");
t!(format!("{:?}", A), "A{}");
t!(format!("{:?}", A), "A");
t!(format!("{:?}", ()), "()");
t!(format!("{:?}", @(~1, "foo")), "@(~1, \"foo\")");