提交 6d4907a7 编写于 作者: T Tim Chevalier

testsuite: Eliminate uses of structural records from most run-pass tests

Except the pipes tests (that needs a snapshot)
上级 413be829
......@@ -13,11 +13,12 @@
use dvec::DVec;
type entry<A,B> = {key: A, value: B};
struct alist<A,B> { eq_fn: fn@(A,A) -> bool, data: DVec<entry<A,B>> }
struct Entry<A,B> {key: A, value: B}
struct alist<A,B> { eq_fn: fn@(A,A) -> bool, data: DVec<Entry<A,B>> }
fn alist_add<A: Copy, B: Copy>(lst: alist<A,B>, k: A, v: B) {
lst.data.push({key:k, value:v});
lst.data.push(Entry{key:k, value:v});
}
fn alist_get<A: Copy, B: Copy>(lst: alist<A,B>, k: A) -> B {
......
......@@ -14,8 +14,10 @@
#[crate_type = "lib"];
#[legacy_exports];
fn structural() -> { name: ~str, val: int } {
{ name: ~"crateresolve5", val: 10 }
struct NameVal { name: ~str, val: int }
fn struct_nameval() -> NameVal {
NameVal { name: ~"crateresolve5", val: 10 }
}
enum e {
......
......@@ -14,8 +14,9 @@
#[crate_type = "lib"];
#[legacy_exports];
fn structural() -> { name: ~str, val: int } {
{ name: ~"crateresolve5", val: 10 }
struct NameVal { name: ~str, val: int }
fn struct_nameval() -> NameVal {
NameVal { name: ~"crateresolve5", val: 10 }
}
enum e {
......
......@@ -14,10 +14,10 @@
enum sty { ty_nil, }
type raw_t = {struct_: sty, cname: Option<~str>, hash: uint};
struct RawT {struct_: sty, cname: Option<~str>, hash: uint}
fn mk_raw_ty(st: sty, cname: Option<~str>) -> raw_t {
return {struct_: st, cname: cname, hash: 0u};
fn mk_raw_ty(st: sty, cname: Option<~str>) -> RawT {
return RawT {struct_: st, cname: cname, hash: 0u};
}
fn main() { mk_raw_ty(ty_nil, None::<~str>); }
......@@ -8,18 +8,18 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
type pair<A,B> = {
struct Pair<A,B> {
a: A, b: B
};
}
enum rec<A> = _rec<A>;
type _rec<A> = {
enum RecEnum<A> = Rec<A>;
struct Rec<A> {
val: A,
mut rec: Option<@rec<A>>
};
mut rec: Option<@RecEnum<A>>
}
fn make_cycle<A:Copy>(a: A) {
let g: @rec<A> = @rec({val: a, mut rec: None});
let g: @RecEnum<A> = @RecEnum(Rec {val: a, mut rec: None});
g.rec = Some(g);
}
......
......@@ -10,8 +10,8 @@
enum option<T> { some(T), none, }
type r<T> = {mut v: ~[option<T>]};
struct R<T> {mut v: ~[option<T>]}
fn f<T>() -> ~[T] { return ~[]; }
fn main() { let r: r<int> = {mut v: ~[]}; r.v = f(); }
fn main() { let r: R<int> = R {mut v: ~[]}; r.v = f(); }
......@@ -8,10 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Pair { mut a: ~int, mut b: ~int }
fn main() {
let x = ~{mut a: ~10, b: ~20};
let x = ~Pair {mut a: ~10, b: ~20};
match x {
~{a: ref mut a, b: ref b} => {
~Pair {a: ref mut a, b: ref b} => {
assert **a == 10; *a = ~30; assert **a == 30;
}
}
......
......@@ -8,9 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct X { x: int }
fn main() {
let x = match 0 {
_ => {
_ => X {
x: 0
}.x
};
......
......@@ -8,9 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct X { x: int }
fn main() {
let x = match 0 {
_ => {
_ => X {
x: 0
}
};
......
......@@ -8,18 +8,18 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
type rec = {
struct Rec {
f: int
};
}
fn destructure(x: &mut rec) {
fn destructure(x: &mut Rec) {
match *x {
{f: ref mut f} => *f += 1
Rec {f: ref mut f} => *f += 1
}
}
fn main() {
let mut v = {f: 22};
let mut v = Rec {f: 22};
destructure(&mut v);
assert v.f == 23;
}
......@@ -11,7 +11,9 @@
// xfail-fast
#[legacy_modes];
fn f1(a: {mut x: int}, b: &mut int, -c: int) -> int {
struct X { mut x: int }
fn f1(a: X, b: &mut int, -c: int) -> int {
let r = a.x + *b + c;
a.x = 0;
*b = 10;
......@@ -21,7 +23,7 @@ fn f1(a: {mut x: int}, b: &mut int, -c: int) -> int {
fn f2(a: int, f: fn(int)) -> int { f(1); return a; }
fn main() {
let mut a = {mut x: 1}, b = 2, c = 3;
let mut a = X {mut x: 1}, b = 2, c = 3;
assert (f1(a, &mut b, move c) == 6);
assert (a.x == 0);
assert (b == 10);
......
......@@ -12,9 +12,13 @@
// -*- rust -*-
fn f<T: Copy, U: Copy>(x: T, y: U) -> {a: T, b: U} { return {a: x, b: y}; }
struct Pair<T, U> { a: T, b: U }
struct Triple { x: int, y: int, z: int }
fn f<T: Copy, U: Copy>(x: T, y: U) -> Pair<T, U> { return Pair {a: x, b: y}; }
fn main() {
log(debug, f({x: 3, y: 4, z: 5}, 4).a.x);
log(debug, f(Triple {x: 3, y: 4, z: 5}, 4).a.x);
log(debug, f(5, 6).a);
}
......@@ -8,14 +8,16 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct F { mut f: ~[int] }
fn impure(_v: &[int]) {
}
fn main() {
let x = {mut f: ~[3]};
let x = F {f: ~[3]};
match x {
{f: ref mut v} => {
F {f: ref mut v} => {
impure(*v);
}
}
......
......@@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
type ints = {sum: ~int, values: ~[int]};
struct Ints {sum: ~int, values: ~[int]}
fn add_int(x: &mut ints, v: int) {
fn add_int(x: &mut Ints, v: int) {
*x.sum += v;
let mut values = ~[];
x.values <-> values;
......@@ -18,13 +18,13 @@ fn add_int(x: &mut ints, v: int) {
x.values <-> values;
}
fn iter_ints(x: &ints, f: fn(x: &int) -> bool) {
fn iter_ints(x: &Ints, f: fn(x: &int) -> bool) {
let l = x.values.len();
uint::range(0, l, |i| f(&x.values[i]))
}
fn main() {
let mut ints = ~{sum: ~0, values: ~[]};
let mut ints = ~Ints {sum: ~0, values: ~[]};
add_int(ints, 22);
add_int(ints, 44);
......
......@@ -10,14 +10,16 @@
// exec-env:RUST_POISON_ON_FREE=1
struct F { f: ~int }
fn main() {
let mut x = @{f: ~3};
let mut x = @F {f: ~3};
match x {
@{f: ref b_x} => {
@F {f: ref b_x} => {
assert **b_x == 3;
assert ptr::addr_of(&(*x.f)) == ptr::addr_of(&(**b_x));
x = @{f: ~4};
x = @F {f: ~4};
debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(**b_x)) as uint);
assert **b_x == 3;
......
......@@ -17,12 +17,14 @@ fn borrow(x: &int, f: fn(x: &int)) {
assert before == after;
}
struct F { f: ~int }
fn main() {
let mut x = @{f: ~3};
let mut x = @F {f: ~3};
do borrow(x.f) |b_x| {
assert *b_x == 3;
assert ptr::addr_of(&(*x.f)) == ptr::addr_of(&(*b_x));
x = @{f: ~4};
x = @F {f: ~4};
debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(*b_x)) as uint);
assert *b_x == 3;
......
......@@ -10,14 +10,16 @@
// exec-env:RUST_POISON_ON_FREE=1
struct F { f: ~int }
fn main() {
let mut x = @mut @{f: ~3};
let mut x = @mut @F {f: ~3};
match x {
@@{f: ref b_x} => {
@@F{f: ref b_x} => {
assert **b_x == 3;
assert ptr::addr_of(&(x.f)) == ptr::addr_of(b_x);
*x = @{f: ~4};
*x = @F {f: ~4};
debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(**b_x)) as uint);
assert **b_x == 3;
......
......@@ -17,12 +17,14 @@ fn borrow(x: &int, f: fn(x: &int)) {
assert before == after;
}
struct F { f: ~int }
fn main() {
let mut x = ~mut @{f: ~3};
let mut x = ~mut @F{f: ~3};
do borrow(x.f) |b_x| {
assert *b_x == 3;
assert ptr::addr_of(&(*x.f)) == ptr::addr_of(&(*b_x));
*x = @{f: ~4};
*x = @F{f: ~4};
debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(*b_x)) as uint);
assert *b_x == 3;
......
......@@ -17,12 +17,14 @@ fn borrow(x: &int, f: fn(x: &int)) {
assert before == after;
}
struct F { f: ~int }
fn main() {
let mut x = @{f: ~3};
let mut x = @F {f: ~3};
do borrow((*x).f) |b_x| {
assert *b_x == 3;
assert ptr::addr_of(&(*x.f)) == ptr::addr_of(&(*b_x));
x = @{f: ~4};
x = @F {f: ~4};
debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(*b_x)) as uint);
assert *b_x == 3;
......
......@@ -8,7 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct F { mut f: @G }
struct G { g: ~[int] }
fn main() {
let rec = @{mut f: @{g: ~[1, 2, 3]}};
let rec = @F {mut f: @G {g: ~[1, 2, 3]}};
while rec.f.g.len() == 23 {}
}
......@@ -10,7 +10,9 @@
fn borrow<T>(x: &r/T) -> &r/T {x}
struct Rec { mut f: @int }
fn main() {
let rec = @{mut f: @22};
let rec = @Rec {mut f: @22};
while *borrow(rec.f) == 23 {}
}
......@@ -8,12 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
type foo = {a: int, b: uint};
enum bar { u(@foo), w(int), }
struct Foo {a: int, b: uint}
enum bar { u(@Foo), w(int), }
fn main() {
assert (match u(@{a: 10, b: 40u}) {
u(@{a: a, b: b}) => { a + (b as int) }
assert (match u(@Foo{a: 10, b: 40u}) {
u(@Foo{a: a, b: b}) => { a + (b as int) }
_ => { 66 }
} == 50);
}
......@@ -10,13 +10,13 @@
type box<T: Copy> = {c: @T};
struct Box<T: Copy> {c: @T}
fn unbox<T: Copy>(b: box<T>) -> T { return *b.c; }
fn unbox<T: Copy>(b: Box<T>) -> T { return *b.c; }
fn main() {
let foo: int = 17;
let bfoo: box<int> = {c: @foo};
let bfoo: Box<int> = Box {c: @foo};
debug!("see what's in our box");
assert (unbox::<int>(bfoo) == foo);
}
......@@ -14,11 +14,13 @@
fn foo<T: Copy Const>(x: T) -> T { x }
struct F { field: int }
fn main() {
foo(1);
foo(~"hi");
foo(~[1, 2, 3]);
foo({field: 42});
foo(F{field: 42});
foo((1, 2u));
foo(@1);
foo(~1);
......
......@@ -13,11 +13,16 @@
const y : &[int] = &[1,2,3,4];
const q : int = y[2];
const s : {a: int, b: int} = {a: 10, b: 20};
struct S {a: int, b: int}
const s : S = S {a: 10, b: 20};
const t : int = s.b;
const k : {a: int, b: int, c: {d: int, e: int}} = {a: 10, b: 20, c: {d: 30,
e: 40}};
struct K {a: int, b: int, c: D}
struct D { d: int, e: int }
const k : K = K {a: 10, b: 20, c: D {d: 30,
e: 40}};
const m : int = k.c.e;
fn main() {
......
......@@ -8,13 +8,15 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Pair { a: float, b: float }
struct AnotherPair { x: (i64, i64), y: Pair }
const x : (i32,i32) = (0xfeedf00dd,0xca11ab1e);
const y : { x: (i64, i64),
y: { a: float,
b: float } } = { x: (0xf0f0f0f0_f0f0f0f0,
0xabababab_abababab),
y: { a: 3.14159265358979323846,
b: 2.7182818284590452354 } };
const y : AnotherPair = AnotherPair{ x: (0xf0f0f0f0_f0f0f0f0,
0xabababab_abababab),
y: Pair { a: 3.14159265358979323846,
b: 2.7182818284590452354 }};
fn main() {
let (p, _) = y.x;
......
......@@ -9,9 +9,11 @@
// except according to those terms.
struct Pair { a: int, b: &int }
const x: &int = &10;
const y: &{a: int, b: &int} = &{a: 15, b: x};
const y: &Pair = &Pair {a: 15, b: x};
fn main() {
io::println(fmt!("x = %?", *x));
......
......@@ -17,8 +17,8 @@
fn main() {
// Structural types can be used between two versions of the same crate
assert cr5_1::structural().name == cr5_2::structural().name;
assert cr5_1::structural().val == cr5_2::structural().val;
assert cr5_1::struct_nameval().name == cr5_2::struct_nameval().name;
assert cr5_1::struct_nameval().val == cr5_2::struct_nameval().val;
// Make sure these are actually two different crates
assert cr5_1::f() == 10 && cr5_2::f() == 20;
}
......@@ -17,9 +17,11 @@ fn foo() -> Option<A> { None }
}
fn foo_func<A, B: thing<A>>(x: B) -> Option<A> { x.foo() }
struct A { a: int }
fn main() {
for iter::eachi(&(Some({a: 0}))) |i, a| {
for iter::eachi(&(Some(A {a: 0}))) |i, a| {
debug!("%u %d", i, a.a);
}
......
......@@ -18,14 +18,14 @@
type HashFn<K> = pure fn~(K) -> uint;
type EqFn<K> = pure fn~(K, K) -> bool;
struct LM { resize_at: uint, size: uint }
enum LinearMap<K,V> {
LinearMap_({
resize_at: uint,
size: uint})
LinearMap_(LM)
}
fn linear_map<K,V>() -> LinearMap<K,V> {
LinearMap_({
LinearMap_(LM{
resize_at: 32,
size: 0})
}
......
......@@ -11,11 +11,11 @@
const tau: float = 2.0*3.14159265358979323;
type point = {x: float, y: float};
type size = {w: float, h: float};
struct Point {x: float, y: float}
struct Size {w: float, h: float}
enum shape {
circle(point, float),
rectangle(point, size)
circle(Point, float),
rectangle(Point, Size)
}
......@@ -37,16 +37,18 @@ fn select<T>(&self, threshold: float,
fn select_based_on_unit_circle<T>(
threshold: float, a: &r/T, b: &r/T) -> &r/T {
let shape = &circle({x: 0.0, y: 0.0}, 1.0);
let shape = &circle(Point{x: 0.0, y: 0.0}, 1.0);
shape.select(threshold, a, b)
}
struct thing {
x: {mut a: @int}
x: A
}
fn thing(x: {mut a: @int}) -> thing {
struct A { mut a: @int }
fn thing(x: A) -> thing {
thing {
x: copy x
}
......@@ -56,7 +58,7 @@ impl thing {
fn foo(@self) -> int { *self.x.a }
fn bar(~self) -> int { *self.x.a }
fn quux(&self) -> int { *self.x.a }
fn baz(&self) -> &self/{mut a: @int} { &self.x }
fn baz(&self) -> &self/A { &self.x }
fn spam(self) -> int { *self.x.a }
}
......@@ -65,14 +67,14 @@ impl thing: Nus { fn f(&self) {} }
fn main() {
let x = @thing({mut a: @10});
let x = @thing(A {mut a: @10});
assert x.foo() == 10;
assert x.quux() == 10;
let y = ~thing({mut a: @10});
let y = ~thing(A {mut a: @10});
assert (copy y).bar() == 10;
assert y.quux() == 10;
let z = thing({mut a: @11});
let z = thing(A {mut a: @11});
assert z.spam() == 11;
}
......@@ -24,13 +24,13 @@ fn test_bool() {
test_generic::<bool>(true, compare_bool);
}
type t = {a: int, b: int};
struct Pair { a: int, b: int }
fn test_rec() {
fn compare_rec(t1: t, t2: t) -> bool {
fn compare_rec(t1: Pair, t2: Pair) -> bool {
t1.a == t2.a && t1.b == t2.b
}
test_generic::<t>({a: 1, b: 2}, compare_rec);
test_generic::<Pair>(Pair {a: 1, b: 2}, compare_rec);
}
fn main() { test_bool(); test_rec(); }
......@@ -13,9 +13,11 @@
// -*- rust -*-
// Tests for match as expressions resulting in structural types
// Tests for match as expressions resulting in struct types
struct R { i: int }
fn test_rec() {
let rs = match true { true => {i: 100}, _ => fail };
let rs = match true { true => R {i: 100}, _ => fail };
assert (rs.i == 100);
}
......
......@@ -26,13 +26,13 @@ fn test_bool() {
test_generic::<bool>(true, compare_bool);
}
type t = {a: int, b: int};
struct Pair {a: int, b: int}
fn test_rec() {
fn compare_rec(t1: t, t2: t) -> bool {
fn compare_rec(t1: Pair, t2: Pair) -> bool {
t1.a == t2.a && t1.b == t2.b
}
test_generic::<t>({a: 1, b: 2}, compare_rec);
test_generic::<Pair>(Pair {a: 1, b: 2}, compare_rec);
}
fn main() { test_bool(); test_rec(); }
......@@ -9,9 +9,13 @@
// except according to those terms.
// Regression test for issue #377
struct A { a: int }
struct V { v: int }
fn main() {
let a = { let b = {a: 3}; b };
let a = { let b = A {a: 3}; b };
assert (a.a == 3);
let c = { let d = {v: 3}; d };
let c = { let d = V {v: 3}; d };
assert (c.v == 3);
}
......@@ -16,7 +16,9 @@
// Tests for standalone blocks as expressions
fn test_basic() { let rs: bool = { true }; assert (rs); }
fn test_rec() { let rs = { {v1: 10, v2: 20} }; assert (rs.v2 == 20); }
struct RS { v1: int, v2: int }
fn test_rec() { let rs = { RS {v1: 10, v2: 20} }; assert (rs.v2 == 20); }
fn test_filled_with_stuff() {
let rs = { let mut a = 0; while a < 10 { a += 1; } a };
......
......@@ -11,12 +11,14 @@
// xfail-fast
#[legacy_modes];
fn f(arg: {mut a: int}) {
fn f(arg: A) {
arg.a = 100;
}
struct A { mut a: int }
fn main() {
let x = {mut a: 10};
let x = A {a: 10};
f(x);
assert x.a == 100;
x.a = 20;
......
......@@ -25,13 +25,13 @@ fn test_bool() {
test_generic::<bool>(true, false, compare_bool);
}
type t = {a: int, b: int};
struct Pair {a: int, b: int}
fn test_rec() {
fn compare_rec(t1: t, t2: t) -> bool {
fn compare_rec(t1: Pair, t2: Pair) -> bool {
t1.a == t2.a && t1.b == t2.b
}
test_generic::<t>({a: 1, b: 2}, {a: 2, b: 3}, compare_rec);
test_generic::<Pair>(Pair{a: 1, b: 2}, Pair{a: 2, b: 3}, compare_rec);
}
fn main() { test_bool(); test_rec(); }
......@@ -13,9 +13,12 @@
// -*- rust -*-
// Tests for if as expressions returning structural types
// Tests for if as expressions returning nominal types
struct I { i: int }
fn test_rec() {
let rs = if true { {i: 100} } else { {i: 101} };
let rs = if true { I {i: 100} } else { I {i: 101} };
assert (rs.i == 100);
}
......
......@@ -12,13 +12,13 @@
// -*- rust -*-
type point = {x: int, y: int, mut z: int};
struct Point {x: int, y: int, mut z: int}
fn f(p: @point) { assert (p.z == 12); p.z = 13; assert (p.z == 13); }
fn f(p: @Point) { assert (p.z == 12); p.z = 13; assert (p.z == 13); }
fn main() {
let a: point = {x: 10, y: 11, mut z: 12};
let b: @point = @copy a;
let a: Point = Point {x: 10, y: 11, mut z: 12};
let b: @Point = @copy a;
assert (b.z == 12);
f(b);
assert (a.z == 12);
......
......@@ -8,9 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Struc { a: u8, b: [int * 3], c: int }
fn main() {
let arr = [1,2,3];
let struc = {a: 13u8, b: arr, c: 42};
let struc = Struc {a: 13u8, b: arr, c: 42};
let s = sys::log_str(&struc);
assert(s == ~"{a: 13, b: [1, 2, 3], c: 42}");
}
......@@ -8,8 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Pair { x: int, y: int }
fn main() {
for vec::each(~[{x: 10, y: 20}, {x: 30, y: 0}]) |elt| {
for vec::each(~[Pair {x: 10, y: 20}, Pair {x: 30, y: 0}]) |elt| {
assert (elt.x + elt.y == 30);
}
}
......@@ -10,9 +10,11 @@
fn box<T: Copy>(x: {x: T, y: T, z: T}) -> @{x: T, y: T, z: T} { return @x; }
fn box<T: Copy>(x: Box<T>) -> @Box<T> { return @x; }
struct Box<T> {x: T, y: T, z: T}
fn main() {
let x: @{x: int, y: int, z: int} = box::<int>({x: 1, y: 2, z: 3});
let x: @Box<int> = box::<int>(Box{x: 1, y: 2, z: 3});
assert (x.y == 2);
}
......@@ -12,11 +12,12 @@
fn g<X: Copy>(x: X) -> X { return x; }
fn f<T: Copy>(t: T) -> {a: T, b: T} {
type pair = {a: T, b: T};
struct Pair<T> {a: T, b: T}
let x: pair = {a: t, b: t};
return g::<pair>(x);
fn f<T: Copy>(t: T) -> Pair<T> {
let x: Pair<T> = Pair {a: t, b: t};
return g::<Pair<T>>(x);
}
fn main() {
......
......@@ -9,7 +9,8 @@
// except according to those terms.
struct Pair { x: @int, y: @int }
fn f<T: Copy>(t: T) { let t1: T = t; }
fn main() { let x = {x: @10, y: @12}; f(x); }
fn main() { let x = Pair {x: @10, y: @12}; f(x); }
......@@ -10,12 +10,12 @@
type recbox<T: Copy> = {x: @T};
struct Recbox<T: Copy> {x: @T}
fn reclift<T: Copy>(t: T) -> recbox<T> { return {x: @t}; }
fn reclift<T: Copy>(t: T) -> Recbox<T> { return Recbox {x: @t}; }
fn main() {
let foo: int = 17;
let rbfoo: recbox<int> = reclift::<int>(foo);
let rbfoo: Recbox<int> = reclift::<int>(foo);
assert (*rbfoo.x == foo);
}
......@@ -8,12 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
type recbox<T: Copy> = {x: ~T};
struct Recbox<T: Copy> {x: ~T}
fn reclift<T: Copy>(t: T) -> recbox<T> { return {x: ~t}; }
fn reclift<T: Copy>(t: T) -> Recbox<T> { return Recbox {x: ~t}; }
fn main() {
let foo: int = 17;
let rbfoo: recbox<int> = reclift::<int>(foo);
let rbfoo: Recbox<int> = reclift::<int>(foo);
assert (*rbfoo.x == foo);
}
......@@ -14,22 +14,22 @@
// -*- rust -*-
fn id<T: Copy>(x: T) -> T { return x; }
type triple = {x: int, y: int, z: int};
struct Triple {x: int, y: int, z: int}
fn main() {
let mut x = 62;
let mut y = 63;
let a = 'a';
let mut b = 'b';
let p: triple = {x: 65, y: 66, z: 67};
let mut q: triple = {x: 68, y: 69, z: 70};
let p: Triple = Triple {x: 65, y: 66, z: 67};
let mut q: Triple = Triple {x: 68, y: 69, z: 70};
y = id::<int>(x);
log(debug, y);
assert (x == y);
b = id::<char>(a);
log(debug, b);
assert (a == b);
q = id::<triple>(p);
q = id::<Triple>(p);
x = p.z;
y = q.z;
log(debug, y);
......
......@@ -14,10 +14,12 @@
// -*- rust -*-
enum noption<T> { some(T), }
struct Pair { x: int, y: int }
fn main() {
let nop: noption<int> = some::<int>(5);
match nop { some::<int>(n) => { log(debug, n); assert (n == 5); } }
let nop2: noption<{x: int, y: int}> = some({x: 17, y: 42});
let nop2: noption<Pair> = some(Pair{x: 17, y: 42});
match nop2 {
some(t) => {
log(debug, t.x);
......
......@@ -10,10 +10,10 @@
type pair<T> = {x: T, y: T};
struct Pair<T> {x: T, y: T}
fn main() {
let x: pair<int> = {x: 10, y: 12};
let x: Pair<int> = Pair {x: 10, y: 12};
assert (x.x == 10);
assert (x.y == 12);
}
......@@ -8,10 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Triple<T> { x: T, y: T, z: T }
fn box<T: Copy>(x: {x: T, y: T, z: T}) -> ~{x: T, y: T, z: T} { return ~x; }
fn box<T: Copy>(x: Triple<T>) -> ~Triple<T> { return ~x; }
fn main() {
let x: ~{x: int, y: int, z: int} = box::<int>({x: 1, y: 2, z: 3});
let x: ~Triple<int> = box::<int>(Triple{x: 1, y: 2, z: 3});
assert (x.y == 2);
}
......@@ -8,16 +8,18 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Pair { x: int, y: int }
fn main() {
let a =
match 10 { x if x < 7 => { 1 } x if x < 11 => { 2 } 10 => { 3 } _ => { 4 } };
assert (a == 2);
let b =
match {x: 10, y: 20} {
match Pair {x: 10, y: 20} {
x if x.x < 5 && x.y < 5 => { 1 }
{x: x, y: y} if x == 10 && y == 20 => { 2 }
{x: x, y: y} => { 3 }
Pair {x: x, y: y} if x == 10 && y == 20 => { 2 }
Pair {x: x, y: y} => { 3 }
};
assert (b == 2);
}
......@@ -13,10 +13,13 @@
// type must be known in this context' if the passing down doesn't
// happen.)
fn eat_tup(_r: ~@(int, fn@({x: int, y: int}) -> int)) {}
fn eat_rec(_r: @~{a: int, b: fn@({x: int, y: int}) -> int}) {}
fn eat_tup(_r: ~@(int, fn@(Pair) -> int)) {}
fn eat_rec(_r: @~Rec) {}
struct Rec { a: int, b: fn(Pair) -> int }
struct Pair { x: int, y: int }
fn main() {
eat_tup(~@(10, |a| a.x ));
eat_rec(@~{a: 10, b: |a| a.x });
eat_rec(@~Rec{a: 10, b: |a| a.x });
}
......@@ -15,6 +15,8 @@ struct r {
i: @mut int,
}
struct Box { x: r }
impl r : Drop {
fn finalize(&self) {
*(self.i) = *(self.i) + 1;
......@@ -38,7 +40,7 @@ fn test_box() {
fn test_rec() {
let i = @mut 0;
{
let a = move {x: r(i)};
let a = move Box {x: r(i)};
}
assert *i == 1;
}
......@@ -74,7 +76,7 @@ fn test_unique() {
fn test_box_rec() {
let i = @mut 0;
{
let a = move @{
let a = move @Box {
x: r(i)
};
}
......
......@@ -11,9 +11,11 @@
// check that we do not report a type like this as uninstantiable,
// even though it would be if the nxt field had type @foo:
enum foo = {x: uint, nxt: *foo};
enum foo = X;
struct X { x: uint, nxt: *foo }
fn main() {
let x = foo({x: 0u, nxt: ptr::null()});
let x = foo(X {x: 0, nxt: ptr::null()});
}
......@@ -11,7 +11,7 @@
// Issue #1112
// Alignment of interior pointers to dynamic-size types
type x<T> = {
struct X<T> {
a: T,
b: u8,
c: bool,
......@@ -19,10 +19,10 @@
e: u16,
f: u8,
g: u8
};
}
fn main() {
let x: x<int> = {
let x: X<int> = X {
a: 12345678,
b: 9u8,
c: true,
......@@ -34,7 +34,7 @@ fn main() {
bar(x);
}
fn bar<T>(x: x<T>) {
fn bar<T>(x: X<T>) {
assert x.b == 9u8;
assert x.c == true;
assert x.d == 10u8;
......
......@@ -12,16 +12,16 @@
enum maybe_pointy {
none,
p(@pointy)
p(@Pointy)
}
type pointy = {
struct Pointy {
mut a : maybe_pointy,
mut f : fn@()->(),
};
}
fn empty_pointy() -> @pointy {
return @{
fn empty_pointy() -> @Pointy {
return @Pointy{
mut a : none,
mut f : fn@()->(){},
}
......
......@@ -8,20 +8,22 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Pair { f: int, g: int }
fn main() {
let x = {
let x = Pair {
f: 0,
g: 0,
};
let y = {
let y = Pair {
f: 1,
g: 1,
.. x
};
let z = {
let z = Pair {
f: 1,
.. x
};
......
......@@ -18,14 +18,14 @@ fn cat() -> cat {
}
}
type kitty_info = {kitty: cat};
struct KittyInfo {kitty: cat}
// Code compiles and runs successfully if we add a + before the first arg
fn nyan(kitty: cat, _kitty_info: kitty_info) {
fn nyan(kitty: cat, _kitty_info: KittyInfo) {
(kitty.meow)();
}
fn main() {
let mut kitty = cat();
nyan(copy kitty, {kitty: copy kitty});
nyan(copy kitty, KittyInfo {kitty: copy kitty});
}
......@@ -14,6 +14,12 @@
pub mod pipes {
use core::cast::{forget, transmute};
pub struct Stuff<T> {
mut state: state,
mut blocked_task: Option<task::Task>,
mut payload: Option<T>
}
pub enum state {
empty,
full,
......@@ -36,7 +42,7 @@ pub impl state : cmp::Eq {
pub fn packet<T: Owned>() -> *packet<T> {
unsafe {
let p: *packet<T> = cast::transmute(~{
let p: *packet<T> = cast::transmute(~Stuff{
mut state: empty,
mut blocked_task: None::<task::Task>,
mut payload: None::<T>
......
......@@ -22,7 +22,7 @@ fn to_bytes() -> ~[u8] {
// the position of this function is significant! - if it comes before methods
// then it works, if it comes after it then it doesnt!
fn to_bools(bitv: {storage: ~[u64]}) -> ~[bool] {
fn to_bools(bitv: Storage) -> ~[bool] {
vec::from_fn(8, |i| {
let w = i / 64;
let b = i % 64;
......@@ -31,9 +31,11 @@ fn to_bools(bitv: {storage: ~[u64]}) -> ~[bool] {
})
}
struct Storage { storage: ~[u64] }
fn main() {
let bools = ~[false, false, true, false, false, true, true, false];
let bools2 = to_bools({storage: ~[0b01100100]});
let bools2 = to_bools(Storage{storage: ~[0b01100100]});
for uint::range(0, 8) |i| {
io::println(fmt!("%u => %u vs %u", i, bools[i] as uint, bools2[i] as uint));
......
......@@ -10,14 +10,14 @@
enum maybe_pointy {
no_pointy,
yes_pointy(@pointy),
yes_pointy(@Pointy),
}
type pointy = {
struct Pointy {
mut x : maybe_pointy
};
}
fn main() {
let m = @{ mut x : no_pointy };
let m = @Pointy { mut x : no_pointy };
m.x = yes_pointy(m);
}
......@@ -10,8 +10,12 @@
// This should typecheck even though the type of e is not fully
// resolved when we finish typechecking the fn@.
struct Refs { mut refs: ~[int], n: int }
fn main() {
let e = @{mut refs: ~[], n: 0};
let e = @Refs{mut refs: ~[], n: 0};
let f = fn@ () { log(error, e.n); };
e.refs += ~[1];
}
......@@ -12,9 +12,8 @@
// -*- rust -*-
fn f() {
let foo:
{a: int,
struct Large {a: int,
b: int,
c: int,
d: int,
......@@ -25,8 +24,10 @@ fn f() {
i: int,
j: int,
k: int,
l: int} =
{a: 0,
l: int}
fn f() {
let foo: Large =
Large {a: 0,
b: 0,
c: 0,
d: 0,
......
......@@ -10,9 +10,11 @@
// Make sure #1399 stays fixed
struct A { a: ~int }
fn foo() -> fn@() -> int {
let k = ~22;
let _u = {a: copy k};
let _u = A {a: copy k};
return fn@(move k) -> int { 22 };
}
......
......@@ -10,9 +10,11 @@
// Make sure #1399 stays fixed
struct A { a: ~int }
fn main() {
fn invoke(f: fn@()) { f(); }
let k = ~22;
let _u = {a: copy k};
let _u = A {a: copy k};
invoke(|| log(error, copy k) )
}
......@@ -8,9 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct X { x: int, y: @A }
struct A { a: int }
fn main() {
let u = {x: 10, y: @{a: 20}};
let mut {x: x, y: @{a: a}} = u;
let u = X {x: 10, y: @A {a: 20}};
let mut X {x: x, y: @A {a: a}} = u;
x = 100;
a = 100;
assert (x == 100);
......
......@@ -10,7 +10,9 @@
enum xx = int;
struct X { x: xx, y: int }
fn main() {
let @{x: xx(x), y: y} = @{x: xx(10), y: 20};
let @X {x: xx(x), y: y} = @X{x: xx(10), y: 20};
assert (x + y == 30);
}
......@@ -15,11 +15,13 @@ enum option<T> {
some(T),
}
type smallintmap<T> = @{mut v: ~[mut option<T>]};
struct Smallintmap<T> {mut v: ~[mut option<T>]}
fn mk<T>() -> smallintmap<T> {
struct V<T> { v: ~[mut option<T>] }
fn mk<T>() -> @Smallintmap<T> {
let v: ~[mut option<T>] = ~[mut];
return @{mut v: move v};
return @Smallintmap {mut v: move v};
}
fn f<T,U>() {
......
......@@ -11,7 +11,7 @@
// This is testing for stack frames greater than 256 bytes,
// for which function prologues are generated differently
type biggy = {
struct Biggy {
a00: u64,
a01: u64,
a02: u64,
......@@ -52,17 +52,17 @@
a37: u64,
a38: u64,
a39: u64,
};
}
fn getbig(i: biggy) {
fn getbig(i: Biggy) {
if i.a00 != 0u64 {
getbig({a00: i.a00 - 1u64,.. i});
getbig(Biggy{a00: i.a00 - 1u64,.. i});
}
}
fn main() {
getbig({
getbig(Biggy {
a00: 10000u64,
a01: 10000u64,
a02: 10000u64,
......
......@@ -8,16 +8,17 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Triple { x: int, y: int, z: int }
fn test(x: bool, foo: ~{x: int, y: int, z: int}) -> int {
fn test(x: bool, foo: ~Triple) -> int {
let bar = foo;
let mut y: ~{x: int, y: int, z: int};
if x { y = move bar; } else { y = ~{x: 4, y: 5, z: 6}; }
let mut y: ~Triple;
if x { y = move bar; } else { y = ~Triple{x: 4, y: 5, z: 6}; }
return y.y;
}
fn main() {
let x = ~{x: 1, y: 2, z: 3};
let x = ~Triple{x: 1, y: 2, z: 3};
assert (test(true, x) == 2);
assert (test(true, x) == 2);
assert (test(true, x) == 2);
......
......@@ -8,15 +8,17 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn test(x: bool, foo: @{x: int, y: int, z: int}) -> int {
struct Triple { x: int, y: int, z: int }
fn test(x: bool, foo: @Triple) -> int {
let bar = foo;
let mut y: @{x: int, y: int, z: int};
if x { y = move bar; } else { y = @{x: 4, y: 5, z: 6}; }
let mut y: @Triple;
if x { y = move bar; } else { y = @Triple{x: 4, y: 5, z: 6}; }
return y.y;
}
fn main() {
let x = @{x: 1, y: 2, z: 3};
let x = @Triple {x: 1, y: 2, z: 3};
assert (test(true, x) == 2);
assert (test(true, x) == 2);
assert (test(true, x) == 2);
......
......@@ -9,5 +9,6 @@
// except according to those terms.
struct X { x: int, y: int, z: int }
fn main() { let x = ~{x: 1, y: 2, z: 3}; let y = move x; assert (y.y == 2); }
fn main() { let x = ~X{x: 1, y: 2, z: 3}; let y = move x; assert (y.y == 2); }
......@@ -9,5 +9,6 @@
// except according to those terms.
struct X { x: int, y: int, z: int }
fn main() { let x = @{x: 1, y: 2, z: 3}; let y = move x; assert (y.y == 2); }
fn main() { let x = @X {x: 1, y: 2, z: 3}; let y = move x; assert (y.y == 2); }
......@@ -10,15 +10,17 @@
extern mod std;
fn test(x: bool, foo: ~{x: int, y: int, z: int}) -> int {
struct Triple { x: int, y: int, z: int }
fn test(x: bool, foo: ~Triple) -> int {
let bar = foo;
let mut y: ~{x: int, y: int, z: int};
if x { y = move bar; } else { y = ~{x: 4, y: 5, z: 6}; }
let mut y: ~Triple;
if x { y = move bar; } else { y = ~Triple {x: 4, y: 5, z: 6}; }
return y.y;
}
fn main() {
let x = ~{x: 1, y: 2, z: 3};
let x = ~Triple{x: 1, y: 2, z: 3};
for uint::range(0u, 10000u) |_i| {
assert (test(true, x) == 2);
}
......
......@@ -10,15 +10,17 @@
extern mod std;
fn test(x: bool, foo: @{x: int, y: int, z: int}) -> int {
struct Triple { x: int, y: int, z: int }
fn test(x: bool, foo: @Triple) -> int {
let bar = foo;
let mut y: @{x: int, y: int, z: int};
if x { y = move bar; } else { y = @{x: 4, y: 5, z: 6}; }
let mut y: @Triple;
if x { y = move bar; } else { y = @Triple{x: 4, y: 5, z: 6}; }
return y.y;
}
fn main() {
let x = @{x: 1, y: 2, z: 3};
let x = @Triple{x: 1, y: 2, z: 3};
for uint::range(0u, 10000u) |i| {
assert (test(true, x) == 2);
}
......
......@@ -10,7 +10,9 @@
extern mod std;
fn test(foo: ~{a: int, b: int, c: int}) -> ~{a: int, b: int, c: int} {
struct Triple {a: int, b: int, c: int}
fn test(foo: ~Triple) -> ~Triple {
let foo = foo;
let bar = move foo;
let baz = move bar;
......@@ -18,4 +20,4 @@ fn test(foo: ~{a: int, b: int, c: int}) -> ~{a: int, b: int, c: int} {
return quux;
}
fn main() { let x = ~{a: 1, b: 2, c: 3}; let y = test(x); assert (y.c == 3); }
fn main() { let x = ~Triple{a: 1, b: 2, c: 3}; let y = test(x); assert (y.c == 3); }
......@@ -11,7 +11,9 @@
extern mod std;
fn test(foo: @{a: int, b: int, c: int}) -> @{a: int, b: int, c: int} {
struct Triple { a: int, b: int, c: int }
fn test(foo: @Triple) -> @Triple {
let foo = foo;
let bar = move foo;
let baz = move bar;
......@@ -19,4 +21,8 @@ fn test(foo: @{a: int, b: int, c: int}) -> @{a: int, b: int, c: int} {
return quux;
}
fn main() { let x = @{a: 1, b: 2, c: 3}; let y = test(x); assert (y.c == 3); }
fn main() {
let x = @Triple{a: 1, b: 2, c: 3};
let y = test(x);
assert (y.c == 3);
}
......@@ -9,8 +9,10 @@
// except according to those terms.
struct Pair { a: int, b: int}
fn main() {
// This just tests whether the vec leaks its members.
let pvec: ~[mut @{a: int, b: int}] =
~[mut @{a: 1, b: 2}, @{a: 3, b: 4}, @{a: 5, b: 6}];
let pvec: ~[mut @Pair] =
~[mut @Pair{a: 1, b: 2}, @Pair{a: 3, b: 4}, @Pair{a: 5, b: 6}];
}
......@@ -8,11 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Foo { foo: bool, bar: Option<int>, baz: int }
fn main() {
match @{foo: true, bar: Some(10), baz: 20} {
@{foo: true, bar: Some(_), _} => {}
@{foo: false, bar: None, _} => {}
@{foo: true, bar: None, _} => {}
@{foo: false, bar: Some(_), _} => {}
match @Foo{foo: true, bar: Some(10), baz: 20} {
@Foo{foo: true, bar: Some(_), _} => {}
@Foo{foo: false, bar: None, _} => {}
@Foo{foo: true, bar: None, _} => {}
@Foo{foo: false, bar: Some(_), _} => {}
}
}
......@@ -8,15 +8,20 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct A { a: int, b: @int }
struct B { a: int, b: C }
struct D { a: int, d: C }
struct C { mut c: int }
fn main() {
match {a: 10, b: @20} {
x@{a, b: @20} => { assert x.a == 10; assert a == 10; }
{b, _} => { fail; }
match A {a: 10, b: @20} {
x@A {a, b: @20} => { assert x.a == 10; assert a == 10; }
A {b, _} => { fail; }
}
let x@{b, _} = {a: 10, b: {mut c: 20}};
let x@B {b, _} = B {a: 10, b: C {mut c: 20}};
x.b.c = 30;
assert b.c == 20;
let y@{d, _} = {a: 10, d: {mut c: 20}};
let y@D {d, _} = D {a: 10, d: C {mut c: 20}};
y.d.c = 30;
assert d.c == 20;
}
......@@ -8,11 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
enum mytype = {compute: extern fn(mytype) -> int, val: int};
enum mytype = Mytype;
struct Mytype {compute: extern fn(mytype) -> int, val: int}
fn compute(i: mytype) -> int { return i.val + 20; }
fn main() {
let myval = mytype({compute: compute, val: 30});
let myval = mytype(Mytype{compute: compute, val: 30});
assert ((myval.compute)(myval) == 50);
}
......@@ -8,27 +8,28 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct A { a: int, b: int }
struct Abox { a: @int, b: @int }
fn ret_int_i() -> int { return 10; }
fn ret_ext_i() -> @int { return @10; }
fn ret_int_rec() -> {a: int, b: int} { return {a: 10, b: 10}; }
fn ret_int_rec() -> A { return A {a: 10, b: 10}; }
fn ret_ext_rec() -> @{a: int, b: int} { return @{a: 10, b: 10}; }
fn ret_ext_rec() -> @A { return @A {a: 10, b: 10}; }
fn ret_ext_mem() -> {a: @int, b: @int} { return {a: @10, b: @10}; }
fn ret_ext_mem() -> Abox { return Abox {a: @10, b: @10}; }
fn ret_ext_ext_mem() -> @{a: @int, b: @int} { return @{a: @10, b: @10}; }
fn ret_ext_ext_mem() -> @Abox { return @Abox{a: @10, b: @10}; }
fn main() {
let mut int_i: int;
let mut ext_i: @int;
let mut int_rec: {a: int, b: int};
let mut ext_rec: @{a: int, b: int};
let mut ext_mem: {a: @int, b: @int};
let mut ext_ext_mem: @{a: @int, b: @int};
let mut int_rec: A;
let mut ext_rec: @A;
let mut ext_mem: Abox;
let mut ext_ext_mem: @Abox;
int_i = ret_int_i(); // initializing
int_i = ret_int_i(); // non-initializing
......
......@@ -8,11 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn magic(+x: {a: @int}) { log(debug, x); }
fn magic(+x: A) { log(debug, x); }
fn magic2(+x: @int) { log(debug, x); }
struct A { a: @int }
fn main() {
let a = {a: @10}, b = @10;
magic(a); magic({a: @20});
let a = A {a: @10}, b = @10;
magic(a); magic(A {a: @20});
magic2(b); magic2(@20);
}
......@@ -10,9 +10,12 @@
// Testing that calling fmt! (via debug!) doesn't complain about impure borrows
struct Big { b: @~str, c: uint, d: int, e: char,
f: float, g: bool }
pure fn foo() {
let a = {
b: @"hi",
let a = Big {
b: @~"hi",
c: 0,
d: 1,
e: 'a',
......
......@@ -29,7 +29,7 @@
}
pure fn sums_to_using_rec(v: ~[int], sum: int) -> bool {
let mut i = 0u, sum0 = {f: 0};
let mut i = 0u, sum0 = F {f: 0};
while i < v.len() {
sum0.f += v[i];
i += 1u;
......@@ -37,8 +37,10 @@
return sum0.f == sum;
}
struct F<T> { f: T }
pure fn sums_to_using_uniq_rec(v: ~[int], sum: int) -> bool {
let mut i = 0u, sum0 = {f: ~mut 0};
let mut i = 0u, sum0 = F {f: ~mut 0};
while i < v.len() {
*sum0.f += v[i];
i += 1u;
......
......@@ -12,8 +12,8 @@
// -*- rust -*-
type point = {x: int, y: int, z: int};
struct Point {x: int, y: int, z: int}
fn f(p: point) { assert (p.z == 12); }
fn f(p: Point) { assert (p.z == 12); }
fn main() { let x: point = {x: 10, y: 11, z: 12}; f(x); }
fn main() { let x: Point = Point {x: 10, y: 11, z: 12}; f(x); }
......@@ -18,16 +18,16 @@
}
// This is the type with the questionable alignment
type inner = {
struct Inner {
c64: u32
};
}
// This is the type that contains the type with the
// questionable alignment, for testing
type outer = {
struct Outer {
c8: u8,
t: inner
};
t: Inner
}
#[cfg(target_arch = "x86")]
......@@ -46,21 +46,21 @@ fn size() -> uint { 8u }
fn main() {
unsafe {
let x = {c8: 22u8, t: {c64: 44u32}};
let x = Outer {c8: 22u8, t: Inner {c64: 44u32}};
// Send it through the shape code
let y = fmt!("%?", x);
debug!("align inner = %?", rusti::min_align_of::<inner>());
debug!("size outer = %?", sys::size_of::<outer>());
debug!("align inner = %?", rusti::min_align_of::<Inner>());
debug!("size outer = %?", sys::size_of::<Outer>());
debug!("y = %s", y);
// per clang/gcc the alignment of `inner` is 4 on x86.
assert rusti::min_align_of::<inner>() == m::align();
assert rusti::min_align_of::<Inner>() == m::align();
// per clang/gcc the size of `outer` should be 12
// because `inner`s alignment was 4.
assert sys::size_of::<outer>() == m::size();
assert sys::size_of::<Outer>() == m::size();
assert y == ~"{c8: 22, t: {c64: 44}}";
}
......
......@@ -18,16 +18,16 @@
}
// This is the type with the questionable alignment
type inner = {
struct Inner {
c64: u64
};
}
// This is the type that contains the type with the
// questionable alignment, for testing
type outer = {
struct Outer {
c8: u8,
t: inner
};
t: Inner
}
#[cfg(target_os = "linux")]
......@@ -63,21 +63,21 @@ fn size() -> uint { 16u }
fn main() {
unsafe {
let x = {c8: 22u8, t: {c64: 44u64}};
let x = Outer {c8: 22u8, t: Inner {c64: 44u64}};
// Send it through the shape code
let y = fmt!("%?", x);
debug!("align inner = %?", rusti::min_align_of::<inner>());
debug!("size outer = %?", sys::size_of::<outer>());
debug!("align inner = %?", rusti::min_align_of::<Inner>());
debug!("size outer = %?", sys::size_of::<Outer>());
debug!("y = %s", y);
// per clang/gcc the alignment of `inner` is 4 on x86.
assert rusti::min_align_of::<inner>() == m::m::align();
// per clang/gcc the alignment of `Inner` is 4 on x86.
assert rusti::min_align_of::<Inner>() == m::m::align();
// per clang/gcc the size of `outer` should be 12
// because `inner`s alignment was 4.
assert sys::size_of::<outer>() == m::m::size();
// per clang/gcc the size of `Outer` should be 12
// because `Inner`s alignment was 4.
assert sys::size_of::<Outer>() == m::m::size();
assert y == ~"{c8: 22, t: {c64: 44}}";
}
......
......@@ -14,8 +14,11 @@
// -*- rust -*-
// Issue #50.
struct X { foo: ~str, bar: ~str }
fn main() {
let x = {foo: ~"hello", bar: ~"world"};
let x = X {foo: ~"hello", bar: ~"world"};
log(debug, copy x.foo);
log(debug, copy x.bar);
}
......@@ -12,12 +12,12 @@
// -*- rust -*-
type point = {x: int, y: int};
struct Point {x: int, y: int}
fn main() {
let origin: point = {x: 0, y: 0};
let right: point = {x: origin.x + 10,.. origin};
let up: point = {y: origin.y + 10,.. origin};
let origin: Point = Point {x: 0, y: 0};
let right: Point = Point {x: origin.x + 10,.. origin};
let up: Point = Point {y: origin.y + 10,.. origin};
assert (origin.x == 0);
assert (origin.y == 0);
assert (right.x == 10);
......
......@@ -9,12 +9,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
type point = {x: int, y: int};
struct Point {x: int, y: int}
type rect = (point, point);
type rect = (Point, Point);
fn fst(r: rect) -> point { let (fst, _) = r; return fst; }
fn snd(r: rect) -> point { let (_, snd) = r; return snd; }
fn fst(r: rect) -> Point { let (fst, _) = r; return fst; }
fn snd(r: rect) -> Point { let (_, snd) = r; return snd; }
fn f(r: rect, x1: int, y1: int, x2: int, y2: int) {
assert (fst(r).x == x1);
......@@ -24,7 +24,7 @@ fn f(r: rect, x1: int, y1: int, x2: int, y2: int) {
}
fn main() {
let r: rect = ({x: 10, y: 20}, {x: 11, y: 22});
let r: rect = (Point {x: 10, y: 20}, Point {x: 11, y: 22});
assert (fst(r).x == 10);
assert (fst(r).y == 20);
assert (snd(r).x == 11);
......
......@@ -12,9 +12,9 @@
// -*- rust -*-
type rect = {x: int, y: int, w: int, h: int};
struct Rect {x: int, y: int, w: int, h: int}
fn f(r: rect, x: int, y: int, w: int, h: int) {
fn f(r: Rect, x: int, y: int, w: int, h: int) {
assert (r.x == x);
assert (r.y == y);
assert (r.w == w);
......@@ -22,12 +22,12 @@ fn f(r: rect, x: int, y: int, w: int, h: int) {
}
fn main() {
let r: rect = {x: 10, y: 20, w: 100, h: 200};
let r: Rect = Rect {x: 10, y: 20, w: 100, h: 200};
assert (r.x == 10);
assert (r.y == 20);
assert (r.w == 100);
assert (r.h == 200);
let r2: rect = r;
let r2: Rect = r;
let x: int = r2.x;
assert (x == 10);
f(r, 10, 20, 100, 200);
......
......@@ -9,17 +9,17 @@
// except according to those terms.
enum t1 { a(int), b(uint), }
type t2 = {x: t1, y: int};
enum t3 { c(t2, uint), }
struct T2 {x: t1, y: int}
enum t3 { c(T2, uint), }
fn m(in: t3) -> int {
match in {
c({x: a(m), _}, _) => { return m; }
c({x: b(m), y: y}, z) => { return ((m + z) as int) + y; }
c(T2 {x: a(m), _}, _) => { return m; }
c(T2 {x: b(m), y: y}, z) => { return ((m + z) as int) + y; }
}
}
fn main() {
assert (m(c({x: a(10), y: 5}, 4u)) == 10);
assert (m(c({x: b(10u), y: 5}, 4u)) == 19);
assert (m(c(T2 {x: a(10), y: 5}, 4u)) == 10);
assert (m(c(T2 {x: b(10u), y: 5}, 4u)) == 19);
}
......@@ -29,9 +29,7 @@ fn align(size: uint, align: uint) -> uint {
((size + align) - 1u) & !(align - 1u)
}
enum ptr_visit_adaptor<V: TyVisitor movable_ptr> = {
inner: V
};
enum ptr_visit_adaptor<V: TyVisitor movable_ptr> = Inner<V>;
impl<V: TyVisitor movable_ptr> ptr_visit_adaptor<V> {
......@@ -469,11 +467,13 @@ fn visit_closure_ptr(ck: uint) -> bool {
}
}
enum my_visitor = @{
enum my_visitor = @Stuff;
struct Stuff {
mut ptr1: *c_void,
mut ptr2: *c_void,
mut vals: ~[~str]
};
}
impl my_visitor {
fn get<T>(f: fn(T)) {
......@@ -485,13 +485,15 @@ fn get<T>(f: fn(T)) {
fn visit_inner(inner: *TyDesc) -> bool {
unsafe {
let u = my_visitor(*self);
let v = ptr_visit_adaptor({inner: u});
let v = ptr_visit_adaptor::<my_visitor>(Inner {inner: u});
visit_tydesc(inner, v as TyVisitor);
true
}
}
}
struct Inner<V> { inner: V }
impl my_visitor: movable_ptr {
fn move_ptr(adjustment: fn(*c_void) -> *c_void) {
self.ptr1 = adjustment(self.ptr1);
......@@ -622,14 +624,16 @@ fn get_tydesc_for<T>(&&_t: T) -> *TyDesc {
get_tydesc::<T>()
}
struct Triple { x: int, y: int, z: int }
fn main() {
unsafe {
let r = (1,2,3,true,false,{x:5,y:4,z:3});
let r = (1,2,3,true,false, Triple {x:5,y:4,z:3});
let p = ptr::addr_of(&r) as *c_void;
let u = my_visitor(@{mut ptr1: p,
let u = my_visitor(@Stuff {mut ptr1: p,
mut ptr2: p,
mut vals: ~[]});
let v = ptr_visit_adaptor({inner: u});
let v = ptr_visit_adaptor(Inner {inner: u});
let td = get_tydesc_for(r);
unsafe { error!("tydesc sz: %u, align: %u",
(*td).size, (*td).align); }
......
......@@ -8,14 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
type point = {x: int, y: int};
struct Point {x: int, y: int}
fn x_coord(p: &r/point) -> &r/int {
fn x_coord(p: &r/Point) -> &r/int {
return &p.x;
}
fn main() {
let p = @{x: 3, y: 4};
let p = @Point {x: 3, y: 4};
let xc = x_coord(p);
assert *xc == 3;
}
......
......@@ -14,36 +14,36 @@
use libc, sys, cast;
use std::arena::Arena;
type bcx = {
fcx: &fcx
};
struct Bcx {
fcx: &Fcx
}
type fcx = {
struct Fcx {
arena: &Arena,
ccx: &ccx
};
ccx: &Ccx
}
type ccx = {
struct Ccx {
x: int
};
}
fn h(bcx : &r/bcx) -> &r/bcx {
return bcx.fcx.arena.alloc(|| { fcx: bcx.fcx });
fn h(bcx : &r/Bcx) -> &r/Bcx {
return bcx.fcx.arena.alloc(|| Bcx { fcx: bcx.fcx });
}
fn g(fcx : &fcx) {
let bcx = { fcx: fcx };
fn g(fcx : &Fcx) {
let bcx = Bcx { fcx: fcx };
h(&bcx);
}
fn f(ccx : &ccx) {
fn f(ccx : &Ccx) {
let a = Arena();
let fcx = &{ arena: &a, ccx: ccx };
let fcx = &Fcx { arena: &a, ccx: ccx };
return g(fcx);
}
fn main() {
let ccx = { x: 0 };
let ccx = Ccx { x: 0 };
f(&ccx);
}
......@@ -10,46 +10,46 @@
enum arena = ();
type bcx = {
fcx: &fcx
};
struct Bcx {
fcx: &Fcx
}
type fcx = {
struct Fcx {
arena: &arena,
ccx: &ccx
};
ccx: &Ccx
}
type ccx = {
struct Ccx {
x: int
};
}
fn alloc(_bcx : &arena) -> &bcx {
fn alloc(_bcx : &arena) -> &Bcx {
unsafe {
return cast::reinterpret_cast(
&libc::malloc(sys::size_of::<bcx/&blk>() as libc::size_t));
&libc::malloc(sys::size_of::<Bcx/&blk>() as libc::size_t));
}
}
fn h(bcx : &bcx) -> &bcx {
fn h(bcx : &Bcx) -> &Bcx {
return alloc(bcx.fcx.arena);
}
fn g(fcx : &fcx) {
let bcx = { fcx: fcx };
fn g(fcx : &Fcx) {
let bcx = Bcx { fcx: fcx };
let bcx2 = h(&bcx);
unsafe {
libc::free(cast::reinterpret_cast(&bcx2));
}
}
fn f(ccx : &ccx) {
fn f(ccx : &Ccx) {
let a = arena(());
let fcx = { arena: &a, ccx: ccx };
let fcx = Fcx { arena: &a, ccx: ccx };
return g(&fcx);
}
fn main() {
let ccx = { x: 0 };
let ccx = Ccx { x: 0 };
f(&ccx);
}
......@@ -8,18 +8,18 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
type clam = { chowder: &int };
struct Clam { chowder: &int }
trait get_chowder {
fn get_chowder() -> &self/int;
}
impl clam: get_chowder {
impl Clam: get_chowder {
fn get_chowder() -> &self/int { return self.chowder; }
}
fn main() {
let clam = { chowder: &3 };
let clam = Clam { chowder: &3 };
log(debug, *clam.get_chowder());
clam.get_chowder();
}
......
......@@ -8,16 +8,16 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
type ctxt = { v: uint };
struct Ctxt { v: uint }
trait get_ctxt {
fn get_ctxt() -> &self/ctxt;
fn get_ctxt() -> &self/Ctxt;
}
type has_ctxt = { c: &ctxt };
struct HasCtxt { c: &Ctxt }
impl has_ctxt: get_ctxt {
fn get_ctxt() -> &self/ctxt {
impl HasCtxt: get_ctxt {
fn get_ctxt() -> &self/Ctxt {
self.c
}
}
......@@ -27,8 +27,8 @@ fn get_v(gc: get_ctxt) -> uint {
}
fn main() {
let ctxt = { v: 22u };
let hc = { c: &ctxt };
let ctxt = Ctxt { v: 22 };
let hc = HasCtxt { c: &ctxt };
assert get_v(hc as get_ctxt) == 22u;
assert get_v(hc as get_ctxt) == 22;
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册