diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-08-11 15:18:38 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-11 15:18:38 -0400 |
| commit | 88629778e6faeda18409ffaa9a00291e3605bae3 (patch) | |
| tree | 79be04b2c4142de3325abb0c070ecfb930d0f1a3 /src/libstd/path.rs | |
| parent | 8a068699a24de306334a1f66b9a83552766d853c (diff) | |
| parent | 740f8db85572aef58d0734fc60bc2b54862ebbb0 (diff) | |
| download | rust-88629778e6faeda18409ffaa9a00291e3605bae3.tar.gz rust-88629778e6faeda18409ffaa9a00291e3605bae3.zip | |
Rollup merge of #61969 - MikailBag:master, r=Centril
Add #[repr(transparent)] for several types In some functions, types mentioned in this PR are transmuted into their inner value. Example for `PathBuf`: https://github.com/rust-lang/rust/blob/master/src/libstd/path.rs#L1132. This PR adds `#[repr(transparent)]` to those types, so their correct behavior doesn't depend on compiler details. (As far as I understand, currently that line, converting `PathBuf` to `Vec<u8>`, is UB).
Diffstat (limited to 'src/libstd/path.rs')
| -rw-r--r-- | src/libstd/path.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 87c071b512a..fd6ff1032bb 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1123,6 +1123,12 @@ impl FusedIterator for Ancestors<'_> {} /// Which method works best depends on what kind of situation you're in. #[derive(Clone)] #[stable(feature = "rust1", since = "1.0.0")] +// FIXME: +// `PathBuf::as_mut_vec` current implementation relies +// on `PathBuf` being layout-compatible with `Vec<u8>`. +// When attribute privacy is implemented, `PathBuf` should be annotated as `#[repr(transparent)]`. +// Anyway, `PathBuf` representation and layout are considered implementation detail, are +// not documented and must not be relied upon. pub struct PathBuf { inner: OsString, } @@ -1745,6 +1751,12 @@ impl AsRef<OsStr> for PathBuf { /// assert_eq!(extension, Some(OsStr::new("txt"))); /// ``` #[stable(feature = "rust1", since = "1.0.0")] +// FIXME: +// `Path::new` current implementation relies +// on `Path` being layout-compatible with `OsStr`. +// When attribute privacy is implemented, `Path` should be annotated as `#[repr(transparent)]`. +// Anyway, `Path` representation and layout are considered implementation detail, are +// not documented and must not be relied upon. pub struct Path { inner: OsStr, } |
