diff options
| author | bors <bors@rust-lang.org> | 2020-03-27 00:25:26 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-03-27 00:25:26 +0000 |
| commit | 7b73d14b0b35e7b4f79f2d71dc1bbbab31698288 (patch) | |
| tree | 274c58c487448e0f043ca91acd85c82d1a1164b2 /src/libstd/sys_common | |
| parent | 62c6006450d8bd33a351673c1f969846d768aab4 (diff) | |
| parent | fa15774a4b3466ac71a0f84871c0106591484fd4 (diff) | |
| download | rust-7b73d14b0b35e7b4f79f2d71dc1bbbab31698288.tar.gz rust-7b73d14b0b35e7b4f79f2d71dc1bbbab31698288.zip | |
Auto merge of #70451 - Dylan-DPC:rollup-2g9oyht, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #69644 (Remove framework in `dataflow/mod.rs` in favor of "generic" one) - #69936 (Fix cycle error when emitting suggestion for mismatched `fn` type) - #70048 (Allow obtaining &mut OsStr) - #70344 (Decouple `rustc_hir::print` into `rustc_hir_pretty`) - #70435 (Add regression test for #66706) Failed merges: r? @ghost
Diffstat (limited to 'src/libstd/sys_common')
| -rw-r--r-- | src/libstd/sys_common/os_str_bytes.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/libstd/sys_common/os_str_bytes.rs b/src/libstd/sys_common/os_str_bytes.rs index e965ea79aa0..c5d02fb1772 100644 --- a/src/libstd/sys_common/os_str_bytes.rs +++ b/src/libstd/sys_common/os_str_bytes.rs @@ -106,9 +106,20 @@ impl Buf { #[inline] pub fn as_slice(&self) -> &Slice { + // Safety: Slice just wraps [u8], + // and &*self.inner is &[u8], therefore + // transmuting &[u8] to &Slice is safe. unsafe { mem::transmute(&*self.inner) } } + #[inline] + pub fn as_mut_slice(&mut self) -> &mut Slice { + // Safety: Slice just wraps [u8], + // and &mut *self.inner is &mut [u8], therefore + // transmuting &mut [u8] to &mut Slice is safe. + unsafe { mem::transmute(&mut *self.inner) } + } + pub fn into_string(self) -> Result<String, Buf> { String::from_utf8(self.inner).map_err(|p| Buf { inner: p.into_bytes() }) } |
