1
Fork 0

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.
This commit is contained in:
Oliver Scherer 2019-12-28 00:36:14 +01:00 committed by GitHub
commit 9525e8e6b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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]) }
}