You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: reference/src/glossary.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ Moreover, arguments passed to a function must be valid at the type given in the
25
25
OPEN QUESTION: Are there more cases where data must be valid?
26
26
27
27
In terms of code, some data computed by `TERM` is valid at type `T` if and only if the following program does not have UB:
28
-
```rust
28
+
```rust,ignore
29
29
fn main() { unsafe {
30
30
let t: T = std::mem::transmute(TERM);
31
31
} }
@@ -37,7 +37,7 @@ The safety invariant can be temporarily violated by unsafe code, but must always
37
37
It is not relevant when arguing whether some *program* has UB, but it is relevant when arguing whether some code safely encapsulates its unsafety -- IOW, it is relevant when arguing whether some *library* can be used by safe code to *cause* UB.
38
38
39
39
In terms of code, some data computed by `TERM` (possibly constructed from some `arguments` that can be *assumed* to satisfy the safety invariant) is valid at type `T` if and only if the following library function can be safely exposed to arbitrary (safe) code as part of the public library interface:
40
-
```rust
40
+
```rust,ignore
41
41
pub fn make_something(arguments: U) -> T { unsafe {
Copy file name to clipboardExpand all lines: reference/src/layout/integers-floatingpoint.md
+4-3
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,10 @@
1
1
# Layout of Boolean, Floating Point, and Integral Types
2
2
This chapter represents the consensus from issue [#9]. It documents the memory layout and considerations for `bool`, `usize`, `isize`, floating point types, and integral types.
These are all scalar types, representing a single value. These types have no layout variants (no #[repr(C)] or #[repr(Rust)]. Their size is fixed and well-defined across FFI boundaries and map to their corresponding integral types in the C ABI.
7
+
These are all scalar types, representing a single value. These types have no layout variants (no `#[repr(C)]` or `#[repr(Rust)]`). Their size is fixed and well-defined across FFI boundaries and map to their corresponding integral types in the C ABI.
7
8
-`bool`: 1 byte
8
9
- any `bool` can be cast into an integer, taking on the values 1 (true) or 0 (false)
9
10
-`usize`, `isize`: pointer-sized unsigned/signed integer type
@@ -19,11 +20,11 @@ These are all scalar types, representing a single value. These types have no lay
Types `usize` and `isize` are committed to having the same size as a native pointer on the platform. The layout of `usize` determines the following:
24
25
- how much a pointer of a certain type can be offseted,
25
26
- the maximum size of Rust objects (because size_of/size_of_val return `usize`),
26
-
- the maximum number of elements in an array ([T; N: usize]),
27
+
- the maximum number of elements in an array (`[T; N: usize]`),
27
28
-`usize`/`isize` in C FFI are compatible with C's `uintptr_t` / `intptr_t` (and have the same size and alignment).
28
29
29
30
The maximum size of any single value must fit within `usize` to [ensure that pointer diff is representable](https://github.com/rust-rfcs/unsafe-code-guidelines/pull/5#discussion_r212703192).
0 commit comments