Skip to content

Commit baf6f8e

Browse files
committed
Clean up some of the casts section
1 parent 5ea3d30 commit baf6f8e

File tree

1 file changed

+13
-40
lines changed

1 file changed

+13
-40
lines changed

src/expressions.md

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -928,8 +928,8 @@ fn average(values: &[f64]) -> f64 {
928928
```
929929

930930
`as` can be used to explicitly perform [coercions](type-coercions.html), as
931-
well as the following additional casts. We write `*T` as short for either
932-
`*const T` or `*mut T`
931+
well as the following additional casts. `*T` is short for either
932+
`*const T` or `*mut T`.
933933

934934
| Type of `e` | `U` | Cast performed by `e as U` |
935935
|-----------------------|-----------------------|----------------------------------|
@@ -946,7 +946,7 @@ well as the following additional casts. We write `*T` as short for either
946946

947947
\* or `T` and `V` are compatible unsized types, e.g., both slices.
948948

949-
* `e` has type `T` and `T` and `U` are any numeric types; *numeric-cast*
949+
* Numeric cast
950950
* Casting between two integers of the same size (e.g. i32 -> u32) is a no-op
951951
* Casting from a larger integer to a smaller integer (e.g. u32 -> u8) will
952952
truncate
@@ -967,43 +967,16 @@ well as the following additional casts. We write `*T` as short for either
967967
is finite but larger or smaller than the largest or smallest finite
968968
value representable by f32][float-float]**. This is a bug and will
969969
be fixed.
970-
* `e` is a C-like enum (with no data attached to the variants), and `U` is an
971-
integer type; *enum-cast*
972-
* What are the guarantees here? Equivalent to C?
973-
* `e` has type `bool` or `char` and `U` is an integer type; *prim-int-cast*
974-
* `false` casts to `0`, `true` casts to `1`?
975-
* `char` casts to the value of the code point, truncating if required?
976-
* `e` has type `u8` and `U` is `char`; *u8-char-cast*
977-
* Interprets the `u8` as a code point?
978-
* `e` has type `*T`, `U` has type `*U_0`, and either `U_0: Sized` or
979-
`unsize_kind(T) == unsize_kind(U_0)`; a *ptr-ptr-cast*
980-
* Points at same location?
981-
* Alignment??
982-
* Fat pointers have the same "additional information"?
983-
* Is unsize_kind described anywhere?
984-
* Round trips?
985-
* `e` has type `*T` and `U` is a numeric type, while `T: Sized`;
986-
*ptr-addr-cast*
987-
* What do we guarantee here?
988-
* Equivalent to `mem::transmute` to `usize`, followed by truncation/extension?
989-
* Extend as though the pointer is unsigned?
990-
* Doing pointer arithmetic this way?
991-
* `e` is an integer and `U` is `*U_0`, while `U_0: Sized`; *addr-ptr-cast*
992-
* Alignment??
993-
* Round trips with pointer address casts (either way), with pointer arithmetic?
994-
* Probably out of scope, but is 'getting (un)lucky' with addresses defined?
995-
* Use in embedded?
996-
* Equivalent to cast to `usize` followed by `mem::transmute`?
997-
* Does casting 0 in this way guaranteed to be a null pointer?
998-
* `e` has type `&[T; n]` and `U` is `*const T`; *array-ptr-cast*
999-
* Equivalent to taking reference to first element and casting (if n > 0)?
1000-
* `e` is a function pointer type and `U` has type `*T`, while `T: Sized`;
1001-
*fptr-ptr-cast*
1002-
* Same concerns as with pointer to pointer casts
1003-
* `e` is a function pointer type and `U` is an integer; *fptr-addr-cast*
1004-
* Same concerns as with pointer to address casts
1005-
1006-
TODO: Explain the semantics of these.
970+
* Enum cast
971+
* Casts an enum to its discriminant, then uses a numeric cast if needed.
972+
* Primitive to integer cast
973+
* `false` casts to `0`, `true` casts to `1`
974+
* `char` casts to the value of the code point, then uses a numeric cast if needed.
975+
* `u8` to `char` cast
976+
* Casts to the `char` with the corresponding code point.
977+
978+
[float-int]: https://github.com/rust-lang/rust/issues/10184
979+
[float-float]: https://github.com/rust-lang/rust/issues/15536
1007980

1008981
### Assignment expressions
1009982

0 commit comments

Comments
 (0)