Skip to content

Commit 34508dc

Browse files
committed
---
yaml --- r: 23972 b: refs/heads/master c: be162da h: refs/heads/master v: v3
1 parent 723bad9 commit 34508dc

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 2018cd912cc98e0c3555b3ca827ad504fe02c3d4
2+
refs/heads/master: be162da9614624f8fd5f5d03909bb99c6ab2c647
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/libcore/repr.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,8 @@ fn test_repr2() {
500500
enum EnumVisitState {
501501
PreVariant, // We're before the variant we're interested in.
502502
InVariant, // We're inside the variant we're interested in.
503-
PostVariant // We're after the variant we're interested in.
503+
PostVariant, // We're after the variant we're interested in.
504+
Newtype // This is a newtyped enum.
504505
}
505506

506507
impl EnumVisitState : cmp::Eq {
@@ -859,13 +860,14 @@ impl ReprPrinterWrapper : TyVisitor {
859860

860861
// Enums
861862

862-
fn visit_enter_enum(_n_variants: uint, sz: uint, align: uint) -> bool {
863+
fn visit_enter_enum(n_variants: uint, sz: uint, align: uint) -> bool {
863864
unsafe {
864865
self.printer.align(align);
865866

866867
// Write in the location of the end of this enum.
867868
let end_ptr = transmute(self.printer.ptr as uint + sz);
868-
let new_state = EnumState { end_ptr: end_ptr, state: PreVariant };
869+
let state = if n_variants == 1 { Newtype } else { PreVariant };
870+
let new_state = EnumState { end_ptr: end_ptr, state: state };
869871
self.printer.enum_stack.push(new_state);
870872

871873
true
@@ -889,21 +891,27 @@ impl ReprPrinterWrapper : TyVisitor {
889891
stack.set_elt(stack.len() - 1, enum_state);
890892
}
891893
}
894+
Newtype => {
895+
self.printer.writer.write_str(name);
896+
}
892897
InVariant | PostVariant => {}
893898
}
894899
true
895900
}
896901
}
897902

898903
fn visit_enum_variant_field(i: uint, inner: *TyDesc) -> bool {
899-
if self.printer.enum_stack.last().state == InVariant {
900-
if i == 0 {
901-
self.printer.writer.write_char('(');
902-
} else {
903-
self.printer.writer.write_str(", ");
904-
}
904+
match self.printer.enum_stack.last().state {
905+
InVariant | Newtype => {
906+
if i == 0 {
907+
self.printer.writer.write_char('(');
908+
} else {
909+
self.printer.writer.write_str(", ");
910+
}
905911

906-
intrinsic::visit_tydesc(inner, self as @TyVisitor);
912+
intrinsic::visit_tydesc(inner, self as @TyVisitor);
913+
}
914+
PreVariant | PostVariant => {}
907915
}
908916
true
909917
}
@@ -920,6 +928,9 @@ impl ReprPrinterWrapper : TyVisitor {
920928
enum_state.state = PostVariant;
921929
stack.set_elt(stack.len() - 1, enum_state);
922930
}
931+
Newtype => {
932+
if n_fields >= 1 { self.printer.writer.write_char(')'); }
933+
}
923934
PreVariant | PostVariant => {}
924935
}
925936
true

0 commit comments

Comments
 (0)