@@ -41,15 +41,25 @@ They have the same layout as the [pointer types] for which the pointee is
41
41
> ` unsigned ` is at least as large as a short, allowed to have padding bits, etc.
42
42
> but it is not necessarily pointer-sized.
43
43
44
- The layout of ` usize ` determines the following:
45
-
46
- - the maximum size of Rust objects (` size_of ` and ` size_of_val ` return ` usize ` ),
47
- - 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() ` ).
49
-
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 ) .
44
+ The layout of ` usize ` determine the following:
45
+
46
+ - the maximum size of Rust values is _ implementation-defined_ , but can at most
47
+ be ` usize::max_value ` since ` mem::size_of ` and ` mem::size_of_val ` return
48
+ ` usize ` ,
49
+ - the maximum number of elements in an array is _ implementation-defined_ , but
50
+ can at most be ` usize::max_value() ` since ` [T; N: usize] ` ,
51
+ - the maximum value by which a pointer can be offseted is
52
+ _ implementation-defined_ , but can at most be ` usize::max_value() ` since
53
+ ` ptr.add(count: usize) ` .
54
+
55
+ > ** Note** : in the current Rust implementation:
56
+ >
57
+ > * the maximum size of Rust values is limited to ` isize::max_value() ` . The LLVM
58
+ > ` getelementptr ` instruction uses signed-integer field offsets. Rust calls
59
+ > ` getelementptr ` with the ` inbounds ` flag which assumes that field offsets do
60
+ > not overflow,
61
+ > * the maximum number of elements in an array is ` usize::max_value() ` ,
62
+ > * the maximum value by which a pointer can be offseted is ` usize::max_value() ` .
53
63
54
64
[ pointer types ] : ./pointers.md
55
65
@@ -74,6 +84,7 @@ the corresponding C fixed-width integer types are expected.
74
84
The specification of native C integer types, ` char ` , ` short ` , ` int ` , ` long ` ,
75
85
... as well as their ` unsigned ` variants, guarantees a lower bound on their size,
76
86
e.g., ` short ` is _ at least_ 16-bit wide and _ at least_ as wide as ` char ` .
87
+
77
88
Their exact sizes are _ implementation-defined_ .
78
89
79
90
Libraries like ` libc ` use knowledge of this _ implementation-defined_ behavior on
0 commit comments