You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/expressions/literal-expr.md
+37Lines changed: 37 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,8 +24,45 @@ Each of the lexical [literal][literal tokens] forms described earlier can make u
24
24
5; // integer type
25
25
```
26
26
27
+
## Integer literal expressions
28
+
29
+
An integer literal expression consists of a single [INTEGER_LITERAL] token.
30
+
31
+
If the token has a [suffix], the suffix will be the name of one of the [primitive integer types][numeric types]: `u8`, `i8`, `u16`, `i16`, `u32`, `i32`, `u64`, `i64`, `u128`, `i128`, `usize`, or `isize`, and the expression has that type.
32
+
33
+
If the token has no suffix, the expression's type is determined by type inference:
34
+
35
+
* If an integer type can be _uniquely_ determined from the surrounding program context, the expression has that type.
36
+
37
+
* If the program context under-constrains the type, it defaults to the signed 32-bit integer `i32`.
38
+
39
+
* If the program context over-constrains the type, it is considered a static type error.
Copy file name to clipboardExpand all lines: src/tokens.md
+16-29Lines changed: 16 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -359,43 +359,29 @@ An _integer literal_ has one of four forms:
359
359
(`0b`) and continues as any mixture (with at least one digit) of binary digits
360
360
and underscores.
361
361
362
-
Like any literal, an integer literal may be followed (immediately,
363
-
without any spaces) by an _integer suffix_, which forcibly sets the
364
-
type of the literal. The integer suffix must be the name of one of the
365
-
integral types: `u8`, `i8`, `u16`, `i16`, `u32`, `i32`, `u64`, `i64`,
366
-
`u128`, `i128`, `usize`, or `isize`.
367
-
368
-
The type of an _unsuffixed_ integer literal is determined by type inference:
369
-
370
-
* If an integer type can be _uniquely_ determined from the surrounding
371
-
program context, the unsuffixed integer literal has that type.
372
-
373
-
* If the program context under-constrains the type, it defaults to the
374
-
signed 32-bit integer `i32`.
375
-
376
-
* If the program context over-constrains the type, it is considered a
377
-
static type error.
362
+
Like any literal, an integer literal may be followed (immediately, without any spaces) by an _integer suffix_, which must be the name of one of the [primitive integer types][numeric types]:
0 commit comments