Skip to content

Commit 7f32ea8

Browse files
committed
auto merge of #8771 : thestinger/rust/repr, r=catamorphism
2 parents 3ab0561 + 803f941 commit 7f32ea8

13 files changed

+76
-83
lines changed

src/librustc/middle/ty.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3476,18 +3476,18 @@ pub fn type_err_to_str(cx: ctxt, err: &type_err) -> ~str {
34763476
terr_ptr_mutability => ~"pointers differ in mutability",
34773477
terr_ref_mutability => ~"references differ in mutability",
34783478
terr_ty_param_size(values) => {
3479-
fmt!("expected a type with %? type params \
3480-
but found one with %? type params",
3479+
fmt!("expected a type with %u type params \
3480+
but found one with %u type params",
34813481
values.expected, values.found)
34823482
}
34833483
terr_tuple_size(values) => {
3484-
fmt!("expected a tuple with %? elements \
3485-
but found one with %? elements",
3484+
fmt!("expected a tuple with %u elements \
3485+
but found one with %u elements",
34863486
values.expected, values.found)
34873487
}
34883488
terr_record_size(values) => {
3489-
fmt!("expected a record with %? fields \
3490-
but found one with %? fields",
3489+
fmt!("expected a record with %u fields \
3490+
but found one with %u fields",
34913491
values.expected, values.found)
34923492
}
34933493
terr_record_mutability => {

src/libstd/reflect.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -460,16 +460,6 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
460460
true
461461
}
462462

463-
fn visit_var(&self) -> bool {
464-
if ! self.inner.visit_var() { return false; }
465-
true
466-
}
467-
468-
fn visit_var_integral(&self) -> bool {
469-
if ! self.inner.visit_var_integral() { return false; }
470-
true
471-
}
472-
473463
fn visit_param(&self, i: uint) -> bool {
474464
if ! self.inner.visit_param(i) { return false; }
475465
true
@@ -494,11 +484,6 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
494484
true
495485
}
496486

497-
fn visit_constr(&self, inner: *TyDesc) -> bool {
498-
if ! self.inner.visit_constr(inner) { return false; }
499-
true
500-
}
501-
502487
fn visit_closure_ptr(&self, ck: uint) -> bool {
503488
self.align_to::<@fn()>();
504489
if ! self.inner.visit_closure_ptr(ck) { return false; }

src/libstd/repr.rs

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -75,35 +75,50 @@ impl Repr for bool {
7575
}
7676
}
7777

78-
macro_rules! int_repr(($ty:ident) => (impl Repr for $ty {
78+
impl Repr for int {
79+
fn write_repr(&self, writer: @Writer) {
80+
do ::int::to_str_bytes(*self, 10u) |bits| {
81+
writer.write(bits);
82+
}
83+
}
84+
}
85+
86+
macro_rules! int_repr(($ty:ident, $suffix:expr) => (impl Repr for $ty {
7987
fn write_repr(&self, writer: @Writer) {
8088
do ::$ty::to_str_bytes(*self, 10u) |bits| {
8189
writer.write(bits);
90+
writer.write(bytes!($suffix));
8291
}
8392
}
8493
}))
8594

86-
int_repr!(int)
87-
int_repr!(i8)
88-
int_repr!(i16)
89-
int_repr!(i32)
90-
int_repr!(i64)
91-
int_repr!(uint)
92-
int_repr!(u8)
93-
int_repr!(u16)
94-
int_repr!(u32)
95-
int_repr!(u64)
96-
97-
macro_rules! num_repr(($ty:ident) => (impl Repr for $ty {
95+
int_repr!(i8, "i8")
96+
int_repr!(i16, "i16")
97+
int_repr!(i32, "i32")
98+
int_repr!(i64, "i64")
99+
int_repr!(uint, "u")
100+
int_repr!(u8, "u8")
101+
int_repr!(u16, "u16")
102+
int_repr!(u32, "u32")
103+
int_repr!(u64, "u64")
104+
105+
impl Repr for float {
106+
fn write_repr(&self, writer: @Writer) {
107+
let s = self.to_str();
108+
writer.write(s.as_bytes());
109+
}
110+
}
111+
112+
macro_rules! num_repr(($ty:ident, $suffix:expr) => (impl Repr for $ty {
98113
fn write_repr(&self, writer: @Writer) {
99114
let s = self.to_str();
100115
writer.write(s.as_bytes());
116+
writer.write(bytes!($suffix));
101117
}
102118
}))
103119

104-
num_repr!(float)
105-
num_repr!(f32)
106-
num_repr!(f64)
120+
num_repr!(f32, "f32")
121+
num_repr!(f64, "f64")
107122

108123
// New implementation using reflect::MovePtr
109124

@@ -267,12 +282,14 @@ impl TyVisitor for ReprVisitor {
267282
self.write_escaped_slice(*s);
268283
}
269284
}
285+
270286
fn visit_estr_uniq(&self) -> bool {
271287
do self.get::<~str> |s| {
272288
self.writer.write_char('~');
273289
self.write_escaped_slice(*s);
274290
}
275291
}
292+
276293
fn visit_estr_slice(&self) -> bool {
277294
do self.get::<&str> |s| {
278295
self.write_escaped_slice(*s);
@@ -307,13 +324,23 @@ impl TyVisitor for ReprVisitor {
307324
}
308325
}
309326

327+
#[cfg(stage0)]
310328
fn visit_ptr(&self, _mtbl: uint, _inner: *TyDesc) -> bool {
311329
do self.get::<*c_void> |p| {
312330
self.writer.write_str(fmt!("(0x%x as *())",
313331
*p as uint));
314332
}
315333
}
316334

335+
#[cfg(not(stage0))]
336+
fn visit_ptr(&self, mtbl: uint, _inner: *TyDesc) -> bool {
337+
do self.get::<*c_void> |p| {
338+
self.writer.write_str(fmt!("(0x%x as *", *p as uint));
339+
self.write_mut_qualifier(mtbl);
340+
self.writer.write_str("())");
341+
}
342+
}
343+
317344
fn visit_rptr(&self, mtbl: uint, inner: *TyDesc) -> bool {
318345
self.writer.write_char('&');
319346
self.write_mut_qualifier(mtbl);
@@ -536,8 +563,6 @@ impl TyVisitor for ReprVisitor {
536563

537564

538565
fn visit_trait(&self) -> bool { true }
539-
fn visit_var(&self) -> bool { true }
540-
fn visit_var_integral(&self) -> bool { true }
541566
fn visit_param(&self, _i: uint) -> bool { true }
542567
fn visit_self(&self) -> bool { true }
543568
fn visit_type(&self) -> bool { true }
@@ -550,9 +575,6 @@ impl TyVisitor for ReprVisitor {
550575
}
551576
}
552577

553-
// Type no longer exists, vestigial function.
554-
fn visit_constr(&self, _inner: *TyDesc) -> bool { fail!(); }
555-
556578
fn visit_closure_ptr(&self, _ck: uint) -> bool { true }
557579
}
558580

@@ -598,11 +620,14 @@ fn test_repr() {
598620
exact_test(&(&mut x), "&mut 10");
599621
exact_test(&(@mut [1, 2]), "@mut [1, 2]");
600622

623+
exact_test(&(0 as *()), "(0x0 as *())");
624+
exact_test(&(0 as *mut ()), "(0x0 as *mut ())");
625+
601626
exact_test(&(1,), "(1,)");
602627
exact_test(&(@[1,2,3,4,5,6,7,8]),
603628
"@[1, 2, 3, 4, 5, 6, 7, 8]");
604629
exact_test(&(@[1u8,2u8,3u8,4u8]),
605-
"@[1, 2, 3, 4]");
630+
"@[1u8, 2u8, 3u8, 4u8]");
606631
exact_test(&(@["hi", "there"]),
607632
"@[\"hi\", \"there\"]");
608633
exact_test(&(~["hi", "there"]),
@@ -615,14 +640,14 @@ fn test_repr() {
615640
"@{a: 10, b: 1.234}");
616641
exact_test(&(~P{a:10, b:1.234}),
617642
"~{a: 10, b: 1.234}");
618-
exact_test(&(10_u8, ~"hello"),
619-
"(10, ~\"hello\")");
620-
exact_test(&(10_u16, ~"hello"),
621-
"(10, ~\"hello\")");
622-
exact_test(&(10_u32, ~"hello"),
623-
"(10, ~\"hello\")");
624-
exact_test(&(10_u64, ~"hello"),
625-
"(10, ~\"hello\")");
643+
exact_test(&(10u8, ~"hello"),
644+
"(10u8, ~\"hello\")");
645+
exact_test(&(10u16, ~"hello"),
646+
"(10u16, ~\"hello\")");
647+
exact_test(&(10u32, ~"hello"),
648+
"(10u32, ~\"hello\")");
649+
exact_test(&(10u64, ~"hello"),
650+
"(10u64, ~\"hello\")");
626651

627652
struct Foo;
628653
exact_test(&(~[Foo, Foo, Foo]), "~[{}, {}, {}]");

src/libstd/unstable/intrinsics.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,10 @@ pub trait TyVisitor {
161161
n_inputs: uint, retstyle: uint) -> bool;
162162

163163
fn visit_trait(&self) -> bool;
164-
fn visit_var(&self) -> bool;
165-
fn visit_var_integral(&self) -> bool;
166164
fn visit_param(&self, i: uint) -> bool;
167165
fn visit_self(&self) -> bool;
168166
fn visit_type(&self) -> bool;
169167
fn visit_opaque_box(&self) -> bool;
170-
fn visit_constr(&self, inner: *TyDesc) -> bool;
171168
fn visit_closure_ptr(&self, ck: uint) -> bool;
172169
}
173170

src/libstd/vec.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ And much, much more.
5959
#[warn(non_camel_case_types)];
6060

6161
use cast;
62-
use clone::Clone;
62+
use clone::{Clone, DeepClone};
6363
use container::{Container, Mutable};
6464
use cmp::{Eq, TotalOrd, Ordering, Less, Equal, Greater};
6565
use cmp;
@@ -2199,13 +2199,20 @@ pub mod bytes {
21992199
}
22002200
}
22012201

2202-
impl<A:Clone> Clone for ~[A] {
2202+
impl<A: Clone> Clone for ~[A] {
22032203
#[inline]
22042204
fn clone(&self) -> ~[A] {
22052205
self.iter().map(|item| item.clone()).collect()
22062206
}
22072207
}
22082208

2209+
impl<A: DeepClone> DeepClone for ~[A] {
2210+
#[inline]
2211+
fn deep_clone(&self) -> ~[A] {
2212+
self.iter().map(|item| item.deep_clone()).collect()
2213+
}
2214+
}
2215+
22092216
// This works because every lifetime is a sub-lifetime of 'static
22102217
impl<'self, A> Zero for &'self [A] {
22112218
fn zero() -> &'self [A] { &'self [] }

src/test/run-pass/fixed_length_vec_glue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ pub fn main() {
1616
let arr = [1,2,3];
1717
let struc = Struc {a: 13u8, b: arr, c: 42};
1818
let s = sys::log_str(&struc);
19-
assert_eq!(s, ~"{a: 13, b: [1, 2, 3], c: 42}");
19+
assert_eq!(s, ~"{a: 13u8, b: [1, 2, 3], c: 42}");
2020
}

src/test/run-pass/log-knows-the-names-of-variants-in-std.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn check_log<T>(exp: ~str, v: T) {
2525

2626
pub fn main() {
2727
let x = list::from_vec([a(22u), b(~"hi")]);
28-
let exp = ~"@Cons(a(22), @Cons(b(~\"hi\"), @Nil))";
28+
let exp = ~"@Cons(a(22u), @Cons(b(~\"hi\"), @Nil))";
2929
let act = fmt!("%?", x);
3030
assert!(act == exp);
3131
check_log(exp, x);

src/test/run-pass/log-knows-the-names-of-variants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ enum bar {
1919
}
2020

2121
pub fn main() {
22-
assert_eq!(~"a(22)", fmt!("%?", a(22u)));
22+
assert_eq!(~"a(22u)", fmt!("%?", a(22u)));
2323
assert_eq!(~"b(~\"hi\")", fmt!("%?", b(~"hi")));
2424
assert_eq!(~"c", fmt!("%?", c));
2525
assert_eq!(~"d", fmt!("%?", d));

src/test/run-pass/rec-align-u32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ pub fn main() {
6464
// because `inner`s alignment was 4.
6565
assert_eq!(sys::size_of::<Outer>(), m::size());
6666

67-
assert_eq!(y, ~"{c8: 22, t: {c64: 44}}");
67+
assert_eq!(y, ~"{c8: 22u8, t: {c64: 44u32}}");
6868
}
6969
}

src/test/run-pass/rec-align-u64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,6 @@ pub fn main() {
8686
// because `Inner`s alignment was 4.
8787
assert_eq!(sys::size_of::<Outer>(), m::m::size());
8888

89-
assert_eq!(y, ~"{c8: 22, t: {c64: 44}}");
89+
assert_eq!(y, ~"{c8: 22u8, t: {c64: 44u64}}");
9090
}
9191
}

src/test/run-pass/reflect-visit-data.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -436,16 +436,6 @@ impl<V:TyVisitor + movable_ptr> TyVisitor for ptr_visit_adaptor<V> {
436436
true
437437
}
438438

439-
fn visit_var(&self) -> bool {
440-
if ! self.inner.visit_var() { return false; }
441-
true
442-
}
443-
444-
fn visit_var_integral(&self) -> bool {
445-
if ! self.inner.visit_var_integral() { return false; }
446-
true
447-
}
448-
449439
fn visit_param(&self, i: uint) -> bool {
450440
if ! self.inner.visit_param(i) { return false; }
451441
true
@@ -470,11 +460,6 @@ impl<V:TyVisitor + movable_ptr> TyVisitor for ptr_visit_adaptor<V> {
470460
true
471461
}
472462

473-
fn visit_constr(&self, inner: *TyDesc) -> bool {
474-
if ! self.inner.visit_constr(inner) { return false; }
475-
true
476-
}
477-
478463
fn visit_closure_ptr(&self, ck: uint) -> bool {
479464
self.align_to::<@fn()>();
480465
if ! self.inner.visit_closure_ptr(ck) { return false; }
@@ -633,13 +618,10 @@ impl TyVisitor for my_visitor {
633618

634619

635620
fn visit_trait(&self) -> bool { true }
636-
fn visit_var(&self) -> bool { true }
637-
fn visit_var_integral(&self) -> bool { true }
638621
fn visit_param(&self, _i: uint) -> bool { true }
639622
fn visit_self(&self) -> bool { true }
640623
fn visit_type(&self) -> bool { true }
641624
fn visit_opaque_box(&self) -> bool { true }
642-
fn visit_constr(&self, _inner: *TyDesc) -> bool { true }
643625
fn visit_closure_ptr(&self, _ck: uint) -> bool { true }
644626
}
645627

src/test/run-pass/reflect-visit-type.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,10 @@ impl TyVisitor for MyVisitor {
144144

145145

146146
fn visit_trait(&self) -> bool { true }
147-
fn visit_var(&self) -> bool { true }
148-
fn visit_var_integral(&self) -> bool { true }
149147
fn visit_param(&self, _i: uint) -> bool { true }
150148
fn visit_self(&self) -> bool { true }
151149
fn visit_type(&self) -> bool { true }
152150
fn visit_opaque_box(&self) -> bool { true }
153-
fn visit_constr(&self, _inner: *TyDesc) -> bool { true }
154151
fn visit_closure_ptr(&self, _ck: uint) -> bool { true }
155152
}
156153

src/test/run-pass/tag-align-shape.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ pub fn main() {
2121
let x = t_rec {c8: 22u8, t: a_tag(44u64)};
2222
let y = fmt!("%?", x);
2323
info!("y = %s", y);
24-
assert_eq!(y, ~"{c8: 22, t: a_tag(44)}");
24+
assert_eq!(y, ~"{c8: 22u8, t: a_tag(44u64)}");
2525
}

0 commit comments

Comments
 (0)