Skip to content

Commit 38cdc45

Browse files
committed
clarify ABI compatibility of fn ptr types
and add an and
1 parent 044d057 commit 38cdc45

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

library/core/src/primitive_docs.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1537,18 +1537,18 @@ mod prim_ref {}
15371537
///
15381538
/// The following types are guaranteed to be ABI-compatible:
15391539
///
1540-
/// - `*const T`, `*mut T`, `&T`, `&mut T`, `Box<T>` (specifically, only `Box<T, Global>`),
1540+
/// - `*const T`, `*mut T`, `&T`, `&mut T`, `Box<T>` (specifically, only `Box<T, Global>`), and
15411541
/// `NonNull<T>` are all ABI-compatible with each other for all `T`. Two of these pointer types
15421542
/// with different `T` are ABI-compatible if they have the same metadata type (`<T as
15431543
/// Pointee>::Metadata`).
15441544
/// - `usize` is ABI-compatible with the `uN` integer type of the same size, and likewise `isize` is
15451545
/// ABI-compatible with the `iN` integer type of the same size.
1546-
/// - Any two `fn` types are ABI-compatible with each other if they have the same ABI string or the
1547-
/// ABI string only differs in a trailing `-unwind`, independent of the rest of their signature.
1548-
/// (Note that this is about the case of passing a function pointer as an argument to a function.
1549-
/// The two pointers being ABI-compatible here means that the call successfully passes the
1550-
/// pointer. When actually calling the pointer, of course the rest of the signature becomes
1551-
/// relevant as well, according to the rules in this section.)
1546+
/// - Any two `fn` (function pointer) types are ABI-compatible with each other if they have the same
1547+
/// ABI string or the ABI string only differs in a trailing `-unwind`, independent of the rest of
1548+
/// their signature. (This means you can pass `fn()` to a function expecting `fn(i32)`, and the
1549+
/// call will be valid ABI-wise. The callee receives the result of transmuting the function pointer
1550+
/// from `fn()` to `fn(i32)`; that transmutation is itself a well-defined operation, it's just
1551+
/// almost certainly UB to later call that function pointer.)
15521552
/// - Any two types with size 0 and alignment 1 are ABI-compatible.
15531553
/// - A `repr(transparent)` type `T` is ABI-compatible with its unique non-trivial field, i.e., the
15541554
/// unique field that doesn't have size 0 and alignment 1 (if there is such a field).

0 commit comments

Comments
 (0)