about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Scherer <github35764891676564198441@oli-obk.de>2019-12-28 00:36:14 +0100
committerGitHub <noreply@github.com>2019-12-28 00:36:14 +0100
commit9525e8e6b2aa03d6c10cc31a30074de4b4adfe5a (patch)
tree9f304cb92706a4f4307b29b6b6afc238ae93000c
parent47d5acf54dd5fbbb61bf6c130839726cea649939 (diff)
parent9c0f3f7f2ae2492542fea99338fac13242cfe25e (diff)
downloadrust-9525e8e6b2aa03d6c10cc31a30074de4b4adfe5a.tar.gz
rust-9525e8e6b2aa03d6c10cc31a30074de4b4adfe5a.zip
Rollup merge of #67635 - Mark-Simulacrum:path-doc-unsafe, r=dtolnay
Document safety of Path casting

I would personally feel more comfortable making the relevant (internal anyway) types repr(transparent) and then documenting that we can make these casts because of that, but I believe this is a more minimal PR, so posting it first.

Resolves #45910.
-rw-r--r--src/libstd/path.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/libstd/path.rs b/src/libstd/path.rs
index 27bbc179988..f308d511cf8 100644
--- a/src/libstd/path.rs
+++ b/src/libstd/path.rs
@@ -296,6 +296,13 @@ where
 }
 
 // See note at the top of this module to understand why these are used:
+//
+// These casts are safe as OsStr is internally a wrapper around [u8] on all
+// platforms.
+//
+// Note that currently this relies on the special knowledge that libstd has;
+// these types are single-element structs but are not marked repr(transparent)
+// or repr(C) which would make these casts allowable outside std.
 fn os_str_as_u8_slice(s: &OsStr) -> &[u8] {
     unsafe { &*(s as *const OsStr as *const [u8]) }
 }