Skip to content

Commit a114443

Browse files
committed
---
yaml --- r: 30572 b: refs/heads/incoming c: be162da h: refs/heads/master v: v3
1 parent aa0ec6d commit a114443

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
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: 2018cd912cc98e0c3555b3ca827ad504fe02c3d4
9+
refs/heads/incoming: be162da9614624f8fd5f5d03909bb99c6ab2c647
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

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