Skip to content

Commit 105bfd3

Browse files
committed
Reference: Purge isize from non-memory-related examples
Also explain integer fallback to `i32`.
1 parent 474b324 commit 105bfd3

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

src/doc/reference.md

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ cases mentioned in [Number literals](#number-literals) below.
268268
##### Suffixes
269269
| Integer | Floating-point |
270270
|---------|----------------|
271-
| `is` (`isize`), `us` (`usize`), `u8`, `i8`, `u16`, `i16`, `u32`, `i32`, `u64`, `i64` | `f32`, `f64` |
271+
| `u8`, `i8`, `u16`, `i16`, `u32`, `i32`, `u64`, `i64`, `is` (`isize`), `us` (`usize`) | `f32`, `f64` |
272272

273273
#### Character and string literals
274274

@@ -468,27 +468,29 @@ Like any literal, an integer literal may be followed (immediately,
468468
without any spaces) by an _integer suffix_, which forcibly sets the
469469
type of the literal. There are 10 valid values for an integer suffix:
470470

471-
* The `is` and `us` suffixes give the literal type `isize` or `usize`,
472-
respectively.
473471
* Each of the signed and unsigned machine types `u8`, `i8`,
474472
`u16`, `i16`, `u32`, `i32`, `u64` and `i64`
475473
give the literal the corresponding machine type.
474+
* The `is` and `us` suffixes give the literal type `isize` or `usize`,
475+
respectively.
476476

477477
The type of an _unsuffixed_ integer literal is determined by type inference.
478478
If an integer type can be _uniquely_ determined from the surrounding program
479479
context, the unsuffixed integer literal has that type. If the program context
480-
underconstrains the type, it is considered a static type error; if the program
481-
context overconstrains the type, it is also considered a static type error.
480+
underconstrains the type, it defaults to the signed 32-bit integer `i32`; if
481+
the program context overconstrains the type, it is considered a static type
482+
error.
482483

483484
Examples of integer literals of various forms:
484485

485486
```
486-
123is; // type isize
487-
123us; // type usize
488-
123_us; // type usize
487+
123i32; // type i32
488+
123u32; // type u32
489+
123_u32; // type u32
489490
0xff_u8; // type u8
490491
0o70_i16; // type i16
491492
0b1111_1111_1001_0000_i32; // type i32
493+
0us; // type usize
492494
```
493495

494496
##### Floating-point literals
@@ -1135,8 +1137,8 @@ used as a type name.
11351137

11361138
When a generic function is referenced, its type is instantiated based on the
11371139
context of the reference. For example, calling the `iter` function defined
1138-
above on `[1, 2]` will instantiate type parameter `T` with `isize`, and require
1139-
the closure parameter to have type `fn(isize)`.
1140+
above on `[1, 2]` will instantiate type parameter `T` with `i32`, and require
1141+
the closure parameter to have type `fn(i32)`.
11401142

11411143
The type parameters can also be explicitly supplied in a trailing
11421144
[path](#paths) component after the function name. This might be necessary if
@@ -2746,9 +2748,9 @@ constant expression that can be evaluated at compile time, such as a
27462748
[literal](#literals) or a [static item](#static-items).
27472749

27482750
```
2749-
[1is, 2, 3, 4];
2751+
[1, 2, 3, 4];
27502752
["a", "b", "c", "d"];
2751-
[0is; 128]; // array with 128 zeros
2753+
[0; 128]; // array with 128 zeros
27522754
[0u8, 0u8, 0u8, 0u8];
27532755
```
27542756

@@ -2921,7 +2923,7 @@ moves](#moved-and-copied-types) its right-hand operand to its left-hand
29212923
operand.
29222924

29232925
```
2924-
# let mut x = 0is;
2926+
# let mut x = 0;
29252927
# let y = 0;
29262928
29272929
x = y;
@@ -3307,11 +3309,11 @@ fn main() {
33073309
```
33083310

33093311
Patterns can also dereference pointers by using the `&`, `&mut` and `box`
3310-
symbols, as appropriate. For example, these two matches on `x: &isize` are
3312+
symbols, as appropriate. For example, these two matches on `x: &i32` are
33113313
equivalent:
33123314

33133315
```
3314-
# let x = &3is;
3316+
# let x = &3;
33153317
let y = match *x { 0 => "zero", _ => "some" };
33163318
let z = match x { &0 => "zero", _ => "some" };
33173319
@@ -3332,7 +3334,7 @@ Multiple match patterns may be joined with the `|` operator. A range of values
33323334
may be specified with `...`. For example:
33333335

33343336
```
3335-
# let x = 2is;
3337+
# let x = 2;
33363338
33373339
let message = match x {
33383340
0 | 1 => "not many",
@@ -3673,16 +3675,16 @@ The type of a closure mapping an input of type `A` to an output of type `B` is
36733675
An example of creating and calling a closure:
36743676

36753677
```rust
3676-
let captured_var = 10is;
3678+
let captured_var = 10;
36773679

36783680
let closure_no_args = |&:| println!("captured_var={}", captured_var);
36793681

3680-
let closure_args = |&: arg: isize| -> isize {
3682+
let closure_args = |&: arg: i32| -> i32 {
36813683
println!("captured_var={}, arg={}", captured_var, arg);
36823684
arg // Note lack of semicolon after 'arg'
36833685
};
36843686

3685-
fn call_closure<F: Fn(), G: Fn(isize) -> isize>(c1: F, c2: G) {
3687+
fn call_closure<F: Fn(), G: Fn(i32) -> i32>(c1: F, c2: G) {
36863688
c1();
36873689
c2(2);
36883690
}
@@ -3714,7 +3716,7 @@ trait Printable {
37143716
fn stringify(&self) -> String;
37153717
}
37163718
3717-
impl Printable for isize {
3719+
impl Printable for i32 {
37183720
fn stringify(&self) -> String { self.to_string() }
37193721
}
37203722
@@ -3723,7 +3725,7 @@ fn print(a: Box<Printable>) {
37233725
}
37243726
37253727
fn main() {
3726-
print(Box::new(10is) as Box<Printable>);
3728+
print(Box::new(10) as Box<Printable>);
37273729
}
37283730
```
37293731

0 commit comments

Comments
 (0)