@@ -342,7 +342,7 @@ features of currying, in a smaller and simpler package.
342
342
To save some quantity of programmer key-pressing, Rust supports local type
343
343
inference: signatures of functions, objects and iterators always require type
344
344
annotation, but within the body of a function or iterator many slots can be
345
- declared @code { auto } and Rust will infer the slot's type from its uses.
345
+ declared without a type, and Rust will infer the slot's type from its uses.
346
346
347
347
@sp 1
348
348
@item Structural object system
@@ -662,7 +662,6 @@ The keywords are:
662
662
@tab @code {import }
663
663
@tab @code {export }
664
664
@tab @code {let }
665
- @tab @code {auto }
666
665
@item @code {state }
667
666
@tab @code {gc }
668
667
@tab @code {const }
@@ -1222,9 +1221,9 @@ mod foo = "foo.rs";
1222
1221
1223
1222
// In the source file "foo.rs", use the #re syntax extension and
1224
1223
// the re module at run-time.
1225
- let str s = get_string();
1226
- let regex pattern = #re.pat@{ aa+b? @} ;
1227
- let bool matched = re.match(pattern, s);
1224
+ let s: str = get_string();
1225
+ let pattern: regex = #re.pat@{ aa+b? @} ;
1226
+ let matched: bool = re.match(pattern, s);
1228
1227
@end example
1229
1228
1230
1229
@page
@@ -1375,7 +1374,7 @@ Box types and values are constructed by the @emph{at} sigil @code{@@}.
1375
1374
1376
1375
An example of constructing a box type and value:
1377
1376
@example
1378
- let @@ int x = @@ 10;
1377
+ let x: @@ int = @@ 10;
1379
1378
@end example
1380
1379
1381
1380
Some operations implicitly dereference boxes. Examples of such @dfn {implicit
@@ -1387,8 +1386,8 @@ dereference} operations are:
1387
1386
1388
1387
An example of an implicit-dereference operation performed on box values:
1389
1388
@example
1390
- let @@ int x = @@ 10;
1391
- let @@ int y = @@ 12;
1389
+ let x: @@ int = @@ 10;
1390
+ let y: @@ int = @@ 12;
1392
1391
assert (x + y == 22);
1393
1392
@end example
1394
1393
@@ -1412,7 +1411,7 @@ fn takes_unboxed(int b) @{
1412
1411
@}
1413
1412
1414
1413
fn main() @{
1415
- let @@ int x = @@ 10;
1414
+ let x: @@ int = @@ 10;
1416
1415
takes_boxed(x);
1417
1416
takes_unboxed(*x);
1418
1417
@}
@@ -1896,14 +1895,14 @@ each} loop or as the argument in a @code{put each} expression.
1896
1895
An example of an iterator:
1897
1896
@example
1898
1897
iter range(int lo, int hi) -> int @{
1899
- let int i = lo;
1898
+ let i: int = lo;
1900
1899
while (i < hi) @{
1901
1900
put i;
1902
1901
i = i + 1;
1903
1902
@}
1904
1903
@}
1905
1904
1906
- let int sum = 0;
1905
+ let sum: int = 0;
1907
1906
for each (int x in range(0,100)) @{
1908
1907
sum += x;
1909
1908
@}
@@ -1936,7 +1935,7 @@ obj counter(int state) @{
1936
1935
@}
1937
1936
@}
1938
1937
1939
- let counter c = counter(1);
1938
+ let c: counter = counter(1);
1940
1939
1941
1940
c.incr();
1942
1941
c.incr();
@@ -1952,7 +1951,7 @@ obj my_obj() @{
1952
1951
ret 3;
1953
1952
@}
1954
1953
fn foo() @{
1955
- auto c = get(); // Fails
1954
+ let c = get(); // Fails
1956
1955
@}
1957
1956
@}
1958
1957
@end example
@@ -1976,7 +1975,7 @@ fn mk_my_obj() -> my_obj @{
1976
1975
ret get_helper();
1977
1976
@}
1978
1977
fn foo() @{
1979
- auto c = get_helper(); // Works
1978
+ let c = get_helper(); // Works
1980
1979
@}
1981
1980
@}
1982
1981
@@ -2040,7 +2039,7 @@ tag animal @{
2040
2039
cat;
2041
2040
@}
2042
2041
2043
- let animal a = dog;
2042
+ let a: animal = dog;
2044
2043
a = cat;
2045
2044
@end example
2046
2045
@@ -2051,7 +2050,7 @@ tag list[T] @{
2051
2050
cons(T, @@ list[T]);
2052
2051
@}
2053
2052
2054
- let list[int] a = cons(7, cons(13, nil));
2053
+ let a: list[int] = cons(7, cons(13, nil));
2055
2054
@end example
2056
2055
2057
2056
@@ -2266,8 +2265,8 @@ the record type.
2266
2265
An example of a record type and its use:
2267
2266
@example
2268
2267
type point = @{ x: int, y: int@} ;
2269
- let point p = @{ x: 10, y: 11@} ;
2270
- let int px = p.x;
2268
+ let p: point = @{ x: 10, y: 11@} ;
2269
+ let px: int = p.x;
2271
2270
@end example
2272
2271
2273
2272
@node Ref.Type.Tup
@@ -2284,7 +2283,7 @@ like a record, in order specified by the tuple type.
2284
2283
An example of a tuple type and its use:
2285
2284
@example
2286
2285
type pair = tup(int,str);
2287
- let pair p = tup(10,"hello");
2286
+ let p: pair = tup(10,"hello");
2288
2287
assert (p._0 == 10);
2289
2288
p._1 = "world";
2290
2289
assert (p._1 == "world");
@@ -2307,9 +2306,9 @@ interval -- out of the sliced vector.
2307
2306
2308
2307
An example of a vector type and its use:
2309
2308
@example
2310
- let [int] v = [7, 5, 3];
2311
- let int i = v.(2);
2312
- let [int] v2 = v.(0,1); // Form a slice.
2309
+ let v: [int] = [7, 5, 3];
2310
+ let i: int = v.(2);
2311
+ let v2: [int] = v.(0,1); // Form a slice.
2313
2312
@end example
2314
2313
2315
2314
Vectors always @emph {allocate } a storage region sufficient to store the first
@@ -2318,7 +2317,7 @@ vector. This behaviour supports idiomatic in-place ``growth'' of a mutable
2318
2317
slot holding a vector:
2319
2318
2320
2319
@example
2321
- let mutable vec[int] v = [1, 2, 3];
2320
+ let v: mutable vec[int] = [1, 2, 3];
2322
2321
v += [4, 5, 6];
2323
2322
@end example
2324
2323
@@ -2363,7 +2362,7 @@ fn add(int x, int y) -> int @{
2363
2362
let int x = add(5,7);
2364
2363
2365
2364
type binop = fn(int,int) -> int;
2366
- let binop bo = add;
2365
+ let bo: binop = add;
2367
2366
x = bo(5,7);
2368
2367
@end example
2369
2368
@@ -2411,8 +2410,8 @@ mutable values can pass over a port or channel.
2411
2410
An example of a @code {port } type:
2412
2411
@example
2413
2412
type port[vec[str]] svp;
2414
- let svp p = get_port();
2415
- let vec[str] v ;
2413
+ let p: svp = get_port();
2414
+ let v: vec[str];
2416
2415
v <- p;
2417
2416
@end example
2418
2417
@@ -2450,8 +2449,8 @@ message is dropped.
2450
2449
An example of a @code {chan } type:
2451
2450
@example
2452
2451
type chan[vec[str]] svc;
2453
- let svc c = get_chan();
2454
- let vec[str] v = ["hello", "world"];
2452
+ let c: svc = get_chan();
2453
+ let v: vec[str] = ["hello", "world"];
2455
2454
c <| v;
2456
2455
@end example
2457
2456
@@ -2523,10 +2522,10 @@ fn give_ints(taker t) @{
2523
2522
t.take(3);
2524
2523
@}
2525
2524
2526
- let port[int] p = port();
2525
+ let p: port[int] = port();
2527
2526
2528
- let taker t1 = adder(0);
2529
- let taker t2 = sender(chan(p));
2527
+ let t1: taker = adder(0);
2528
+ let t2: taker = sender(chan(p));
2530
2529
2531
2530
give_ints(t1);
2532
2531
give_ints(t2);
@@ -2554,10 +2553,10 @@ An example of a constrained type with two separate instantiations:
2554
2553
@example
2555
2554
type ordered_range = @{ low: int, high: int@} : less_than(*.low, *.high);
2556
2555
2557
- let ordered_range rng1 = @{ low: 5, high: 7@} ;
2556
+ let rng1: ordered_range = @{ low: 5, high: 7@} ;
2558
2557
// implicit: 'check less_than(rng1.low, rng1.high);'
2559
2558
2560
- let ordered_range rng2 = @{ low: 15, high: 17@} ;
2559
+ let rng2: ordered_range = @{ low: 15, high: 17@} ;
2561
2560
// implicit: 'check less_than(rng2.low, rng2.high);'
2562
2561
@end example
2563
2562
@@ -2696,8 +2695,8 @@ pred is_less_than(int a, int b) -> bool @{
2696
2695
@}
2697
2696
2698
2697
fn test() @{
2699
- let int x = 10;
2700
- let int y = 20;
2698
+ let x: int = 10;
2699
+ let y: int = 20;
2701
2700
check is_less_than(x,y);
2702
2701
@}
2703
2702
@end example
@@ -2890,27 +2889,27 @@ declaring a function-local item.
2890
2889
@cindex Local slot
2891
2890
@cindex Variable , see @i {Local slot }
2892
2891
@cindex Type inference
2893
- @cindex Automatic slot
2894
2892
2895
2893
A @code {slot declaration statement } has one one of two forms:
2896
2894
2897
2895
@itemize
2898
- @item @code {let } @var {type } @var { slot } @var {optional-init };
2899
- @item @code {auto } @var {slot } @var {optional-init };
2896
+ @item @code {let } @var {pattern } @var {optional-init };
2897
+ @item @code {let } @var {pattern } : @var { type } @var {optional-init };
2900
2898
@end itemize
2901
2899
2902
- Where @var {type } is a type expression, @var {slot } is the name of the slot
2903
- being declared, and @var {optional-init } is either the empty string or an
2904
- equals sign (@code {= }) followed by a primitive expression.
2900
+ Where @var {type } is a type expression, @var {pattern } is an irrefutable pattern
2901
+ (often just the name of a single slot), and @var {optional-init } is an optional
2902
+ initializer. If present, the initializer consists of either an equals sign
2903
+ (@code {= }) or move operator (@code {<- }), followed by an expression.
2905
2904
2906
2905
Both forms introduce a new slot into the containing block scope. The new slot
2907
2906
is visible across the entire scope, but is initialized only at the point
2908
2907
following the declaration statement.
2909
2908
2910
- The latter ( @code { auto }) form of slot declaration causes the compiler to infer
2911
- the static type of the slot through unification with the types of values
2912
- assigned to the slot in the remaining code in the block scope. Inference only
2913
- occurs on frame-local slots, not argument slots. Function, iterator and object
2909
+ The former form, with no type annotation, causes the compiler to infer the
2910
+ static type of the slot through unification with the types of values assigned
2911
+ to the slot in the remaining code in the block scope. Inference only occurs on
2912
+ frame-local slots, not argument slots. Function, iterator and object
2914
2913
signatures must always declared types for all argument slots.
2915
2914
@xref {Ref.Mem.Slot }.
2916
2915
@@ -2953,8 +2952,7 @@ effects of the expression's evaluation.
2953
2952
* Ref.Expr.Prove :: Expression for static assertion of typestate.
2954
2953
* Ref.Expr.Check :: Expression for dynamic assertion of typestate.
2955
2954
* Ref.Expr.Claim :: Expression for static (unsafe) or dynamic assertion of typestate.
2956
- * Ref.Expr.Assert :: Expression for halting the program if a
2957
- boolean condition fails to hold.
2955
+ * Ref.Expr.Assert :: Expression for halting the program if a boolean condition fails to hold.
2958
2956
* Ref.Expr.IfCheck :: Expression for dynamic testing of typestate.
2959
2957
@end menu
2960
2958
@@ -3012,11 +3010,11 @@ fn helper(chan[u8] out) @{
3012
3010
out <| result;
3013
3011
@}
3014
3012
3015
- let port[u8] out ;
3016
- let task p = spawn helper(chan(out));
3017
- let task p2 = spawn "my_helper" helper(chan(out));
3013
+ let out: port[u8];
3014
+ let p: task = spawn helper(chan(out));
3015
+ let p2: task = spawn "my_helper" helper(chan(out));
3018
3016
// let task run, do other things.
3019
- auto result <- out;
3017
+ let result <- out;
3020
3018
3021
3019
@end example
3022
3020
@@ -3070,7 +3068,7 @@ un-blocks the receiving task. @xref{Ref.Run.Comm}.
3070
3068
An example of a @emph {receive }:
3071
3069
@example
3072
3070
port[str] p = @dots {};
3073
- let str s <- p;
3071
+ let s: str <- p;
3074
3072
@end example
3075
3073
3076
3074
@node Ref.Expr.Call
@@ -3090,7 +3088,7 @@ typestates propagate through function boundaries. @xref{Ref.Typestate}.
3090
3088
3091
3089
An example of a call expression:
3092
3090
@example
3093
- let int x = add(1, 2);
3091
+ let x: int = add(1, 2);
3094
3092
@end example
3095
3093
3096
3094
@node Ref.Expr.Bind
@@ -3121,9 +3119,9 @@ fn add(int x, int y) -> int @{
3121
3119
@}
3122
3120
type single_param_fn = fn(int) -> int;
3123
3121
3124
- let single_param_fn add4 = bind add(4, _);
3122
+ let add4: single_param_fn = bind add(4, _);
3125
3123
3126
- let single_param_fn add5 = bind add(_, 5);
3124
+ let add5: single_param_fn = bind add(_, 5);
3127
3125
3128
3126
assert (add(4,5) == add4(5));
3129
3127
assert (add(4,5) == add5(4));
@@ -3368,7 +3366,7 @@ run the loop over the slice.
3368
3366
3369
3367
Example of 4 for loops, all identical:
3370
3368
@example
3371
- let vec[foo] v = [a, b, c];
3369
+ let v: vec[foo] = [a, b, c];
3372
3370
3373
3371
for (foo e in v.(0, _vec.len(v))) @{
3374
3372
bar(e);
@@ -3400,8 +3398,8 @@ the iterator. When the iterator returns or fails, the loop terminates.
3400
3398
3401
3399
Example of a foreach loop:
3402
3400
@example
3403
- let str txt;
3404
- let vec[str] lines ;
3401
+ let txt: str ;
3402
+ let lines: vec[str];
3405
3403
for each (str s in _str.split(txt, "\n")) @{
3406
3404
vec.push(lines, s);
3407
3405
@}
@@ -3472,10 +3470,10 @@ branches to the block of that arm.
3472
3470
3473
3471
An example of a communication @code {alt } expression:
3474
3472
@example
3475
- let chan c [int] = foo();
3476
- let port p [str] = bar();
3477
- let int x = 0;
3478
- let vec[str] strs ;
3473
+ let c: chan [int] = foo();
3474
+ let p: port [str] = bar();
3475
+ let x: int = 0;
3476
+ let strs: vec[str];
3479
3477
3480
3478
alt @{
3481
3479
case (str s <- p) @{
@@ -3504,15 +3502,15 @@ To execute a pattern @code{alt} expression, first the head expression is
3504
3502
evaluated, then its value is sequentially compared to the patterns in the arms
3505
3503
until a match is found. The first arm with a matching @code {case } pattern is
3506
3504
chosen as the branch target of the @code {alt }, any variables bound by the
3507
- pattern are assigned to local @emph { auto } slots in the arm's block, and
3508
- control enters the block.
3505
+ pattern are assigned to local slots in the arm's block, and control enters the
3506
+ block.
3509
3507
3510
3508
An example of a pattern @code {alt } expression:
3511
3509
3512
3510
@example
3513
3511
type list[X] = tag(nil, cons(X, @@ list[X]));
3514
3512
3515
- let list[int] x = cons(10, cons(11, nil));
3513
+ let x: list[int] = cons(10, cons(11, nil));
3516
3514
3517
3515
alt (x) @{
3518
3516
case (cons(a, cons(b, _))) @{
@@ -3544,7 +3542,7 @@ the value in the @code{any}.
3544
3542
An example of an @code {alt type } expression:
3545
3543
3546
3544
@example
3547
- let any x = foo();
3545
+ let x: any = foo();
3548
3546
3549
3547
alt type (x) @{
3550
3548
case (int i) @{
@@ -3606,7 +3604,7 @@ fn print_even(int x) : even(x) @{
3606
3604
@}
3607
3605
3608
3606
fn test() @{
3609
- let int y = 8;
3607
+ let y: int = 8;
3610
3608
3611
3609
// Cannot call print_even(y) here.
3612
3610
0 commit comments