Skip to content

Commit 5f54e61

Browse files
committed
Fix usize limitations
Closes #102 .
1 parent b732072 commit 5f54e61

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

reference/src/layout/scalars.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ They have the same layout as the [pointer types] for which the pointee is
4141
> `unsigned` is at least as large as a short, allowed to have padding bits, etc.
4242
> but it is not necessarily pointer-sized.
4343
44-
The layout of `usize` determines the following:
44+
The layout of `usize` determine the following:
4545

46-
- the maximum size of Rust objects (`size_of` and `size_of_val` return `usize`),
46+
- the maximum size of Rust values (`size_of` and `size_of_val` return `usize`),
4747
- the maximum number of elements in an array (`[T; N: usize]`),
48-
- how much a pointer of a certain type can be offseted (limited by `usize::max_value()`).
48+
- how much a pointer of a certain type can be offseted (`ptr.add(count: usize)`).
4949

50-
The maximum size of any single value must fit within `usize` to [ensure that
51-
pointer diff is
52-
representable](https://github.com/rust-rfcs/unsafe-code-guidelines/pull/5#discussion_r212703192).
50+
> **Note**: in the current Rust implementation the maximum size of Rust values
51+
> is limited to `isize::max_value()`. The LLVM `getelementptr` instruction uses
52+
> signed-integer field offsets. Rust calls `getelementptr` with the `inbounds`
53+
> flag which assumes that field offsets do not overflow.
5354
5455
[pointer types]: ./pointers.md
5556

@@ -74,6 +75,7 @@ the corresponding C fixed-width integer types are expected.
7475
The specification of native C integer types, `char`, `short`, `int`, `long`,
7576
... as well as their `unsigned` variants, guarantees a lower bound on their size,
7677
e.g., `short` is _at least_ 16-bit wide and _at least_ as wide as `char`.
78+
7779
Their exact sizes are _implementation-defined_.
7880

7981
Libraries like `libc` use knowledge of this _implementation-defined_ behavior on

0 commit comments

Comments
 (0)