Skip to content

Commit 6a94029

Browse files
committed
---
yaml --- r: 236015 b: refs/heads/stable c: 3318e3d h: refs/heads/master i: 236013: a08e8c1 236011: d46f065 236007: 5697123 235999: 6e8cc28 v: v3
1 parent 0ba35fa commit 6a94029

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/heads/tmp: afae2ff723393b3ab4ccffef6ac7c6d1809e2da0
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: f859507de8c410b648d934d8f5ec1c52daac971d
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 39c047317f39df2b0f55da10f276b88826f54d3b
32+
refs/heads/stable: 3318e3d8edd4336021f4314a25618e77061f2684
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e

branches/stable/conversions.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,27 @@ actually think about it is probably the general *Deref Coercion*: `&T` coerces t
5454

5555
Casts are a superset of coercions: every coercion can be explicitly invoked via a cast,
5656
but some changes require a cast. These "true casts" are generally regarded as dangerous or
57-
problematic actions. The set of true casts is actually quite small, and once again revolves
58-
largely around pointers. However it also introduces the primary mechanism to convert between
59-
numeric types.
57+
problematic actions. True casts revolves around raw pointers and the primitive numeric
58+
types. Here's an exhaustive list of all the true casts:
6059

6160
* rawptr -> rawptr (e.g. `*mut T as *const T` or `*mut T as *mut U`)
6261
* rawptr <-> usize (e.g. `*mut T as usize` or `usize as *mut T`)
63-
* primitive -> primitive (e.g. `u32 as u8` or `u8 as u32`)
64-
* c-like enum -> integer/bool (e.g. `DaysOfWeek as u8`)
62+
* number -> number (e.g. `u32 as i8` or `i16 as f64`)
63+
* c-like enum -> integer/bool (e.g. `DaysOfWeek as u32`)
6564
* `u8` -> `char`
65+
* something about arrays?
66+
67+
For number -> number casts, there are quite a few cases to consider:
68+
69+
* unsigned to bigger unsigned will zero-extend losslessly
70+
* unsigned to smaller unsigned will truncate via wrapping
71+
* signed to unsigned will ... TODO rest of this list
72+
73+
The casts involving rawptrs also allow us to completely bypass type-safety
74+
by re-interpretting a pointer of T to a pointer of U for arbitrary types, as
75+
well as interpret integers as addresses. However it is impossible to actually
76+
*capitalize* on this violation in Safe Rust, because derefencing a raw ptr is
77+
`unsafe`.
6678

6779

6880
## Conversion Traits

0 commit comments

Comments
 (0)