Skip to content

Commit 15f8c45

Browse files
committed
---
yaml --- r: 24101 b: refs/heads/master c: 3b89dcb h: refs/heads/master i: 24099: a9316fa v: v3
1 parent 501622b commit 15f8c45

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 4081b40523c7059a742dc11193fea7356495c614
2+
refs/heads/master: 3b89dcbdf2de3f757556639cd7323c60d343c4d2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/doc/tutorial.md

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -408,34 +408,30 @@ error. Read about [single-variant enums](#single_variant_enum)
408408
further on if you need to create a type name that's not just a
409409
synonym.
410410

411-
## Numeric literals
411+
## Literals
412412

413413
Integers can be written in decimal (`144`), hexadecimal (`0x90`), and
414-
binary (`0b10010000`) base.
414+
binary (`0b10010000`) base. Each integral type has a corresponding literal
415+
suffix that can be used to indicate the type of a literal: `i` for `int`,
416+
`u` for `uint`, and `i8` for the `i8` type, etc.
415417

416-
If you write an integer literal without a suffix (`3`, `-500`, etc.),
417-
the Rust compiler will try to infer its type based on type annotations
418-
and function signatures in the surrounding program. In the absence of any type
419-
annotations at all, Rust will assume that an unsuffixed integer literal has
420-
type `int`. It's also possible to avoid any type ambiguity by writing integer
421-
literals with a suffix. For example:
418+
In the absense of an integer literal suffix, Rust will infer the
419+
integer type based on type annotations and function signatures in the
420+
surrounding program. In the absence of any type information at all,
421+
Rust will assume that an unsuffixed integer literal has type
422+
`int`.
422423

423424
~~~~
424-
let x = 50;
425-
log(error, x); // x is an int
426-
let y = 100u;
427-
log(error, y); // y is an uint
425+
let a = 1; // a is an int
426+
let b = 10i; // b is an int, due to the 'i' suffix
427+
let c = 100u; // c as a uint
428+
let d = 1000i32; // d is an i32
428429
~~~~
429430

430-
Note that, in Rust, no implicit conversion between integer types
431-
happens. If you are adding one to a variable of type `uint`, saying
432-
`+= 1u8` will give you a type error.
433-
434431
Floating point numbers are written `0.0`, `1e6`, or `2.1e-4`. Without
435-
a suffix, the literal is assumed to be of type `float`. Suffixes `f` (32-bit)
436-
and `l` (64-bit) can be used to create literals of a specific type.
437-
438-
## Other literals
432+
a suffix, the literal is assumed to be of type `float`. Suffixes `f32`
433+
(32-bit) and `f64` (64-bit) can be used to create literals of a
434+
specific type.
439435

440436
The nil literal is written just like the type: `()`. The keywords
441437
`true` and `false` produce the boolean literals.

0 commit comments

Comments
 (0)