Skip to content

Commit 5b084e4

Browse files
committed
Update docs to new let syntax.
1 parent 347230b commit 5b084e4

File tree

1 file changed

+65
-67
lines changed

1 file changed

+65
-67
lines changed

doc/rust.texi

Lines changed: 65 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ features of currying, in a smaller and simpler package.
342342
To save some quantity of programmer key-pressing, Rust supports local type
343343
inference: signatures of functions, objects and iterators always require type
344344
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.
346346

347347
@sp 1
348348
@item Structural object system
@@ -662,7 +662,6 @@ The keywords are:
662662
@tab @code{import}
663663
@tab @code{export}
664664
@tab @code{let}
665-
@tab @code{auto}
666665
@item @code{state}
667666
@tab @code{gc}
668667
@tab @code{const}
@@ -1222,9 +1221,9 @@ mod foo = "foo.rs";
12221221
12231222
// In the source file "foo.rs", use the #re syntax extension and
12241223
// 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);
12281227
@end example
12291228

12301229
@page
@@ -1375,7 +1374,7 @@ Box types and values are constructed by the @emph{at} sigil @code{@@}.
13751374

13761375
An example of constructing a box type and value:
13771376
@example
1378-
let @@int x = @@10;
1377+
let x: @@int = @@10;
13791378
@end example
13801379

13811380
Some operations implicitly dereference boxes. Examples of such @dfn{implicit
@@ -1387,8 +1386,8 @@ dereference} operations are:
13871386

13881387
An example of an implicit-dereference operation performed on box values:
13891388
@example
1390-
let @@int x = @@10;
1391-
let @@int y = @@12;
1389+
let x: @@int = @@10;
1390+
let y: @@int = @@12;
13921391
assert (x + y == 22);
13931392
@end example
13941393

@@ -1412,7 +1411,7 @@ fn takes_unboxed(int b) @{
14121411
@}
14131412
14141413
fn main() @{
1415-
let @@int x = @@10;
1414+
let x: @@int = @@10;
14161415
takes_boxed(x);
14171416
takes_unboxed(*x);
14181417
@}
@@ -1896,14 +1895,14 @@ each} loop or as the argument in a @code{put each} expression.
18961895
An example of an iterator:
18971896
@example
18981897
iter range(int lo, int hi) -> int @{
1899-
let int i = lo;
1898+
let i: int = lo;
19001899
while (i < hi) @{
19011900
put i;
19021901
i = i + 1;
19031902
@}
19041903
@}
19051904
1906-
let int sum = 0;
1905+
let sum: int = 0;
19071906
for each (int x in range(0,100)) @{
19081907
sum += x;
19091908
@}
@@ -1936,7 +1935,7 @@ obj counter(int state) @{
19361935
@}
19371936
@}
19381937
1939-
let counter c = counter(1);
1938+
let c: counter = counter(1);
19401939
19411940
c.incr();
19421941
c.incr();
@@ -1952,7 +1951,7 @@ obj my_obj() @{
19521951
ret 3;
19531952
@}
19541953
fn foo() @{
1955-
auto c = get(); // Fails
1954+
let c = get(); // Fails
19561955
@}
19571956
@}
19581957
@end example
@@ -1976,7 +1975,7 @@ fn mk_my_obj() -> my_obj @{
19761975
ret get_helper();
19771976
@}
19781977
fn foo() @{
1979-
auto c = get_helper(); // Works
1978+
let c = get_helper(); // Works
19801979
@}
19811980
@}
19821981
@@ -2040,7 +2039,7 @@ tag animal @{
20402039
cat;
20412040
@}
20422041
2043-
let animal a = dog;
2042+
let a: animal = dog;
20442043
a = cat;
20452044
@end example
20462045

@@ -2051,7 +2050,7 @@ tag list[T] @{
20512050
cons(T, @@list[T]);
20522051
@}
20532052
2054-
let list[int] a = cons(7, cons(13, nil));
2053+
let a: list[int] = cons(7, cons(13, nil));
20552054
@end example
20562055

20572056

@@ -2266,8 +2265,8 @@ the record type.
22662265
An example of a record type and its use:
22672266
@example
22682267
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;
22712270
@end example
22722271

22732272
@node Ref.Type.Tup
@@ -2284,7 +2283,7 @@ like a record, in order specified by the tuple type.
22842283
An example of a tuple type and its use:
22852284
@example
22862285
type pair = tup(int,str);
2287-
let pair p = tup(10,"hello");
2286+
let p: pair = tup(10,"hello");
22882287
assert (p._0 == 10);
22892288
p._1 = "world";
22902289
assert (p._1 == "world");
@@ -2307,9 +2306,9 @@ interval -- out of the sliced vector.
23072306

23082307
An example of a vector type and its use:
23092308
@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.
23132312
@end example
23142313

23152314
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
23182317
slot holding a vector:
23192318

23202319
@example
2321-
let mutable vec[int] v = [1, 2, 3];
2320+
let v: mutable vec[int] = [1, 2, 3];
23222321
v += [4, 5, 6];
23232322
@end example
23242323

@@ -2363,7 +2362,7 @@ fn add(int x, int y) -> int @{
23632362
let int x = add(5,7);
23642363
23652364
type binop = fn(int,int) -> int;
2366-
let binop bo = add;
2365+
let bo: binop = add;
23672366
x = bo(5,7);
23682367
@end example
23692368

@@ -2411,8 +2410,8 @@ mutable values can pass over a port or channel.
24112410
An example of a @code{port} type:
24122411
@example
24132412
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];
24162415
v <- p;
24172416
@end example
24182417

@@ -2450,8 +2449,8 @@ message is dropped.
24502449
An example of a @code{chan} type:
24512450
@example
24522451
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"];
24552454
c <| v;
24562455
@end example
24572456

@@ -2523,10 +2522,10 @@ fn give_ints(taker t) @{
25232522
t.take(3);
25242523
@}
25252524
2526-
let port[int] p = port();
2525+
let p: port[int] = port();
25272526
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));
25302529
25312530
give_ints(t1);
25322531
give_ints(t2);
@@ -2554,10 +2553,10 @@ An example of a constrained type with two separate instantiations:
25542553
@example
25552554
type ordered_range = @{low: int, high: int@} : less_than(*.low, *.high);
25562555
2557-
let ordered_range rng1 = @{low: 5, high: 7@};
2556+
let rng1: ordered_range = @{low: 5, high: 7@};
25582557
// implicit: 'check less_than(rng1.low, rng1.high);'
25592558
2560-
let ordered_range rng2 = @{low: 15, high: 17@};
2559+
let rng2: ordered_range = @{low: 15, high: 17@};
25612560
// implicit: 'check less_than(rng2.low, rng2.high);'
25622561
@end example
25632562

@@ -2696,8 +2695,8 @@ pred is_less_than(int a, int b) -> bool @{
26962695
@}
26972696
26982697
fn test() @{
2699-
let int x = 10;
2700-
let int y = 20;
2698+
let x: int = 10;
2699+
let y: int = 20;
27012700
check is_less_than(x,y);
27022701
@}
27032702
@end example
@@ -2890,27 +2889,27 @@ declaring a function-local item.
28902889
@cindex Local slot
28912890
@cindex Variable, see @i{Local slot}
28922891
@cindex Type inference
2893-
@cindex Automatic slot
28942892

28952893
A @code{slot declaration statement} has one one of two forms:
28962894

28972895
@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};
29002898
@end itemize
29012899

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.
29052904

29062905
Both forms introduce a new slot into the containing block scope. The new slot
29072906
is visible across the entire scope, but is initialized only at the point
29082907
following the declaration statement.
29092908

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
29142913
signatures must always declared types for all argument slots.
29152914
@xref{Ref.Mem.Slot}.
29162915

@@ -2953,8 +2952,7 @@ effects of the expression's evaluation.
29532952
* Ref.Expr.Prove:: Expression for static assertion of typestate.
29542953
* Ref.Expr.Check:: Expression for dynamic assertion of typestate.
29552954
* 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.
29582956
* Ref.Expr.IfCheck:: Expression for dynamic testing of typestate.
29592957
@end menu
29602958

@@ -3012,11 +3010,11 @@ fn helper(chan[u8] out) @{
30123010
out <| result;
30133011
@}
30143012
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));
30183016
// let task run, do other things.
3019-
auto result <- out;
3017+
let result <- out;
30203018
30213019
@end example
30223020

@@ -3070,7 +3068,7 @@ un-blocks the receiving task. @xref{Ref.Run.Comm}.
30703068
An example of a @emph{receive}:
30713069
@example
30723070
port[str] p = @dots{};
3073-
let str s <- p;
3071+
let s: str <- p;
30743072
@end example
30753073

30763074
@node Ref.Expr.Call
@@ -3090,7 +3088,7 @@ typestates propagate through function boundaries. @xref{Ref.Typestate}.
30903088

30913089
An example of a call expression:
30923090
@example
3093-
let int x = add(1, 2);
3091+
let x: int = add(1, 2);
30943092
@end example
30953093

30963094
@node Ref.Expr.Bind
@@ -3121,9 +3119,9 @@ fn add(int x, int y) -> int @{
31213119
@}
31223120
type single_param_fn = fn(int) -> int;
31233121
3124-
let single_param_fn add4 = bind add(4, _);
3122+
let add4: single_param_fn = bind add(4, _);
31253123
3126-
let single_param_fn add5 = bind add(_, 5);
3124+
let add5: single_param_fn = bind add(_, 5);
31273125
31283126
assert (add(4,5) == add4(5));
31293127
assert (add(4,5) == add5(4));
@@ -3368,7 +3366,7 @@ run the loop over the slice.
33683366

33693367
Example of 4 for loops, all identical:
33703368
@example
3371-
let vec[foo] v = [a, b, c];
3369+
let v: vec[foo] = [a, b, c];
33723370
33733371
for (foo e in v.(0, _vec.len(v))) @{
33743372
bar(e);
@@ -3400,8 +3398,8 @@ the iterator. When the iterator returns or fails, the loop terminates.
34003398

34013399
Example of a foreach loop:
34023400
@example
3403-
let str txt;
3404-
let vec[str] lines;
3401+
let txt: str;
3402+
let lines: vec[str];
34053403
for each (str s in _str.split(txt, "\n")) @{
34063404
vec.push(lines, s);
34073405
@}
@@ -3472,10 +3470,10 @@ branches to the block of that arm.
34723470

34733471
An example of a communication @code{alt} expression:
34743472
@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];
34793477
34803478
alt @{
34813479
case (str s <- p) @{
@@ -3504,15 +3502,15 @@ To execute a pattern @code{alt} expression, first the head expression is
35043502
evaluated, then its value is sequentially compared to the patterns in the arms
35053503
until a match is found. The first arm with a matching @code{case} pattern is
35063504
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.
35093507

35103508
An example of a pattern @code{alt} expression:
35113509

35123510
@example
35133511
type list[X] = tag(nil, cons(X, @@list[X]));
35143512
3515-
let list[int] x = cons(10, cons(11, nil));
3513+
let x: list[int] = cons(10, cons(11, nil));
35163514
35173515
alt (x) @{
35183516
case (cons(a, cons(b, _))) @{
@@ -3544,7 +3542,7 @@ the value in the @code{any}.
35443542
An example of an @code{alt type} expression:
35453543

35463544
@example
3547-
let any x = foo();
3545+
let x: any = foo();
35483546
35493547
alt type (x) @{
35503548
case (int i) @{
@@ -3606,7 +3604,7 @@ fn print_even(int x) : even(x) @{
36063604
@}
36073605
36083606
fn test() @{
3609-
let int y = 8;
3607+
let y: int = 8;
36103608
36113609
// Cannot call print_even(y) here.
36123610

0 commit comments

Comments
 (0)