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/libstd/path.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/libstd/path.rs')
| -rw-r--r-- | src/libstd/path.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 4a4db61c3b9..c3a887cbcb8 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -942,7 +942,7 @@ pub struct PathBuf { impl PathBuf { fn as_mut_vec(&mut self) -> &mut Vec<u8> { - unsafe { mem::transmute(self) } + unsafe { &mut *(self as *mut PathBuf as *mut Vec<u8>) } } /// Allocates an empty `PathBuf`. @@ -1126,7 +1126,7 @@ impl ops::Deref for PathBuf { type Target = Path; fn deref(&self) -> &Path { - unsafe { mem::transmute(&self.inner[..]) } + Path::new(&self.inner) } } @@ -1227,11 +1227,11 @@ impl Path { // The following (private!) function allows construction of a path from a u8 // slice, which is only safe when it is known to follow the OsStr encoding. unsafe fn from_u8_slice(s: &[u8]) -> &Path { - mem::transmute(s) + Path::new(u8_slice_as_os_str(s)) } // The following (private!) function reveals the byte encoding used for OsStr. fn as_u8_slice(&self) -> &[u8] { - unsafe { mem::transmute(self) } + os_str_as_u8_slice(&self.inner) } /// Directly wrap a string slice as a `Path` slice. |
