From 10fed3ab03d9cc9c2829ada76a9369f77af8986b Mon Sep 17 00:00:00 2001 From: Nicolas Date: Sat, 8 Jan 2022 18:31:32 -0300 Subject: [PATCH 1/3] Clarify repr(transparent) in other-reprs --- src/other-reprs.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/other-reprs.md b/src/other-reprs.md index fe06faf6..0feb3c5b 100644 --- a/src/other-reprs.md +++ b/src/other-reprs.md @@ -62,12 +62,17 @@ whole struct is guaranteed to be the same as that one field. The goal is to make it possible to transmute between the single field and the struct. An example of that is [`UnsafeCell`], which can be transmuted into -the type it wraps. +the type it wraps ([`UnsafeCell`] also uses the unstable [no_niche][no-niche-pull], +so it's ABI is not actually guaranteed to be the same when nested in other types). Also, passing the struct through FFI where the inner field type is expected on the other side is guaranteed to work. In particular, this is necessary for `struct Foo(f32)` to always have the same ABI as `f32`. +This repr is only considered part of the public ABI of a type if either the single +field is pub, or if it's layout is documented in prose. Otherwise, the layout should +not be relied upon by other crates. + More details are in the [RFC][rfc-transparent]. ## repr(u*), repr(i*) @@ -153,3 +158,4 @@ This is a modifier on `repr(C)` and `repr(Rust)`. It is incompatible with [really-tagged]: https://github.com/rust-lang/rfcs/blob/master/text/2195-really-tagged-unions.md [rust-bindgen]: https://rust-lang.github.io/rust-bindgen/ [cbindgen]: https://github.com/eqrion/cbindgen +[no-niche-pull]: https://github.com/rust-lang/rust/pull/68491 From cd999a7ea9ea7bb5bb6d46bd1ca7619e9fc308ab Mon Sep 17 00:00:00 2001 From: Nicolas Abram Date: Thu, 20 Jan 2022 15:06:18 -0300 Subject: [PATCH 2/3] Update src/other-reprs.md Co-authored-by: Yuki Okushi --- src/other-reprs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/other-reprs.md b/src/other-reprs.md index 0feb3c5b..ea8fc718 100644 --- a/src/other-reprs.md +++ b/src/other-reprs.md @@ -70,7 +70,7 @@ the other side is guaranteed to work. In particular, this is necessary for `stru Foo(f32)` to always have the same ABI as `f32`. This repr is only considered part of the public ABI of a type if either the single -field is pub, or if it's layout is documented in prose. Otherwise, the layout should +field is `pub`, or if its layout is documented in prose. Otherwise, the layout should not be relied upon by other crates. More details are in the [RFC][rfc-transparent]. From da24b086ec31246e8600db6c4398422e9dba3c0b Mon Sep 17 00:00:00 2001 From: Nicolas Abram Date: Thu, 20 Jan 2022 15:06:42 -0300 Subject: [PATCH 3/3] Update src/other-reprs.md Co-authored-by: Yuki Okushi --- src/other-reprs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/other-reprs.md b/src/other-reprs.md index ea8fc718..93da7297 100644 --- a/src/other-reprs.md +++ b/src/other-reprs.md @@ -63,7 +63,7 @@ whole struct is guaranteed to be the same as that one field. The goal is to make it possible to transmute between the single field and the struct. An example of that is [`UnsafeCell`], which can be transmuted into the type it wraps ([`UnsafeCell`] also uses the unstable [no_niche][no-niche-pull], -so it's ABI is not actually guaranteed to be the same when nested in other types). +so its ABI is not actually guaranteed to be the same when nested in other types). Also, passing the struct through FFI where the inner field type is expected on the other side is guaranteed to work. In particular, this is necessary for `struct