Skip to content

Commit

Permalink
Document safety of Path casting
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Dec 26, 2019
1 parent 3ac40b6 commit 9c0f3f7
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/libstd/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]) }
}
Expand Down

0 comments on commit 9c0f3f7

Please sign in to comment.