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/windows | |
| 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/windows')
| -rw-r--r-- | src/libstd/sys/windows/os_str.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/libstd/sys/windows/os_str.rs b/src/libstd/sys/windows/os_str.rs index ef260f9c5d2..ff6885cb274 100644 --- a/src/libstd/sys/windows/os_str.rs +++ b/src/libstd/sys/windows/os_str.rs @@ -77,9 +77,21 @@ impl Buf { } pub fn as_slice(&self) -> &Slice { + // Safety: Slice is just a wrapper for Wtf8, + // and self.inner.as_slice() returns &Wtf8. + // Therefore, transmuting &Wtf8 to &Slice is safe. unsafe { mem::transmute(self.inner.as_slice()) } } + pub fn as_mut_slice(&mut self) -> &mut Slice { + // Safety: Slice is just a wrapper for Wtf8, + // and self.inner.as_mut_slice() returns &mut Wtf8. + // Therefore, transmuting &mut Wtf8 to &mut Slice is safe. + // Additionally, care should be taken to ensure the slice + // is always valid Wtf8. + unsafe { mem::transmute(self.inner.as_mut_slice()) } + } + pub fn into_string(self) -> Result<String, Buf> { self.inner.into_string().map_err(|buf| Buf { inner: buf }) } |
