1
Fork 0

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

Except the pipes tests (that needs a snapshot)
This commit is contained in:
Tim Chevalier 2013-01-25 22:46:32 -08:00
parent 413be829eb
commit 6d4907a742
119 changed files with 605 additions and 437 deletions

View file

@ -13,11 +13,12 @@
use dvec::DVec; use dvec::DVec;
type entry<A,B> = {key: A, value: B}; struct Entry<A,B> {key: A, value: B}
struct alist<A,B> { eq_fn: fn@(A,A) -> bool, data: DVec<entry<A,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) { 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 { fn alist_get<A: Copy, B: Copy>(lst: alist<A,B>, k: A) -> B {

View file

@ -14,8 +14,10 @@
#[crate_type = "lib"]; #[crate_type = "lib"];
#[legacy_exports]; #[legacy_exports];
fn structural() -> { name: ~str, val: int } { struct NameVal { name: ~str, val: int }
{ name: ~"crateresolve5", val: 10 }
fn struct_nameval() -> NameVal {
NameVal { name: ~"crateresolve5", val: 10 }
} }
enum e { enum e {

View file

@ -14,8 +14,9 @@
#[crate_type = "lib"]; #[crate_type = "lib"];
#[legacy_exports]; #[legacy_exports];
fn structural() -> { name: ~str, val: int } { struct NameVal { name: ~str, val: int }
{ name: ~"crateresolve5", val: 10 } fn struct_nameval() -> NameVal {
NameVal { name: ~"crateresolve5", val: 10 }
} }
enum e { enum e {

View file

@ -14,10 +14,10 @@
enum sty { ty_nil, } 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 { fn mk_raw_ty(st: sty, cname: Option<~str>) -> RawT {
return {struct_: st, cname: cname, hash: 0u}; return RawT {struct_: st, cname: cname, hash: 0u};
} }
fn main() { mk_raw_ty(ty_nil, None::<~str>); } fn main() { mk_raw_ty(ty_nil, None::<~str>); }

View file

@ -8,18 +8,18 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
type pair<A,B> = { struct Pair<A,B> {
a: A, b: B a: A, b: B
}; }
enum rec<A> = _rec<A>; enum RecEnum<A> = Rec<A>;
type _rec<A> = { struct Rec<A> {
val: A, val: A,
mut rec: Option<@rec<A>> mut rec: Option<@RecEnum<A>>
}; }
fn make_cycle<A:Copy>(a: 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); g.rec = Some(g);
} }

View file

@ -10,8 +10,8 @@
enum option<T> { some(T), none, } 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 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(); }

View file

@ -8,10 +8,12 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
struct Pair { mut a: ~int, mut b: ~int }
fn main() { fn main() {
let x = ~{mut a: ~10, b: ~20}; let x = ~Pair {mut a: ~10, b: ~20};
match x { 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; assert **a == 10; *a = ~30; assert **a == 30;
} }
} }

View file

@ -8,9 +8,11 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
struct X { x: int }
fn main() { fn main() {
let x = match 0 { let x = match 0 {
_ => { _ => X {
x: 0 x: 0
}.x }.x
}; };

View file

@ -8,9 +8,11 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
struct X { x: int }
fn main() { fn main() {
let x = match 0 { let x = match 0 {
_ => { _ => X {
x: 0 x: 0
} }
}; };

View file

@ -8,18 +8,18 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
type rec = { struct Rec {
f: int f: int
}; }
fn destructure(x: &mut rec) { fn destructure(x: &mut Rec) {
match *x { match *x {
{f: ref mut f} => *f += 1 Rec {f: ref mut f} => *f += 1
} }
} }
fn main() { fn main() {
let mut v = {f: 22}; let mut v = Rec {f: 22};
destructure(&mut v); destructure(&mut v);
assert v.f == 23; assert v.f == 23;
} }

View file

@ -11,7 +11,9 @@
// xfail-fast // xfail-fast
#[legacy_modes]; #[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; let r = a.x + *b + c;
a.x = 0; a.x = 0;
*b = 10; *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 f2(a: int, f: fn(int)) -> int { f(1); return a; }
fn main() { 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 (f1(a, &mut b, move c) == 6);
assert (a.x == 0); assert (a.x == 0);
assert (b == 10); assert (b == 10);

View file

@ -12,9 +12,13 @@
// -*- rust -*- // -*- 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() { 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); log(debug, f(5, 6).a);
} }

View file

@ -8,14 +8,16 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
struct F { mut f: ~[int] }
fn impure(_v: &[int]) { fn impure(_v: &[int]) {
} }
fn main() { fn main() {
let x = {mut f: ~[3]}; let x = F {f: ~[3]};
match x { match x {
{f: ref mut v} => { F {f: ref mut v} => {
impure(*v); impure(*v);
} }
} }

View file

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // 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; *x.sum += v;
let mut values = ~[]; let mut values = ~[];
x.values <-> values; x.values <-> values;
@ -18,13 +18,13 @@ fn add_int(x: &mut ints, v: int) {
x.values <-> values; 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(); let l = x.values.len();
uint::range(0, l, |i| f(&x.values[i])) uint::range(0, l, |i| f(&x.values[i]))
} }
fn main() { fn main() {
let mut ints = ~{sum: ~0, values: ~[]}; let mut ints = ~Ints {sum: ~0, values: ~[]};
add_int(ints, 22); add_int(ints, 22);
add_int(ints, 44); add_int(ints, 44);

View file

@ -10,14 +10,16 @@
// exec-env:RUST_POISON_ON_FREE=1 // exec-env:RUST_POISON_ON_FREE=1
struct F { f: ~int }
fn main() { fn main() {
let mut x = @{f: ~3}; let mut x = @F {f: ~3};
match x { match x {
@{f: ref b_x} => { @F {f: ref b_x} => {
assert **b_x == 3; assert **b_x == 3;
assert ptr::addr_of(&(*x.f)) == ptr::addr_of(&(**b_x)); 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); debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(**b_x)) as uint);
assert **b_x == 3; assert **b_x == 3;

View file

@ -17,12 +17,14 @@ fn borrow(x: &int, f: fn(x: &int)) {
assert before == after; assert before == after;
} }
struct F { f: ~int }
fn main() { fn main() {
let mut x = @{f: ~3}; let mut x = @F {f: ~3};
do borrow(x.f) |b_x| { do borrow(x.f) |b_x| {
assert *b_x == 3; assert *b_x == 3;
assert ptr::addr_of(&(*x.f)) == ptr::addr_of(&(*b_x)); 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); debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(*b_x)) as uint);
assert *b_x == 3; assert *b_x == 3;

View file

@ -10,14 +10,16 @@
// exec-env:RUST_POISON_ON_FREE=1 // exec-env:RUST_POISON_ON_FREE=1
struct F { f: ~int }
fn main() { fn main() {
let mut x = @mut @{f: ~3}; let mut x = @mut @F {f: ~3};
match x { match x {
@@{f: ref b_x} => { @@F{f: ref b_x} => {
assert **b_x == 3; assert **b_x == 3;
assert ptr::addr_of(&(x.f)) == ptr::addr_of(b_x); 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); debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(**b_x)) as uint);
assert **b_x == 3; assert **b_x == 3;

View file

@ -17,12 +17,14 @@ fn borrow(x: &int, f: fn(x: &int)) {
assert before == after; assert before == after;
} }
struct F { f: ~int }
fn main() { fn main() {
let mut x = ~mut @{f: ~3}; let mut x = ~mut @F{f: ~3};
do borrow(x.f) |b_x| { do borrow(x.f) |b_x| {
assert *b_x == 3; assert *b_x == 3;
assert ptr::addr_of(&(*x.f)) == ptr::addr_of(&(*b_x)); 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); debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(*b_x)) as uint);
assert *b_x == 3; assert *b_x == 3;

View file

@ -17,12 +17,14 @@ fn borrow(x: &int, f: fn(x: &int)) {
assert before == after; assert before == after;
} }
struct F { f: ~int }
fn main() { fn main() {
let mut x = @{f: ~3}; let mut x = @F {f: ~3};
do borrow((*x).f) |b_x| { do borrow((*x).f) |b_x| {
assert *b_x == 3; assert *b_x == 3;
assert ptr::addr_of(&(*x.f)) == ptr::addr_of(&(*b_x)); 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); debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(*b_x)) as uint);
assert *b_x == 3; assert *b_x == 3;

View file

@ -8,7 +8,10 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
struct F { mut f: @G }
struct G { g: ~[int] }
fn main() { 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 {} while rec.f.g.len() == 23 {}
} }

View file

@ -10,7 +10,9 @@
fn borrow<T>(x: &r/T) -> &r/T {x} fn borrow<T>(x: &r/T) -> &r/T {x}
struct Rec { mut f: @int }
fn main() { fn main() {
let rec = @{mut f: @22}; let rec = @Rec {mut f: @22};
while *borrow(rec.f) == 23 {} while *borrow(rec.f) == 23 {}
} }

View file

@ -8,12 +8,12 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
type foo = {a: int, b: uint}; struct Foo {a: int, b: uint}
enum bar { u(@foo), w(int), } enum bar { u(@Foo), w(int), }
fn main() { fn main() {
assert (match u(@{a: 10, b: 40u}) { assert (match u(@Foo{a: 10, b: 40u}) {
u(@{a: a, b: b}) => { a + (b as int) } u(@Foo{a: a, b: b}) => { a + (b as int) }
_ => { 66 } _ => { 66 }
} == 50); } == 50);
} }

View file

@ -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() { fn main() {
let foo: int = 17; let foo: int = 17;
let bfoo: box<int> = {c: @foo}; let bfoo: Box<int> = Box {c: @foo};
debug!("see what's in our box"); debug!("see what's in our box");
assert (unbox::<int>(bfoo) == foo); assert (unbox::<int>(bfoo) == foo);
} }

View file

@ -14,11 +14,13 @@
fn foo<T: Copy Const>(x: T) -> T { x } fn foo<T: Copy Const>(x: T) -> T { x }
struct F { field: int }
fn main() { fn main() {
foo(1); foo(1);
foo(~"hi"); foo(~"hi");
foo(~[1, 2, 3]); foo(~[1, 2, 3]);
foo({field: 42}); foo(F{field: 42});
foo((1, 2u)); foo((1, 2u));
foo(@1); foo(@1);
foo(~1); foo(~1);

View file

@ -13,10 +13,15 @@ const p : int = x[2];
const y : &[int] = &[1,2,3,4]; const y : &[int] = &[1,2,3,4];
const q : int = y[2]; 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 t : int = s.b;
const k : {a: int, b: int, c: {d: int, e: int}} = {a: 10, b: 20, c: {d: 30, 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}}; e: 40}};
const m : int = k.c.e; const m : int = k.c.e;

View file

@ -8,12 +8,14 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // 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 x : (i32,i32) = (0xfeedf00dd,0xca11ab1e);
const y : { x: (i64, i64), const y : AnotherPair = AnotherPair{ x: (0xf0f0f0f0_f0f0f0f0,
y: { a: float,
b: float } } = { x: (0xf0f0f0f0_f0f0f0f0,
0xabababab_abababab), 0xabababab_abababab),
y: { a: 3.14159265358979323846, y: Pair { a: 3.14159265358979323846,
b: 2.7182818284590452354 }}; b: 2.7182818284590452354 }};
fn main() { fn main() {

View file

@ -9,9 +9,11 @@
// except according to those terms. // except according to those terms.
struct Pair { a: int, b: &int }
const x: &int = &10; const x: &int = &10;
const y: &{a: int, b: &int} = &{a: 15, b: x}; const y: &Pair = &Pair {a: 15, b: x};
fn main() { fn main() {
io::println(fmt!("x = %?", *x)); io::println(fmt!("x = %?", *x));

View file

@ -17,8 +17,8 @@ extern mod cr5_2 (name = "crateresolve5", vers = "0.2");
fn main() { fn main() {
// Structural types can be used between two versions of the same crate // Structural types can be used between two versions of the same crate
assert cr5_1::structural().name == cr5_2::structural().name; assert cr5_1::struct_nameval().name == cr5_2::struct_nameval().name;
assert cr5_1::structural().val == cr5_2::structural().val; assert cr5_1::struct_nameval().val == cr5_2::struct_nameval().val;
// Make sure these are actually two different crates // Make sure these are actually two different crates
assert cr5_1::f() == 10 && cr5_2::f() == 20; assert cr5_1::f() == 10 && cr5_2::f() == 20;
} }

View file

@ -17,9 +17,11 @@ impl<A> int: thing<A> {
} }
fn foo_func<A, B: thing<A>>(x: B) -> Option<A> { x.foo() } fn foo_func<A, B: thing<A>>(x: B) -> Option<A> { x.foo() }
struct A { a: int }
fn main() { 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); debug!("%u %d", i, a.a);
} }

View file

@ -18,14 +18,14 @@ extern mod std;
type HashFn<K> = pure fn~(K) -> uint; type HashFn<K> = pure fn~(K) -> uint;
type EqFn<K> = pure fn~(K, K) -> bool; type EqFn<K> = pure fn~(K, K) -> bool;
struct LM { resize_at: uint, size: uint }
enum LinearMap<K,V> { enum LinearMap<K,V> {
LinearMap_({ LinearMap_(LM)
resize_at: uint,
size: uint})
} }
fn linear_map<K,V>() -> LinearMap<K,V> { fn linear_map<K,V>() -> LinearMap<K,V> {
LinearMap_({ LinearMap_(LM{
resize_at: 32, resize_at: 32,
size: 0}) size: 0})
} }

View file

@ -11,11 +11,11 @@
const tau: float = 2.0*3.14159265358979323; const tau: float = 2.0*3.14159265358979323;
type point = {x: float, y: float}; struct Point {x: float, y: float}
type size = {w: float, h: float}; struct Size {w: float, h: float}
enum shape { enum shape {
circle(point, float), circle(Point, float),
rectangle(point, size) rectangle(Point, Size)
} }
@ -37,16 +37,18 @@ impl shape {
fn select_based_on_unit_circle<T>( fn select_based_on_unit_circle<T>(
threshold: float, a: &r/T, b: &r/T) -> &r/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) shape.select(threshold, a, b)
} }
struct thing { 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 { thing {
x: copy x x: copy x
} }
@ -56,7 +58,7 @@ impl thing {
fn foo(@self) -> int { *self.x.a } fn foo(@self) -> int { *self.x.a }
fn bar(~self) -> int { *self.x.a } fn bar(~self) -> int { *self.x.a }
fn quux(&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 } fn spam(self) -> int { *self.x.a }
} }
@ -65,14 +67,14 @@ impl thing: Nus { fn f(&self) {} }
fn main() { fn main() {
let x = @thing({mut a: @10}); let x = @thing(A {mut a: @10});
assert x.foo() == 10; assert x.foo() == 10;
assert x.quux() == 10; assert x.quux() == 10;
let y = ~thing({mut a: @10}); let y = ~thing(A {mut a: @10});
assert (copy y).bar() == 10; assert (copy y).bar() == 10;
assert y.quux() == 10; assert y.quux() == 10;
let z = thing({mut a: @11}); let z = thing(A {mut a: @11});
assert z.spam() == 11; assert z.spam() == 11;
} }

View file

@ -24,13 +24,13 @@ fn test_bool() {
test_generic::<bool>(true, compare_bool); test_generic::<bool>(true, compare_bool);
} }
type t = {a: int, b: int}; struct Pair { a: int, b: int }
fn test_rec() { 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 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(); } fn main() { test_bool(); test_rec(); }

View file

@ -13,9 +13,11 @@
// -*- rust -*- // -*- 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() { fn test_rec() {
let rs = match true { true => {i: 100}, _ => fail }; let rs = match true { true => R {i: 100}, _ => fail };
assert (rs.i == 100); assert (rs.i == 100);
} }

View file

@ -26,13 +26,13 @@ fn test_bool() {
test_generic::<bool>(true, compare_bool); test_generic::<bool>(true, compare_bool);
} }
type t = {a: int, b: int}; struct Pair {a: int, b: int}
fn test_rec() { 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 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(); } fn main() { test_bool(); test_rec(); }

View file

@ -9,9 +9,13 @@
// except according to those terms. // except according to those terms.
// Regression test for issue #377 // Regression test for issue #377
struct A { a: int }
struct V { v: int }
fn main() { fn main() {
let a = { let b = {a: 3}; b }; let a = { let b = A {a: 3}; b };
assert (a.a == 3); assert (a.a == 3);
let c = { let d = {v: 3}; d }; let c = { let d = V {v: 3}; d };
assert (c.v == 3); assert (c.v == 3);
} }

View file

@ -16,7 +16,9 @@
// Tests for standalone blocks as expressions // Tests for standalone blocks as expressions
fn test_basic() { let rs: bool = { true }; assert (rs); } 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() { fn test_filled_with_stuff() {
let rs = { let mut a = 0; while a < 10 { a += 1; } a }; let rs = { let mut a = 0; while a < 10 { a += 1; } a };

View file

@ -11,12 +11,14 @@
// xfail-fast // xfail-fast
#[legacy_modes]; #[legacy_modes];
fn f(arg: {mut a: int}) { fn f(arg: A) {
arg.a = 100; arg.a = 100;
} }
struct A { mut a: int }
fn main() { fn main() {
let x = {mut a: 10}; let x = A {a: 10};
f(x); f(x);
assert x.a == 100; assert x.a == 100;
x.a = 20; x.a = 20;

View file

@ -25,13 +25,13 @@ fn test_bool() {
test_generic::<bool>(true, false, compare_bool); test_generic::<bool>(true, false, compare_bool);
} }
type t = {a: int, b: int}; struct Pair {a: int, b: int}
fn test_rec() { 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 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(); } fn main() { test_bool(); test_rec(); }

View file

@ -13,9 +13,12 @@
// -*- rust -*- // -*- rust -*-
// Tests for if as expressions returning structural types // Tests for if as expressions returning nominal types
struct I { i: int }
fn test_rec() { 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); assert (rs.i == 100);
} }

View file

@ -12,13 +12,13 @@
// -*- rust -*- // -*- 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() { fn main() {
let a: point = {x: 10, y: 11, mut z: 12}; let a: Point = Point {x: 10, y: 11, mut z: 12};
let b: @point = @copy a; let b: @Point = @copy a;
assert (b.z == 12); assert (b.z == 12);
f(b); f(b);
assert (a.z == 12); assert (a.z == 12);

View file

@ -8,9 +8,11 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
struct Struc { a: u8, b: [int * 3], c: int }
fn main() { fn main() {
let arr = [1,2,3]; 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); let s = sys::log_str(&struc);
assert(s == ~"{a: 13, b: [1, 2, 3], c: 42}"); assert(s == ~"{a: 13, b: [1, 2, 3], c: 42}");
} }

View file

@ -8,8 +8,10 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
struct Pair { x: int, y: int }
fn main() { 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); assert (elt.x + elt.y == 30);
} }
} }

View file

@ -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() { 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); assert (x.y == 2);
} }

View file

@ -12,11 +12,12 @@
fn g<X: Copy>(x: X) -> X { return x; } fn g<X: Copy>(x: X) -> X { return x; }
fn f<T: Copy>(t: T) -> {a: T, b: T} { struct Pair<T> {a: T, b: T}
type pair = {a: T, b: T};
let x: pair = {a: t, b: t}; fn f<T: Copy>(t: T) -> Pair<T> {
return g::<pair>(x);
let x: Pair<T> = Pair {a: t, b: t};
return g::<Pair<T>>(x);
} }
fn main() { fn main() {

View file

@ -9,7 +9,8 @@
// except according to those terms. // except according to those terms.
struct Pair { x: @int, y: @int }
fn f<T: Copy>(t: T) { let t1: T = t; } 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); }

View file

@ -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() { fn main() {
let foo: int = 17; let foo: int = 17;
let rbfoo: recbox<int> = reclift::<int>(foo); let rbfoo: Recbox<int> = reclift::<int>(foo);
assert (*rbfoo.x == foo); assert (*rbfoo.x == foo);
} }

View file

@ -8,12 +8,12 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // 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() { fn main() {
let foo: int = 17; let foo: int = 17;
let rbfoo: recbox<int> = reclift::<int>(foo); let rbfoo: Recbox<int> = reclift::<int>(foo);
assert (*rbfoo.x == foo); assert (*rbfoo.x == foo);
} }

View file

@ -14,22 +14,22 @@
// -*- rust -*- // -*- rust -*-
fn id<T: Copy>(x: T) -> T { return x; } 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() { fn main() {
let mut x = 62; let mut x = 62;
let mut y = 63; let mut y = 63;
let a = 'a'; let a = 'a';
let mut b = 'b'; let mut b = 'b';
let p: triple = {x: 65, y: 66, z: 67}; let p: Triple = Triple {x: 65, y: 66, z: 67};
let mut q: triple = {x: 68, y: 69, z: 70}; let mut q: Triple = Triple {x: 68, y: 69, z: 70};
y = id::<int>(x); y = id::<int>(x);
log(debug, y); log(debug, y);
assert (x == y); assert (x == y);
b = id::<char>(a); b = id::<char>(a);
log(debug, b); log(debug, b);
assert (a == b); assert (a == b);
q = id::<triple>(p); q = id::<Triple>(p);
x = p.z; x = p.z;
y = q.z; y = q.z;
log(debug, y); log(debug, y);

View file

@ -14,10 +14,12 @@
// -*- rust -*- // -*- rust -*-
enum noption<T> { some(T), } enum noption<T> { some(T), }
struct Pair { x: int, y: int }
fn main() { fn main() {
let nop: noption<int> = some::<int>(5); let nop: noption<int> = some::<int>(5);
match nop { some::<int>(n) => { log(debug, n); assert (n == 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 { match nop2 {
some(t) => { some(t) => {
log(debug, t.x); log(debug, t.x);

View file

@ -10,10 +10,10 @@
type pair<T> = {x: T, y: T}; struct Pair<T> {x: T, y: T}
fn main() { 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.x == 10);
assert (x.y == 12); assert (x.y == 12);
} }

View file

@ -8,10 +8,11 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // 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() { 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); assert (x.y == 2);
} }

View file

@ -8,16 +8,18 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
struct Pair { x: int, y: int }
fn main() { fn main() {
let a = let a =
match 10 { x if x < 7 => { 1 } x if x < 11 => { 2 } 10 => { 3 } _ => { 4 } }; match 10 { x if x < 7 => { 1 } x if x < 11 => { 2 } 10 => { 3 } _ => { 4 } };
assert (a == 2); assert (a == 2);
let b = let b =
match {x: 10, y: 20} { match Pair {x: 10, y: 20} {
x if x.x < 5 && x.y < 5 => { 1 } x if x.x < 5 && x.y < 5 => { 1 }
{x: x, y: y} if x == 10 && y == 20 => { 2 } Pair {x: x, y: y} if x == 10 && y == 20 => { 2 }
{x: x, y: y} => { 3 } Pair {x: x, y: y} => { 3 }
}; };
assert (b == 2); assert (b == 2);
} }

View file

@ -13,10 +13,13 @@
// type must be known in this context' if the passing down doesn't // type must be known in this context' if the passing down doesn't
// happen.) // happen.)
fn eat_tup(_r: ~@(int, fn@({x: int, y: int}) -> int)) {} fn eat_tup(_r: ~@(int, fn@(Pair) -> int)) {}
fn eat_rec(_r: @~{a: int, b: fn@({x: int, y: int}) -> int}) {} fn eat_rec(_r: @~Rec) {}
struct Rec { a: int, b: fn(Pair) -> int }
struct Pair { x: int, y: int }
fn main() { fn main() {
eat_tup(~@(10, |a| a.x )); eat_tup(~@(10, |a| a.x ));
eat_rec(@~{a: 10, b: |a| a.x }); eat_rec(@~Rec{a: 10, b: |a| a.x });
} }

View file

@ -15,6 +15,8 @@ struct r {
i: @mut int, i: @mut int,
} }
struct Box { x: r }
impl r : Drop { impl r : Drop {
fn finalize(&self) { fn finalize(&self) {
*(self.i) = *(self.i) + 1; *(self.i) = *(self.i) + 1;
@ -38,7 +40,7 @@ fn test_box() {
fn test_rec() { fn test_rec() {
let i = @mut 0; let i = @mut 0;
{ {
let a = move {x: r(i)}; let a = move Box {x: r(i)};
} }
assert *i == 1; assert *i == 1;
} }
@ -74,7 +76,7 @@ fn test_unique() {
fn test_box_rec() { fn test_box_rec() {
let i = @mut 0; let i = @mut 0;
{ {
let a = move @{ let a = move @Box {
x: r(i) x: r(i)
}; };
} }

View file

@ -11,9 +11,11 @@
// check that we do not report a type like this as uninstantiable, // check that we do not report a type like this as uninstantiable,
// even though it would be if the nxt field had type @foo: // 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() { fn main() {
let x = foo({x: 0u, nxt: ptr::null()}); let x = foo(X {x: 0, nxt: ptr::null()});
} }

View file

@ -11,7 +11,7 @@
// Issue #1112 // Issue #1112
// Alignment of interior pointers to dynamic-size types // Alignment of interior pointers to dynamic-size types
type x<T> = { struct X<T> {
a: T, a: T,
b: u8, b: u8,
c: bool, c: bool,
@ -19,10 +19,10 @@ type x<T> = {
e: u16, e: u16,
f: u8, f: u8,
g: u8 g: u8
}; }
fn main() { fn main() {
let x: x<int> = { let x: X<int> = X {
a: 12345678, a: 12345678,
b: 9u8, b: 9u8,
c: true, c: true,
@ -34,7 +34,7 @@ fn main() {
bar(x); bar(x);
} }
fn bar<T>(x: x<T>) { fn bar<T>(x: X<T>) {
assert x.b == 9u8; assert x.b == 9u8;
assert x.c == true; assert x.c == true;
assert x.d == 10u8; assert x.d == 10u8;

View file

@ -12,16 +12,16 @@
enum maybe_pointy { enum maybe_pointy {
none, none,
p(@pointy) p(@Pointy)
} }
type pointy = { struct Pointy {
mut a : maybe_pointy, mut a : maybe_pointy,
mut f : fn@()->(), mut f : fn@()->(),
}; }
fn empty_pointy() -> @pointy { fn empty_pointy() -> @Pointy {
return @{ return @Pointy{
mut a : none, mut a : none,
mut f : fn@()->(){}, mut f : fn@()->(){},
} }

View file

@ -8,20 +8,22 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
struct Pair { f: int, g: int }
fn main() { fn main() {
let x = { let x = Pair {
f: 0, f: 0,
g: 0, g: 0,
}; };
let y = { let y = Pair {
f: 1, f: 1,
g: 1, g: 1,
.. x .. x
}; };
let z = { let z = Pair {
f: 1, f: 1,
.. x .. x
}; };

View file

@ -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 // 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)(); (kitty.meow)();
} }
fn main() { fn main() {
let mut kitty = cat(); let mut kitty = cat();
nyan(copy kitty, {kitty: copy kitty}); nyan(copy kitty, KittyInfo {kitty: copy kitty});
} }

View file

@ -14,6 +14,12 @@
pub mod pipes { pub mod pipes {
use core::cast::{forget, transmute}; 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 { pub enum state {
empty, empty,
full, full,
@ -36,7 +42,7 @@ pub mod pipes {
pub fn packet<T: Owned>() -> *packet<T> { pub fn packet<T: Owned>() -> *packet<T> {
unsafe { unsafe {
let p: *packet<T> = cast::transmute(~{ let p: *packet<T> = cast::transmute(~Stuff{
mut state: empty, mut state: empty,
mut blocked_task: None::<task::Task>, mut blocked_task: None::<task::Task>,
mut payload: None::<T> mut payload: None::<T>

View file

@ -22,7 +22,7 @@ impl (): methods {
// the position of this function is significant! - if it comes before methods // the position of this function is significant! - if it comes before methods
// then it works, if it comes after it then it doesnt! // 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| { vec::from_fn(8, |i| {
let w = i / 64; let w = i / 64;
let b = i % 64; let b = i % 64;
@ -31,9 +31,11 @@ fn to_bools(bitv: {storage: ~[u64]}) -> ~[bool] {
}) })
} }
struct Storage { storage: ~[u64] }
fn main() { fn main() {
let bools = ~[false, false, true, false, false, true, true, false]; 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| { for uint::range(0, 8) |i| {
io::println(fmt!("%u => %u vs %u", i, bools[i] as uint, bools2[i] as uint)); io::println(fmt!("%u => %u vs %u", i, bools[i] as uint, bools2[i] as uint));

View file

@ -10,14 +10,14 @@
enum maybe_pointy { enum maybe_pointy {
no_pointy, no_pointy,
yes_pointy(@pointy), yes_pointy(@Pointy),
} }
type pointy = { struct Pointy {
mut x : maybe_pointy mut x : maybe_pointy
}; }
fn main() { fn main() {
let m = @{ mut x : no_pointy }; let m = @Pointy { mut x : no_pointy };
m.x = yes_pointy(m); m.x = yes_pointy(m);
} }

View file

@ -10,8 +10,12 @@
// This should typecheck even though the type of e is not fully // This should typecheck even though the type of e is not fully
// resolved when we finish typechecking the fn@. // resolved when we finish typechecking the fn@.
struct Refs { mut refs: ~[int], n: int }
fn main() { fn main() {
let e = @{mut refs: ~[], n: 0}; let e = @Refs{mut refs: ~[], n: 0};
let f = fn@ () { log(error, e.n); }; let f = fn@ () { log(error, e.n); };
e.refs += ~[1]; e.refs += ~[1];
} }

View file

@ -12,9 +12,8 @@
// -*- rust -*- // -*- rust -*-
fn f() {
let foo: struct Large {a: int,
{a: int,
b: int, b: int,
c: int, c: int,
d: int, d: int,
@ -25,8 +24,10 @@ fn f() {
i: int, i: int,
j: int, j: int,
k: int, k: int,
l: int} = l: int}
{a: 0, fn f() {
let foo: Large =
Large {a: 0,
b: 0, b: 0,
c: 0, c: 0,
d: 0, d: 0,

View file

@ -10,9 +10,11 @@
// Make sure #1399 stays fixed // Make sure #1399 stays fixed
struct A { a: ~int }
fn foo() -> fn@() -> int { fn foo() -> fn@() -> int {
let k = ~22; let k = ~22;
let _u = {a: copy k}; let _u = A {a: copy k};
return fn@(move k) -> int { 22 }; return fn@(move k) -> int { 22 };
} }

View file

@ -10,9 +10,11 @@
// Make sure #1399 stays fixed // Make sure #1399 stays fixed
struct A { a: ~int }
fn main() { fn main() {
fn invoke(f: fn@()) { f(); } fn invoke(f: fn@()) { f(); }
let k = ~22; let k = ~22;
let _u = {a: copy k}; let _u = A {a: copy k};
invoke(|| log(error, copy k) ) invoke(|| log(error, copy k) )
} }

View file

@ -8,9 +8,12 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
struct X { x: int, y: @A }
struct A { a: int }
fn main() { fn main() {
let u = {x: 10, y: @{a: 20}}; let u = X {x: 10, y: @A {a: 20}};
let mut {x: x, y: @{a: a}} = u; let mut X {x: x, y: @A {a: a}} = u;
x = 100; x = 100;
a = 100; a = 100;
assert (x == 100); assert (x == 100);

View file

@ -10,7 +10,9 @@
enum xx = int; enum xx = int;
struct X { x: xx, y: int }
fn main() { 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); assert (x + y == 30);
} }

View file

@ -15,11 +15,13 @@ enum option<T> {
some(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]; let v: ~[mut option<T>] = ~[mut];
return @{mut v: move v}; return @Smallintmap {mut v: move v};
} }
fn f<T,U>() { fn f<T,U>() {

View file

@ -11,7 +11,7 @@
// This is testing for stack frames greater than 256 bytes, // This is testing for stack frames greater than 256 bytes,
// for which function prologues are generated differently // for which function prologues are generated differently
type biggy = { struct Biggy {
a00: u64, a00: u64,
a01: u64, a01: u64,
a02: u64, a02: u64,
@ -52,17 +52,17 @@ type biggy = {
a37: u64, a37: u64,
a38: u64, a38: u64,
a39: u64, a39: u64,
}; }
fn getbig(i: biggy) { fn getbig(i: Biggy) {
if i.a00 != 0u64 { if i.a00 != 0u64 {
getbig({a00: i.a00 - 1u64,.. i}); getbig(Biggy{a00: i.a00 - 1u64,.. i});
} }
} }
fn main() { fn main() {
getbig({ getbig(Biggy {
a00: 10000u64, a00: 10000u64,
a01: 10000u64, a01: 10000u64,
a02: 10000u64, a02: 10000u64,

View file

@ -8,16 +8,17 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // 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 bar = foo;
let mut y: ~{x: int, y: int, z: int}; let mut y: ~Triple;
if x { y = move bar; } else { y = ~{x: 4, y: 5, z: 6}; } if x { y = move bar; } else { y = ~Triple{x: 4, y: 5, z: 6}; }
return y.y; return y.y;
} }
fn main() { 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); assert (test(true, x) == 2);
assert (test(true, x) == 2); assert (test(true, x) == 2);

View file

@ -8,15 +8,17 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // 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 bar = foo;
let mut y: @{x: int, y: int, z: int}; let mut y: @Triple;
if x { y = move bar; } else { y = @{x: 4, y: 5, z: 6}; } if x { y = move bar; } else { y = @Triple{x: 4, y: 5, z: 6}; }
return y.y; return y.y;
} }
fn main() { 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); assert (test(true, x) == 2);
assert (test(true, x) == 2); assert (test(true, x) == 2);

View file

@ -9,5 +9,6 @@
// except according to those terms. // 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); }

View file

@ -9,5 +9,6 @@
// except according to those terms. // 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); }

View file

@ -10,15 +10,17 @@
extern mod std; 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 bar = foo;
let mut y: ~{x: int, y: int, z: int}; let mut y: ~Triple;
if x { y = move bar; } else { y = ~{x: 4, y: 5, z: 6}; } if x { y = move bar; } else { y = ~Triple {x: 4, y: 5, z: 6}; }
return y.y; return y.y;
} }
fn main() { 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| { for uint::range(0u, 10000u) |_i| {
assert (test(true, x) == 2); assert (test(true, x) == 2);
} }

View file

@ -10,15 +10,17 @@
extern mod std; 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 bar = foo;
let mut y: @{x: int, y: int, z: int}; let mut y: @Triple;
if x { y = move bar; } else { y = @{x: 4, y: 5, z: 6}; } if x { y = move bar; } else { y = @Triple{x: 4, y: 5, z: 6}; }
return y.y; return y.y;
} }
fn main() { 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| { for uint::range(0u, 10000u) |i| {
assert (test(true, x) == 2); assert (test(true, x) == 2);
} }

View file

@ -10,7 +10,9 @@
extern mod std; 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 foo = foo;
let bar = move foo; let bar = move foo;
let baz = move bar; 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; 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); }

View file

@ -11,7 +11,9 @@
extern mod std; 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 foo = foo;
let bar = move foo; let bar = move foo;
let baz = move bar; 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; 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);
}

View file

@ -9,8 +9,10 @@
// except according to those terms. // except according to those terms.
struct Pair { a: int, b: int}
fn main() { fn main() {
// This just tests whether the vec leaks its members. // This just tests whether the vec leaks its members.
let pvec: ~[mut @{a: int, b: int}] = let pvec: ~[mut @Pair] =
~[mut @{a: 1, b: 2}, @{a: 3, b: 4}, @{a: 5, b: 6}]; ~[mut @Pair{a: 1, b: 2}, @Pair{a: 3, b: 4}, @Pair{a: 5, b: 6}];
} }

View file

@ -8,11 +8,13 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
struct Foo { foo: bool, bar: Option<int>, baz: int }
fn main() { fn main() {
match @{foo: true, bar: Some(10), baz: 20} { match @Foo{foo: true, bar: Some(10), baz: 20} {
@{foo: true, bar: Some(_), _} => {} @Foo{foo: true, bar: Some(_), _} => {}
@{foo: false, bar: None, _} => {} @Foo{foo: false, bar: None, _} => {}
@{foo: true, bar: None, _} => {} @Foo{foo: true, bar: None, _} => {}
@{foo: false, bar: Some(_), _} => {} @Foo{foo: false, bar: Some(_), _} => {}
} }
} }

View file

@ -8,15 +8,20 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // 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() { fn main() {
match {a: 10, b: @20} { match A {a: 10, b: @20} {
x@{a, b: @20} => { assert x.a == 10; assert a == 10; } x@A {a, b: @20} => { assert x.a == 10; assert a == 10; }
{b, _} => { fail; } 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; x.b.c = 30;
assert b.c == 20; 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; y.d.c = 30;
assert d.c == 20; assert d.c == 20;
} }

View file

@ -8,11 +8,13 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // 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 compute(i: mytype) -> int { return i.val + 20; }
fn main() { fn main() {
let myval = mytype({compute: compute, val: 30}); let myval = mytype(Mytype{compute: compute, val: 30});
assert ((myval.compute)(myval) == 50); assert ((myval.compute)(myval) == 50);
} }

View file

@ -8,27 +8,28 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // 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_int_i() -> int { return 10; }
fn ret_ext_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() { fn main() {
let mut int_i: int; let mut int_i: int;
let mut ext_i: @int; let mut ext_i: @int;
let mut int_rec: {a: int, b: int}; let mut int_rec: A;
let mut ext_rec: @{a: int, b: int}; let mut ext_rec: @A;
let mut ext_mem: {a: @int, b: @int}; let mut ext_mem: Abox;
let mut ext_ext_mem: @{a: @int, b: @int}; let mut ext_ext_mem: @Abox;
int_i = ret_int_i(); // initializing int_i = ret_int_i(); // initializing
int_i = ret_int_i(); // non-initializing int_i = ret_int_i(); // non-initializing

View file

@ -8,11 +8,13 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // 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); } fn magic2(+x: @int) { log(debug, x); }
struct A { a: @int }
fn main() { fn main() {
let a = {a: @10}, b = @10; let a = A {a: @10}, b = @10;
magic(a); magic({a: @20}); magic(a); magic(A {a: @20});
magic2(b); magic2(@20); magic2(b); magic2(@20);
} }

View file

@ -10,9 +10,12 @@
// Testing that calling fmt! (via debug!) doesn't complain about impure borrows // 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() { pure fn foo() {
let a = { let a = Big {
b: @"hi", b: @~"hi",
c: 0, c: 0,
d: 1, d: 1,
e: 'a', e: 'a',

View file

@ -29,7 +29,7 @@ pure fn sums_to_using_uniq(v: ~[int], sum: int) -> bool {
} }
pure fn sums_to_using_rec(v: ~[int], sum: int) -> bool { 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() { while i < v.len() {
sum0.f += v[i]; sum0.f += v[i];
i += 1u; i += 1u;
@ -37,8 +37,10 @@ pure fn sums_to_using_rec(v: ~[int], sum: int) -> bool {
return sum0.f == sum; return sum0.f == sum;
} }
struct F<T> { f: T }
pure fn sums_to_using_uniq_rec(v: ~[int], sum: int) -> bool { 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() { while i < v.len() {
*sum0.f += v[i]; *sum0.f += v[i];
i += 1u; i += 1u;

View file

@ -12,8 +12,8 @@
// -*- rust -*- // -*- 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); }

View file

@ -18,16 +18,16 @@ extern mod rusti {
} }
// This is the type with the questionable alignment // This is the type with the questionable alignment
type inner = { struct Inner {
c64: u32 c64: u32
}; }
// This is the type that contains the type with the // This is the type that contains the type with the
// questionable alignment, for testing // questionable alignment, for testing
type outer = { struct Outer {
c8: u8, c8: u8,
t: inner t: Inner
}; }
#[cfg(target_arch = "x86")] #[cfg(target_arch = "x86")]
@ -46,21 +46,21 @@ mod m {
fn main() { fn main() {
unsafe { unsafe {
let x = {c8: 22u8, t: {c64: 44u32}}; let x = Outer {c8: 22u8, t: Inner {c64: 44u32}};
// Send it through the shape code // Send it through the shape code
let y = fmt!("%?", x); let y = fmt!("%?", x);
debug!("align inner = %?", rusti::min_align_of::<inner>()); debug!("align inner = %?", rusti::min_align_of::<Inner>());
debug!("size outer = %?", sys::size_of::<outer>()); debug!("size outer = %?", sys::size_of::<Outer>());
debug!("y = %s", y); debug!("y = %s", y);
// per clang/gcc the alignment of `inner` is 4 on x86. // 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 // per clang/gcc the size of `outer` should be 12
// because `inner`s alignment was 4. // 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}}"; assert y == ~"{c8: 22, t: {c64: 44}}";
} }

View file

@ -18,16 +18,16 @@ extern mod rusti {
} }
// This is the type with the questionable alignment // This is the type with the questionable alignment
type inner = { struct Inner {
c64: u64 c64: u64
}; }
// This is the type that contains the type with the // This is the type that contains the type with the
// questionable alignment, for testing // questionable alignment, for testing
type outer = { struct Outer {
c8: u8, c8: u8,
t: inner t: Inner
}; }
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
@ -63,21 +63,21 @@ mod m {
fn main() { fn main() {
unsafe { unsafe {
let x = {c8: 22u8, t: {c64: 44u64}}; let x = Outer {c8: 22u8, t: Inner {c64: 44u64}};
// Send it through the shape code // Send it through the shape code
let y = fmt!("%?", x); let y = fmt!("%?", x);
debug!("align inner = %?", rusti::min_align_of::<inner>()); debug!("align inner = %?", rusti::min_align_of::<Inner>());
debug!("size outer = %?", sys::size_of::<outer>()); debug!("size outer = %?", sys::size_of::<Outer>());
debug!("y = %s", y); debug!("y = %s", y);
// per clang/gcc the alignment of `inner` is 4 on x86. // per clang/gcc the alignment of `Inner` is 4 on x86.
assert rusti::min_align_of::<inner>() == m::m::align(); assert rusti::min_align_of::<Inner>() == m::m::align();
// per clang/gcc the size of `outer` should be 12 // per clang/gcc the size of `Outer` should be 12
// because `inner`s alignment was 4. // because `Inner`s alignment was 4.
assert sys::size_of::<outer>() == m::m::size(); assert sys::size_of::<Outer>() == m::m::size();
assert y == ~"{c8: 22, t: {c64: 44}}"; assert y == ~"{c8: 22, t: {c64: 44}}";
} }

View file

@ -14,8 +14,11 @@
// -*- rust -*- // -*- rust -*-
// Issue #50. // Issue #50.
struct X { foo: ~str, bar: ~str }
fn main() { fn main() {
let x = {foo: ~"hello", bar: ~"world"}; let x = X {foo: ~"hello", bar: ~"world"};
log(debug, copy x.foo); log(debug, copy x.foo);
log(debug, copy x.bar); log(debug, copy x.bar);
} }

View file

@ -12,12 +12,12 @@
// -*- rust -*- // -*- rust -*-
type point = {x: int, y: int}; struct Point {x: int, y: int}
fn main() { fn main() {
let origin: point = {x: 0, y: 0}; let origin: Point = Point {x: 0, y: 0};
let right: point = {x: origin.x + 10,.. origin}; let right: Point = Point {x: origin.x + 10,.. origin};
let up: point = {y: origin.y + 10,.. origin}; let up: Point = Point {y: origin.y + 10,.. origin};
assert (origin.x == 0); assert (origin.x == 0);
assert (origin.y == 0); assert (origin.y == 0);
assert (right.x == 10); assert (right.x == 10);

View file

@ -9,12 +9,12 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // 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 fst(r: rect) -> Point { let (fst, _) = r; return fst; }
fn snd(r: rect) -> point { let (_, snd) = r; return snd; } fn snd(r: rect) -> Point { let (_, snd) = r; return snd; }
fn f(r: rect, x1: int, y1: int, x2: int, y2: int) { fn f(r: rect, x1: int, y1: int, x2: int, y2: int) {
assert (fst(r).x == x1); assert (fst(r).x == x1);
@ -24,7 +24,7 @@ fn f(r: rect, x1: int, y1: int, x2: int, y2: int) {
} }
fn main() { 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).x == 10);
assert (fst(r).y == 20); assert (fst(r).y == 20);
assert (snd(r).x == 11); assert (snd(r).x == 11);

View file

@ -12,9 +12,9 @@
// -*- rust -*- // -*- 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.x == x);
assert (r.y == y); assert (r.y == y);
assert (r.w == w); assert (r.w == w);
@ -22,12 +22,12 @@ fn f(r: rect, x: int, y: int, w: int, h: int) {
} }
fn main() { 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.x == 10);
assert (r.y == 20); assert (r.y == 20);
assert (r.w == 100); assert (r.w == 100);
assert (r.h == 200); assert (r.h == 200);
let r2: rect = r; let r2: Rect = r;
let x: int = r2.x; let x: int = r2.x;
assert (x == 10); assert (x == 10);
f(r, 10, 20, 100, 200); f(r, 10, 20, 100, 200);

View file

@ -9,17 +9,17 @@
// except according to those terms. // except according to those terms.
enum t1 { a(int), b(uint), } enum t1 { a(int), b(uint), }
type t2 = {x: t1, y: int}; struct T2 {x: t1, y: int}
enum t3 { c(t2, uint), } enum t3 { c(T2, uint), }
fn m(in: t3) -> int { fn m(in: t3) -> int {
match in { match in {
c({x: a(m), _}, _) => { return m; } c(T2 {x: a(m), _}, _) => { return m; }
c({x: b(m), y: y}, z) => { return ((m + z) as int) + y; } c(T2 {x: b(m), y: y}, z) => { return ((m + z) as int) + y; }
} }
} }
fn main() { fn main() {
assert (m(c({x: a(10), y: 5}, 4u)) == 10); assert (m(c(T2 {x: a(10), y: 5}, 4u)) == 10);
assert (m(c({x: b(10u), y: 5}, 4u)) == 19); assert (m(c(T2 {x: b(10u), y: 5}, 4u)) == 19);
} }

View file

@ -29,9 +29,7 @@ fn align(size: uint, align: uint) -> uint {
((size + align) - 1u) & !(align - 1u) ((size + align) - 1u) & !(align - 1u)
} }
enum ptr_visit_adaptor<V: TyVisitor movable_ptr> = { enum ptr_visit_adaptor<V: TyVisitor movable_ptr> = Inner<V>;
inner: V
};
impl<V: TyVisitor movable_ptr> ptr_visit_adaptor<V> { impl<V: TyVisitor movable_ptr> ptr_visit_adaptor<V> {
@ -469,11 +467,13 @@ impl<V: TyVisitor movable_ptr> ptr_visit_adaptor<V>: TyVisitor {
} }
} }
enum my_visitor = @{ enum my_visitor = @Stuff;
struct Stuff {
mut ptr1: *c_void, mut ptr1: *c_void,
mut ptr2: *c_void, mut ptr2: *c_void,
mut vals: ~[~str] mut vals: ~[~str]
}; }
impl my_visitor { impl my_visitor {
fn get<T>(f: fn(T)) { fn get<T>(f: fn(T)) {
@ -485,13 +485,15 @@ impl my_visitor {
fn visit_inner(inner: *TyDesc) -> bool { fn visit_inner(inner: *TyDesc) -> bool {
unsafe { unsafe {
let u = my_visitor(*self); 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); visit_tydesc(inner, v as TyVisitor);
true true
} }
} }
} }
struct Inner<V> { inner: V }
impl my_visitor: movable_ptr { impl my_visitor: movable_ptr {
fn move_ptr(adjustment: fn(*c_void) -> *c_void) { fn move_ptr(adjustment: fn(*c_void) -> *c_void) {
self.ptr1 = adjustment(self.ptr1); self.ptr1 = adjustment(self.ptr1);
@ -622,14 +624,16 @@ fn get_tydesc_for<T>(&&_t: T) -> *TyDesc {
get_tydesc::<T>() get_tydesc::<T>()
} }
struct Triple { x: int, y: int, z: int }
fn main() { fn main() {
unsafe { 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 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 ptr2: p,
mut vals: ~[]}); mut vals: ~[]});
let v = ptr_visit_adaptor({inner: u}); let v = ptr_visit_adaptor(Inner {inner: u});
let td = get_tydesc_for(r); let td = get_tydesc_for(r);
unsafe { error!("tydesc sz: %u, align: %u", unsafe { error!("tydesc sz: %u, align: %u",
(*td).size, (*td).align); } (*td).size, (*td).align); }

View file

@ -8,14 +8,14 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // 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; return &p.x;
} }
fn main() { fn main() {
let p = @{x: 3, y: 4}; let p = @Point {x: 3, y: 4};
let xc = x_coord(p); let xc = x_coord(p);
assert *xc == 3; assert *xc == 3;
} }

View file

@ -14,36 +14,36 @@ extern mod std;
use libc, sys, cast; use libc, sys, cast;
use std::arena::Arena; use std::arena::Arena;
type bcx = { struct Bcx {
fcx: &fcx fcx: &Fcx
};
type fcx = {
arena: &Arena,
ccx: &ccx
};
type ccx = {
x: int
};
fn h(bcx : &r/bcx) -> &r/bcx {
return bcx.fcx.arena.alloc(|| { fcx: bcx.fcx });
} }
fn g(fcx : &fcx) { struct Fcx {
let bcx = { fcx: fcx }; arena: &Arena,
ccx: &Ccx
}
struct Ccx {
x: int
}
fn h(bcx : &r/Bcx) -> &r/Bcx {
return bcx.fcx.arena.alloc(|| Bcx { fcx: bcx.fcx });
}
fn g(fcx : &Fcx) {
let bcx = Bcx { fcx: fcx };
h(&bcx); h(&bcx);
} }
fn f(ccx : &ccx) { fn f(ccx : &Ccx) {
let a = Arena(); let a = Arena();
let fcx = &{ arena: &a, ccx: ccx }; let fcx = &Fcx { arena: &a, ccx: ccx };
return g(fcx); return g(fcx);
} }
fn main() { fn main() {
let ccx = { x: 0 }; let ccx = Ccx { x: 0 };
f(&ccx); f(&ccx);
} }

View file

@ -10,46 +10,46 @@
enum arena = (); enum arena = ();
type bcx = { struct Bcx {
fcx: &fcx fcx: &Fcx
}; }
type fcx = { struct Fcx {
arena: &arena, arena: &arena,
ccx: &ccx ccx: &Ccx
}; }
type ccx = { struct Ccx {
x: int x: int
}; }
fn alloc(_bcx : &arena) -> &bcx { fn alloc(_bcx : &arena) -> &Bcx {
unsafe { unsafe {
return cast::reinterpret_cast( 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); return alloc(bcx.fcx.arena);
} }
fn g(fcx : &fcx) { fn g(fcx : &Fcx) {
let bcx = { fcx: fcx }; let bcx = Bcx { fcx: fcx };
let bcx2 = h(&bcx); let bcx2 = h(&bcx);
unsafe { unsafe {
libc::free(cast::reinterpret_cast(&bcx2)); libc::free(cast::reinterpret_cast(&bcx2));
} }
} }
fn f(ccx : &ccx) { fn f(ccx : &Ccx) {
let a = arena(()); let a = arena(());
let fcx = { arena: &a, ccx: ccx }; let fcx = Fcx { arena: &a, ccx: ccx };
return g(&fcx); return g(&fcx);
} }
fn main() { fn main() {
let ccx = { x: 0 }; let ccx = Ccx { x: 0 };
f(&ccx); f(&ccx);
} }

View file

@ -8,18 +8,18 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
type clam = { chowder: &int }; struct Clam { chowder: &int }
trait get_chowder { trait get_chowder {
fn get_chowder() -> &self/int; fn get_chowder() -> &self/int;
} }
impl clam: get_chowder { impl Clam: get_chowder {
fn get_chowder() -> &self/int { return self.chowder; } fn get_chowder() -> &self/int { return self.chowder; }
} }
fn main() { fn main() {
let clam = { chowder: &3 }; let clam = Clam { chowder: &3 };
log(debug, *clam.get_chowder()); log(debug, *clam.get_chowder());
clam.get_chowder(); clam.get_chowder();
} }

View file

@ -8,16 +8,16 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
type ctxt = { v: uint }; struct Ctxt { v: uint }
trait get_ctxt { 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 { impl HasCtxt: get_ctxt {
fn get_ctxt() -> &self/ctxt { fn get_ctxt() -> &self/Ctxt {
self.c self.c
} }
} }
@ -27,8 +27,8 @@ fn get_v(gc: get_ctxt) -> uint {
} }
fn main() { fn main() {
let ctxt = { v: 22u }; let ctxt = Ctxt { v: 22 };
let hc = { c: &ctxt }; let hc = HasCtxt { c: &ctxt };
assert get_v(hc as get_ctxt) == 22u; assert get_v(hc as get_ctxt) == 22;
} }

Some files were not shown because too many files have changed in this diff Show more