Skip to content

Commit ba8fa67

Browse files
authored
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.
2 parents 3557bed + 9c0f3f7 commit ba8fa67

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/libstd/path.rs

+7
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,13 @@ where
296296
}
297297

298298
// See note at the top of this module to understand why these are used:
299+
//
300+
// These casts are safe as OsStr is internally a wrapper around [u8] on all
301+
// platforms.
302+
//
303+
// Note that currently this relies on the special knowledge that libstd has;
304+
// these types are single-element structs but are not marked repr(transparent)
305+
// or repr(C) which would make these casts allowable outside std.
299306
fn os_str_as_u8_slice(s: &OsStr) -> &[u8] {
300307
unsafe { &*(s as *const OsStr as *const [u8]) }
301308
}

0 commit comments

Comments
 (0)