@@ -1144,22 +1144,23 @@ Constants are declared with the `const` keyword.
11441144A constant item must have an expression giving its definition.
11451145The definition expression of a constant is limited to expression forms that can be evaluated at compile time.
11461146
1147- Constants must be explicitly typed. The type may be ``` bool ``` , ``` char ``` , a number, or a type derived from
1148- those primitive types. The derived types are borrowed pointers, static arrays, tuples, and structs.
1147+ Constants must be explicitly typed. The type may be ``` bool ``` , ``` char ``` , a number, or a type derived from those primitive types.
1148+ The derived types are borrowed pointers, static arrays, tuples, and structs.
1149+ Borrowed pointers must be have the ` 'static ` lifetime.
11491150
11501151~~~~
11511152const bit1: uint = 1 << 0;
11521153const bit2: uint = 1 << 1;
11531154
11541155const bits: [uint * 2] = [bit1, bit2];
1155- const string: &str = "bitstring";
1156+ const string: &'static str = "bitstring";
11561157
11571158struct BitsNStrings {
11581159 mybits: [uint *2],
1159- mystring: &str
1160+ mystring: &'self str
11601161}
11611162
1162- const bits_n_strings: BitsNStrings = BitsNStrings {
1163+ const bits_n_strings: BitsNStrings<'static> = BitsNStrings {
11631164 mybits: bits,
11641165 mystring: string
11651166};
@@ -1630,7 +1631,7 @@ The following are examples of structure expressions:
16301631~~~~
16311632# struct Point { x: float, y: float }
16321633# struct TuplePoint(float, float);
1633- # mod game { pub struct User { name: &str, age: uint, score: uint } }
1634+ # mod game { pub struct User<'self> { name: &'self str, age: uint, score: uint } }
16341635# struct Cookie; fn some_fn<T>(t: T) {}
16351636Point {x: 10f, y: 20f};
16361637TuplePoint(10f, 20f);
@@ -2556,8 +2557,8 @@ order specified by the tuple type.
25562557An example of a tuple type and its use:
25572558
25582559~~~~
2559- type Pair = (int,&str);
2560- let p: Pair = (10,"hello");
2560+ type Pair<'self> = (int,&'self str);
2561+ let p: Pair<'static> = (10,"hello");
25612562let (a, b) = p;
25622563assert b != "world";
25632564~~~~
@@ -2718,7 +2719,7 @@ fn add(x: int, y: int) -> int {
27182719
27192720let mut x = add(5,7);
27202721
2721- type Binop = fn(int,int) -> int;
2722+ type Binop<'self> = &'self fn(int,int) -> int;
27222723let bo: Binop = add;
27232724x = bo(5,7);
27242725~~~~~~~~
0 commit comments