Skip to content

Commit 11dbcb9

Browse files
committed
---
yaml --- r: 32763 b: refs/heads/dist-snap c: 3b89dcb h: refs/heads/master i: 32761: f392917 32759: bd2df74 v: v3
1 parent de6a5ee commit 11dbcb9

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
@@ -7,6 +7,6 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
10-
refs/heads/dist-snap: 4081b40523c7059a742dc11193fea7356495c614
10+
refs/heads/dist-snap: 3b89dcbdf2de3f757556639cd7323c60d343c4d2
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/dist-snap/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)