Skip to content

Commit 3b1353f

Browse files
committed
Document current behavior and don't guarantee 16-bit wide isize/usize
1 parent 8128316 commit 3b1353f

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

reference/src/layout/scalars.md

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,14 @@ of `char` is _implementation-defined_.
3535

3636
The `isize` and `usize` types are pointer-sized signed and unsigned integers.
3737
They have the same layout as the [pointer types] for which the pointee is
38-
`Sized`, and are layout compatible with C's `uintptr_t` and `intptr_t` types,
39-
and are therefore at least 16-bit wide.
38+
`Sized`, and are layout compatible with C's `uintptr_t` and `intptr_t` types.
39+
40+
> **Note**: on all platforms that we currently support, `usize`/`isize` are at
41+
> least 16-bit wide. C99
42+
> [7.18.2.4](https://port70.net/~nsz/c/c99/n1256.html#7.18.2.4) requires
43+
> `uintptr_t` and `intptr_t` to be at least 16-bit wide. `libcore` relies on
44+
> this to unconditionally provide impls of `From<i16>`/`From<u16>` for
45+
> `isize`/`usize`.
4046
4147
> **Note**: Rust's `usize` and C's `unsigned` types are **not** equivalent. C's
4248
> `unsigned` is at least as large as a short, allowed to have padding bits, etc.
@@ -60,23 +66,6 @@ and are therefore at least 16-bit wide.
6066
> These limits have not gone through the RFC process and are not guaranteed to
6167
> hold.
6268
63-
<details><summary><b>Rationale</b></summary>
64-
65-
C99 [7.18.2.4](https://port70.net/~nsz/c/c99/n1256.html#7.18.2.4) "Limits of
66-
integer types capable of holding object pointers" provides the following minimum
67-
range of values that the pointer-holding integer types must support:
68-
69-
* `intptr_t`: `[INTPTR_MIN, INTPTR_MAX] = [-(2^15 - 1), 2^15 - 1]`
70-
* `uintptr_t`: `[0, UINTPTR_MAX] = [0, 2^16 - 1]`
71-
72-
That is, `isize`/`usize` are at least 16-bit wide. `libcore` relies on
73-
this guarantee and unconditionally provides:
74-
75-
* `impl From<i16> for isize`,
76-
* `impl From<u16> for usize`.
77-
78-
</details>
79-
8069
[pointer types]: ./pointers.md
8170

8271
## Fixed-width integer types

0 commit comments

Comments
 (0)