diff options
| author | Tobias Bucher <tobiasbucher5991@gmail.com> | 2015-07-24 03:04:55 +0200 |
|---|---|---|
| committer | Tobias Bucher <tobiasbucher5991@gmail.com> | 2015-08-09 22:05:22 +0200 |
| commit | 22ec5f4af7b5a85ad375d672ed727571b49f3cad (patch) | |
| tree | eea29f1286398aaaa9d55f23163ddcc49b033eeb /src/libcore/cmp.rs | |
| parent | febdc3b201bcce1546c88e3be1b956d3f90d3059 (diff) | |
| download | rust-22ec5f4af7b5a85ad375d672ed727571b49f3cad.tar.gz rust-22ec5f4af7b5a85ad375d672ed727571b49f3cad.zip | |
Replace many uses of `mem::transmute` with more specific functions
The replacements are functions that usually use a single `mem::transmute` in their body and restrict input and output via more concrete types than `T` and `U`. Worth noting are the `transmute` functions for slices and the `from_utf8*` family for mutable slices. Additionally, `mem::transmute` was often used for casting raw pointers, when you can already cast raw pointers just fine with `as`.
Diffstat (limited to 'src/libcore/cmp.rs')
| -rw-r--r-- | src/libcore/cmp.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 9d151abea78..da4bb41fd9c 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -19,6 +19,7 @@ use self::Ordering::*; +use mem; use marker::Sized; use option::Option::{self, Some, None}; @@ -114,6 +115,10 @@ pub enum Ordering { } impl Ordering { + unsafe fn from_i8_unchecked(v: i8) -> Ordering { + mem::transmute(v) + } + /// Reverse the `Ordering`. /// /// * `Less` becomes `Greater`. @@ -155,7 +160,7 @@ impl Ordering { // // NB. it is safe because of the explicit discriminants // given above. - ::mem::transmute::<_, Ordering>(-(self as i8)) + Ordering::from_i8_unchecked(-(self as i8)) } } } |
