Skip to content

Commit a24da7e

Browse files
committed
Discuss the types that may be used with const items.
Also removed vector example that doesn't compile. IMO closes #3341.
1 parent e5c9a8a commit a24da7e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

doc/rust.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,17 @@ Constants are declared with the `const` keyword.
11041104
A constant item must have an expression giving its definition.
11051105
The definition expression of a constant is limited to expression forms that can be evaluated at compile time.
11061106

1107+
Constants must be explicitly typed. The type may be ```bool```, ```char```, a number, or a type derived from
1108+
those primitive types. The derived types are borrowed pointers, static arrays, tuples, and structs.
1109+
1110+
~~~~
1111+
const bit1: uint = 1 << 0;
1112+
const bit2: uint = 1 << 1;
1113+
1114+
const bits: [uint * 2] = [bit1, bit2];
1115+
const bits_r: &[uint] = &bits;
1116+
~~~~
1117+
11071118
### Traits
11081119

11091120
A _trait_ describes a set of method types.
@@ -1562,7 +1573,6 @@ indicate that the elements of the resulting vector may be mutated.
15621573
When no mutability is specified, the vector is immutable.
15631574

15641575
~~~~
1565-
[]
15661576
[1, 2, 3, 4];
15671577
["a", "b", "c", "d"];
15681578
[0, ..128]; // vector with 128 zeros

0 commit comments

Comments
 (0)