Skip to content

Commit 5f02de3

Browse files
committed
clarify casts are checked at compile time
1 parent 14bc454 commit 5f02de3

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/doc/tarpl/casts.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ using the `as` keyword: `expr as Type`.
99
True casts generally revolve around raw pointers and the primitive numeric
1010
types. Even though they're dangerous, these casts are *infallible* at runtime.
1111
If a cast triggers some subtle corner case no indication will be given that
12-
this occurred. The cast will simply succeed.
12+
this occurred. The cast will simply succeed. That said, casts must be valid
13+
at the type level, or else they will be prevented statically. For instance,
14+
`7u8 as bool` will not compile.
1315

1416
That said, casts aren't `unsafe` because they generally can't violate memory
1517
safety *on their own*. For instance, converting an integer to a raw pointer can

src/doc/tarpl/repr-rust.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ An enum is said to be *C-like* if none of its variants have associated data.
1212
For all these, individual fields are aligned to their preferred alignment. For
1313
primitives this is usually equal to their size. For instance, a u32 will be
1414
aligned to a multiple of 32 bits, and a u16 will be aligned to a multiple of 16
15-
bits. Composite structures will have a preferred alignment equal to the maximum
15+
bits. Note that some primitives may be emulated on different platforms, and as
16+
such may have strange alignment. For instance, a u64 on x86 may actually be
17+
emulated as a pair of u32s, and thus only have 32-bit alignment.
18+
19+
Composite structures will have a preferred alignment equal to the maximum
1620
of their fields' preferred alignment, and a size equal to a multiple of their
1721
preferred alignment. This ensures that arrays of T can be correctly iterated
1822
by offsetting by their size. So for instance,

0 commit comments

Comments
 (0)