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 {
#[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 {
#[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 {
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>); }
// 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);
}
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(); }
// 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;
}
}
// 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
};
// 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
}
};
// 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;
}
// 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;
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);
// -*- 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);
}
// 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);
}
}
// 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;
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);
// 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;
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;
// 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;
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;
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;
// 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 {}
}
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 {}
}
// 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);
}
-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);
}
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);
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() {
// 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;
// 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));
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;
}
}
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);
}
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})
}
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)
}
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
}
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 }
}
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;
}
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(); }
// -*- 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);
}
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(); }
// 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);
}
// 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 };
// 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;
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(); }
// -*- 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);
}
// -*- 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);
// 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}");
}
// 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);
}
}
-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);
}
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() {
// 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); }
-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);
}
// 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);
}
// -*- 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);
// -*- 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);
-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);
}
// 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);
}
// 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);
}
// 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 });
}
i: @mut int,
}
+struct Box { x: r }
+
impl r : Drop {
fn finalize(&self) {
*(self.i) = *(self.i) + 1;
fn test_rec() {
let i = @mut 0;
{
- let a = move {x: r(i)};
+ let a = move Box {x: r(i)};
}
assert *i == 1;
}
fn test_box_rec() {
let i = @mut 0;
{
- let a = move @{
+ let a = move @Box {
x: r(i)
};
}
// 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()});
}
// Issue #1112
// Alignment of interior pointers to dynamic-size types
-type x<T> = {
+struct X<T> {
a: T,
b: u8,
c: bool,
e: u16,
f: u8,
g: u8
-};
+}
fn main() {
- let x: x<int> = {
+ let x: X<int> = X {
a: 12345678,
b: 9u8,
c: true,
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;
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@()->(){},
}
// 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
};
}
}
-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});
}
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,
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>
// 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;
})
}
+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));
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);
}
// 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];
}
// -*- rust -*-
-fn f() {
- let foo:
- {a: int,
+
+struct Large {a: int,
b: int,
c: int,
d: int,
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,
// 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 };
}
// 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) )
}
// 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);
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);
}
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>() {
// 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,
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,
// 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);
// 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);
// 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); }
// 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); }
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);
}
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);
}
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;
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); }
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;
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);
+}
// 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}];
}
// 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(_), _} => {}
}
}
// 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;
}
// 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);
}
// 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
// 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);
}
// 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',
}
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;
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;
// -*- 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); }
}
// 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")]
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}}";
}
}
// 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")]
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}}";
}
// -*- 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);
}
// -*- 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);
// 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);
}
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);
// -*- 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);
}
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);
// 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);
}
((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> {
}
}
-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)) {
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);
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); }
// 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;
}
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);
}
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);
}
// 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();
}
// 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
}
}
}
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;
}
}
}
-enum t = {
+enum t = Node;
+
+struct Node {
mut next: Option<@t>,
r: r
-};
+}
fn main() {
unsafe {
let i2p = cast::reinterpret_cast(&i2);
cast::forget(move i2);
- let x1 = @t({
+ let x1 = @t(Node{
mut next: None,
r: {
let rs = r(i1p);
cast::reinterpret_cast::<@t, uint>(&x1),
cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(&(x1.r))));
- let x2 = @t({
+ let x2 = @t(Node{
mut next: None,
r: {
let rs = r(i2p);
// Don't leak the unique pointers
-type u = {
+struct U {
a: int,
b: int,
c: *int
-};
+}
struct r {
- v: u,
+ v: U,
}
impl r : Drop {
}
}
-fn r(v: u) -> r {
+fn r(v: U) -> r {
r {
v: v
}
}
-enum t = {
+enum t = Node;
+
+struct Node {
mut next: Option<@t>,
r: r
-};
+}
fn main() {
unsafe {
let i2p = cast::reinterpret_cast(&i2);
cast::forget(move i2);
- let u1 = {a: 0xB, b: 0xC, c: i1p};
- let u2 = {a: 0xB, b: 0xC, c: i2p};
+ let u1 = U {a: 0xB, b: 0xC, c: i1p};
+ let u2 = U {a: 0xB, b: 0xC, c: i2p};
- let x1 = @t({
+ let x1 = @t(Node {
mut next: None,
r: r(u1)
});
- let x2 = @t({
+ let x2 = @t(Node {
mut next: None,
r: r(u2)
});
// Don't leak the unique pointers
-type u = {
+struct U {
a: int,
b: int,
c: *int
-};
+}
-struct r {
- v: u,
+struct R {
+ v: U,
w: int,
x: *int,
}
-impl r : Drop {
+impl R : Drop {
fn finalize(&self) {
unsafe {
let _v2: ~int = cast::reinterpret_cast(&self.v.c);
}
}
-fn r(v: u, w: int, _x: *int) -> r {
+fn r(v: U, w: int, _x: *int) -> R {
unsafe {
- r {
+ R {
v: v,
w: w,
x: cast::reinterpret_cast(&0)
}
}
-enum t = {
+enum t = Node;
+
+struct Node {
mut next: Option<@t>,
- r: r
-};
+ r: R
+}
fn main() {
unsafe {
let i2p = cast::reinterpret_cast(&i2);
cast::forget(move i2);
- let u1 = {a: 0xB, b: 0xC, c: i1p};
- let u2 = {a: 0xB, b: 0xC, c: i2p};
+ let u1 = U {a: 0xB, b: 0xC, c: i1p};
+ let u2 = U {a: 0xB, b: 0xC, c: i2p};
- let x1 = @t({
+ let x1 = @t(Node{
mut next: None,
r: r(u1, 42, i1p)
});
- let x2 = @t({
+ let x2 = @t(Node{
mut next: None,
r: r(u2, 42, i2p)
});
// xfail-fast
#[legacy_modes];
+struct Arg<T> {val: T, fin: extern fn(T)}
+
struct finish<T: Copy> {
- arg: {val: T, fin: extern fn(T)},
+ arg: Arg<T>
}
impl<T: Copy> finish<T> : Drop {
}
}
-fn finish<T: Copy>(arg: {val: T, fin: extern fn(T)}) -> finish<T> {
+fn finish<T: Copy>(arg: Arg<T>) -> finish<T> {
finish {
arg: arg
}
let box = @mut 10;
fn dec_box(&&i: @mut int) { *i -= 1; }
- { let _i = move finish({val: box, fin: dec_box}); }
+ { let _i = move finish(Arg{val: box, fin: dec_box}); }
assert (*box == 9);
}
// that has a size that is not a power of two
// A 12-byte unit to ::core::oldcomm::send over the channel
-type record = {val1: u32, val2: u32, val3: u32};
+struct Record {val1: u32, val2: u32, val3: u32}
// Assuming that the default buffer size needs to hold 8 units,
fn test_init() {
let myport = ::core::oldcomm::Port();
let mychan = ::core::oldcomm::Chan(&myport);
- let val: record = {val1: 0u32, val2: 0u32, val3: 0u32};
+ let val: Record = Record {val1: 0u32, val2: 0u32, val3: 0u32};
::core::oldcomm::send(mychan, val);
}
let myport = ::core::oldcomm::Port();
let mychan = ::core::oldcomm::Chan(&myport);
for uint::range(0u, 100u) |i| {
- let val: record = {val1: 0u32, val2: 0u32, val3: 0u32};
+ let val: Record = Record {val1: 0u32, val2: 0u32, val3: 0u32};
::core::oldcomm::send(mychan, val);
}
}
let myport = ::core::oldcomm::Port();
let mychan = ::core::oldcomm::Chan(&myport);
for uint::range(0u, 100u) |_i| {
- let val: record = {val1: 0u32, val2: 0u32, val3: 0u32};
+ let val: Record = Record {val1: 0u32, val2: 0u32, val3: 0u32};
::core::oldcomm::send(mychan, val);
}
for uint::range(0u, 100u) |_i| { let x = ::core::oldcomm::recv(myport); }
let myport = ::core::oldcomm::Port();
let mychan = ::core::oldcomm::Chan(&myport);
for uint::range(0u, 100u) |i| {
- let val = {val1: i as u32, val2: i as u32, val3: i as u32};
+ let val = Record {val1: i as u32, val2: i as u32, val3: i as u32};
::core::oldcomm::send(mychan, val);
let x = ::core::oldcomm::recv(myport);
assert (x.val1 == i as u32);
// Test rotating and growing the buffer when
// the unit size is not a power of two
fn test_rotate_grow() {
- let myport = ::core::oldcomm::Port::<record>();
+ let myport = ::core::oldcomm::Port::<Record>();
let mychan = ::core::oldcomm::Chan(&myport);
for uint::range(0u, 10u) |j| {
for uint::range(0u, 10u) |i| {
- let val: record =
- {val1: i as u32, val2: i as u32, val3: i as u32};
+ let val: Record =
+ Record {val1: i as u32, val2: i as u32, val3: i as u32};
::core::oldcomm::send(mychan, val);
}
for uint::range(0u, 10u) |i| {
fn main() { test05(); }
-type pair<A,B> = { a: A, b: B };
+struct Pair<A,B> { a: A, b: B }
-fn make_generic_record<A: Copy, B: Copy>(a: A, b: B) -> pair<A,B> {
- return {a: a, b: b};
+fn make_generic_record<A: Copy, B: Copy>(a: A, b: B) -> Pair<A,B> {
+ return Pair {a: a, b: b};
}
-fn test05_start(&&f: fn~(&&v: float, &&v: ~str) -> pair<float, ~str>) {
+fn test05_start(&&f: fn~(&&v: float, &&v: ~str) -> Pair<float, ~str>) {
let p = f(22.22f, ~"Hi");
log(debug, copy p);
assert p.a == 22.22f;
assert q.b == ~"Ho";
}
-fn spawn<A: Copy, B: Copy>(f: extern fn(fn~(A,B)->pair<A,B>)) {
- let arg = fn~(a: A, b: B) -> pair<A,B> {
+fn spawn<A: Copy, B: Copy>(f: extern fn(fn~(A,B)->Pair<A,B>)) {
+ let arg = fn~(a: A, b: B) -> Pair<A,B> {
return make_generic_record(a, b);
};
task::spawn(|| f(arg) );
//hack (as opposed to option), to make `span` compile
os_none,
- os_some(@span),
+ os_some(@Span),
}
-type span = {lo: uint, hi: uint, expanded_from: opt_span};
-type spanned<T> = { data: T, span: span };
+struct Span {lo: uint, hi: uint, expanded_from: opt_span}
+struct Spanned<T> { data: T, span: Span }
type ty_ = uint;
-type path_ = { global: bool, idents: ~[~str], types: ~[@ty] };
-type path = spanned<path_>;
-type ty = spanned<ty_>;
+struct Path_ { global: bool, idents: ~[~str], types: ~[@ty] }
+type path = Spanned<Path_>;
+type ty = Spanned<ty_>;
+
+struct X { sp: Span, path: path }
fn main() {
- let sp: span = {lo: 57451u, hi: 57542u, expanded_from: os_none};
- let t: @ty = @{ data: 3u, span: sp };
- let p_: path_ = { global: true, idents: ~[~"hi"], types: ~[t] };
- let p: path = { data: p_, span: sp };
- let x = { sp: sp, path: p };
+ let sp: Span = Span {lo: 57451u, hi: 57542u, expanded_from: os_none};
+ let t: @ty = @Spanned { data: 3u, span: sp };
+ let p_: Path_ = Path_ { global: true, idents: ~[~"hi"], types: ~[t] };
+ let p: path = Spanned { data: p_, span: sp };
+ let x = X { sp: sp, path: p };
log(error, copy x.path);
log(error, copy x);
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-type quad = { a: u64, b: u64, c: u64, d: u64 };
-type floats = { a: f64, b: u8, c: f64 };
+struct Quad { a: u64, b: u64, c: u64, d: u64 }
+struct Floats { a: f64, b: u8, c: f64 }
#[nolink]
extern mod rustrt {
#[legacy_exports];
- fn debug_abi_1(++q: quad) -> quad;
- fn debug_abi_2(++f: floats) -> floats;
+ fn debug_abi_1(++q: Quad) -> Quad;
+ fn debug_abi_2(++f: Floats) -> Floats;
}
fn test1() {
unsafe {
- let q = { a: 0xaaaa_aaaa_aaaa_aaaa_u64,
+ let q = Quad { a: 0xaaaa_aaaa_aaaa_aaaa_u64,
b: 0xbbbb_bbbb_bbbb_bbbb_u64,
c: 0xcccc_cccc_cccc_cccc_u64,
d: 0xdddd_dddd_dddd_dddd_u64 };
#[cfg(target_arch = "x86_64")]
fn test2() {
unsafe {
- let f = { a: 1.234567890e-15_f64,
+ let f = Floats { a: 1.234567890e-15_f64,
b: 0b_1010_1010_u8,
c: 1.0987654321e-15_f64 };
let ff = rustrt::debug_abi_2(f);
// Tests of ports and channels on various types
fn test_rec() {
- type r = {val0: int, val1: u8, val2: char};
+ struct R {val0: int, val1: u8, val2: char}
let (po, ch) = pipes::stream();
- let r0: r = {val0: 0, val1: 1u8, val2: '2'};
+ let r0: R = R {val0: 0, val1: 1u8, val2: '2'};
ch.send(r0);
- let mut r1: r;
+ let mut r1: R;
r1 = po.recv();
assert (r1.val0 == 0);
assert (r1.val1 == 1u8);
// Test cyclic detector when using trait instances.
-enum Tree = TreeR;
-type TreeR = @{
+enum Tree = @TreeR;
+struct TreeR {
mut left: Option<Tree>,
mut right: Option<Tree>,
val: to_str
-};
+}
trait to_str {
fn to_str() -> ~str;
fn foo<T: to_str>(x: T) -> ~str { x.to_str() }
fn main() {
- let t1 = Tree(@{mut left: None,
+ let t1 = Tree(@TreeR{mut left: None,
mut right: None,
val: 1 as to_str });
- let t2 = Tree(@{mut left: Some(t1),
+ let t2 = Tree(@TreeR{mut left: Some(t1),
mut right: Some(t1),
val: 2 as to_str });
let expected = ~"[2, some([1, none, none]), some([1, none, none])]";
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-type a = {a: int};
+struct A { a: int }
-fn a(a: a) -> int { return a.a; }
+fn a(a: A) -> int { return a.a; }
-fn main() { let x: a = {a: 1}; assert (a(x) == 1); }
+fn main() { let x: A = A {a: 1}; assert (a(x) == 1); }
enum maybe_pointy {
none,
- p(@pointy),
+ p(@Pointy),
}
-type pointy = {
+struct Pointy {
mut a : maybe_pointy,
d : fn~() -> uint,
-};
+}
fn make_uniq_closure<A:Owned Copy>(a: A) -> fn~() -> uint {
fn~() -> uint { ptr::addr_of(&a) as uint }
}
-fn empty_pointy() -> @pointy {
- return @{
+fn empty_pointy() -> @Pointy {
+ return @Pointy {
mut a : none,
d : make_uniq_closure(~"hi")
}
enum maybe_pointy {
none,
- p(@pointy),
+ p(@Pointy),
}
-type pointy = {
+struct Pointy {
mut a : maybe_pointy,
c : ~int,
d : fn~()->(),
-};
+}
-fn empty_pointy() -> @pointy {
- return @{
+fn empty_pointy() -> @Pointy {
+ return @Pointy {
mut a : none,
c : ~22,
d : fn~()->(){},
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+struct J { j: int }
+
fn main() {
- let i = ~{
+ let i = ~J {
j: 100
};
assert i.j == 100;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+struct Foo { a: int, b: int }
+
fn main() {
- let ~{a, b} = ~{a: 100, b: 200};
+ let ~Foo{a, b} = ~Foo{a: 100, b: 200};
assert a + b == 300;
}
\ No newline at end of file
// 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);
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+struct X { x: int }
fn main() {
- let x = ~{x: 1};
+ let x = ~X {x: 1};
let bar = x;
assert bar.x == 1;
}
+struct Pair { x: int, y: int }
+
fn main() {
// This just tests whether the vec leaks its members.
- let pvec: ~[@{x: int, y: int}] =
- ~[@{x: 1, y: 2}, @{x: 3, y: 4}, @{x: 5, y: 6}];
+ let pvec: ~[@Pair] =
+ ~[@Pair{x: 1, y: 2}, @Pair{x: 3, y: 4}, @Pair{x: 5, y: 6}];
}
// -*- rust -*-
-type point = {x: int, y: int, mut z: int};
+struct Point {x: int, y: int, mut z: int}
-fn f(p: &mut point) { p.z = 13; }
+fn f(p: &mut Point) { p.z = 13; }
fn main() {
- let mut x: point = {x: 10, y: 11, mut z: 12};
+ let mut x: Point = Point {x: 10, y: 11, mut z: 12};
f(&mut x);
assert (x.z == 13);
}