Skip to content

Commit f9bcda9

Browse files
committed
wording improvements
1 parent 037afca commit f9bcda9

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

library/core/src/option.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
//! # Representation
120120
//!
121121
//! Rust guarantees to optimize the following types `T` such that
122-
//! [`Option<T>`] has the same size and alignment as `T`:
122+
//! [`Option<T>`] has the same size, alignment, and [function call ABI] as `T`:
123123
//!
124124
//! * [`Box<U>`]
125125
//! * `&U`
@@ -129,11 +129,12 @@
129129
//! * [`ptr::NonNull<U>`]
130130
//! * `#[repr(transparent)]` struct around one of the types in this list.
131131
//!
132-
//! [^extern_fn]: this remains true for any other ABI: `extern "abi" fn` (_e.g._, `extern "system" fn`)
132+
//! [^extern_fn]: this remains true for any argument/return types and any other ABI: `extern "abi" fn` (_e.g._, `extern "system" fn`)
133133
//!
134134
//! [`Box<U>`]: ../../std/boxed/struct.Box.html
135135
//! [`num::NonZero*`]: crate::num
136136
//! [`ptr::NonNull<U>`]: crate::ptr::NonNull
137+
//! [function call ABI]: ../primitive.fn.html#abi-compatibility
137138
//!
138139
//! This is called the "null pointer optimization" or NPO.
139140
//!

library/core/src/primitive_docs.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -1544,28 +1544,35 @@ mod prim_ref {}
15441544
///
15451545
/// The following types are guaranteed to be ABI-compatible:
15461546
///
1547-
/// - Every type is ABI-compatible with itself.
15481547
/// - `*const T`, `*mut T`, `&T`, `&mut T`, `Box<T>`, `NonNull<T>` are all ABI-compatible with each
15491548
/// other for all `T`.
1550-
/// - Any two `fn()` types with the same `extern` ABI string are ABI-compatible with each other.
1551-
/// - Any two 1-ZST types (types with size 0 and alignment 1) are ABI-compatible.
1552-
/// - A `repr(transparent)` type `T` is ABI-compatible with its unique non-1-ZST field (if there is
1553-
/// such a field).
1549+
/// - Any two `fn`/`extern "ABI" fn` types with the same call ABI are ABI-compatible with each
1550+
/// other, independent of the rest of their signature.
1551+
/// - Any two types with size 0 and alignment 1 are ABI-compatible.
1552+
/// - A `repr(transparent)` type `T` is ABI-compatible with its unique non-trivial field, i.e., the
1553+
/// unique field that doesn't have size 0 and alignment 1 (if there is such a field).
15541554
/// - `i32` is ABI-compatible with `NonZeroI32`, and similar for all other integer types with their
15551555
/// matching `NonZero*` type.
15561556
/// - If `T` is guaranteed to be subject to the [null pointer
15571557
/// optimization](option/index.html#representation), then `T` and `Option<T>` are ABI-compatible.
1558+
///
1559+
/// Furthermore, ABI compatibility satisfies the following general properties:
1560+
///
1561+
/// - Every type is ABI-compatible with itself.
15581562
/// - If `T1` and `T2` are ABI-compatible, then two `repr(C)` types that only differ because one
15591563
/// field type was changed from `T1` to `T2` are ABI-compatible.
1560-
/// - ABI-compatibility is symmetric and transitive.
1564+
/// - If `T1` and `T2` are ABI-compatible and `T2` and `T3` are ABI-compatible, then so are `T1` and
1565+
/// `T3` (i.e., ABI-compatibility is transitive).
1566+
/// - If `T1` and `T2` are ABI-compatible, then so are `T2` and `T1` (i.e., ABI-compatibility is
1567+
/// symmetric).
15611568
///
15621569
/// More signatures can be ABI-compatible on specific targets, but that should not be relied upon
15631570
/// since it is not portable and not a stable guarantee.
15641571
///
15651572
/// Noteworthy cases of types *not* being ABI-compatible in general are `bool` vs `u8`, and `i32` vs
15661573
/// `u32`: on some targets, the calling conventions for these types differ in terms of what they
15671574
/// guarantee for the remaining bits in the register that are not used by the value. `i32` vs `f32`
1568-
/// has already been mentioned above.
1575+
/// are not compatible either, as has already been mentioned above.
15691576
///
15701577
/// Note that these rules describe when two completely known types are ABI-compatible. When
15711578
/// considering ABI compatibility of a type declared in another crate (including the standard

library/std/src/primitive_docs.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -1544,28 +1544,35 @@ mod prim_ref {}
15441544
///
15451545
/// The following types are guaranteed to be ABI-compatible:
15461546
///
1547-
/// - Every type is ABI-compatible with itself.
15481547
/// - `*const T`, `*mut T`, `&T`, `&mut T`, `Box<T>`, `NonNull<T>` are all ABI-compatible with each
15491548
/// other for all `T`.
1550-
/// - Any two `fn()` types with the same `extern` ABI string are ABI-compatible with each other.
1551-
/// - Any two 1-ZST types (types with size 0 and alignment 1) are ABI-compatible.
1552-
/// - A `repr(transparent)` type `T` is ABI-compatible with its unique non-1-ZST field (if there is
1553-
/// such a field).
1549+
/// - Any two `fn`/`extern "ABI" fn` types with the same call ABI are ABI-compatible with each
1550+
/// other, independent of the rest of their signature.
1551+
/// - Any two types with size 0 and alignment 1 are ABI-compatible.
1552+
/// - A `repr(transparent)` type `T` is ABI-compatible with its unique non-trivial field, i.e., the
1553+
/// unique field that doesn't have size 0 and alignment 1 (if there is such a field).
15541554
/// - `i32` is ABI-compatible with `NonZeroI32`, and similar for all other integer types with their
15551555
/// matching `NonZero*` type.
15561556
/// - If `T` is guaranteed to be subject to the [null pointer
15571557
/// optimization](option/index.html#representation), then `T` and `Option<T>` are ABI-compatible.
1558+
///
1559+
/// Furthermore, ABI compatibility satisfies the following general properties:
1560+
///
1561+
/// - Every type is ABI-compatible with itself.
15581562
/// - If `T1` and `T2` are ABI-compatible, then two `repr(C)` types that only differ because one
15591563
/// field type was changed from `T1` to `T2` are ABI-compatible.
1560-
/// - ABI-compatibility is symmetric and transitive.
1564+
/// - If `T1` and `T2` are ABI-compatible and `T2` and `T3` are ABI-compatible, then so are `T1` and
1565+
/// `T3` (i.e., ABI-compatibility is transitive).
1566+
/// - If `T1` and `T2` are ABI-compatible, then so are `T2` and `T1` (i.e., ABI-compatibility is
1567+
/// symmetric).
15611568
///
15621569
/// More signatures can be ABI-compatible on specific targets, but that should not be relied upon
15631570
/// since it is not portable and not a stable guarantee.
15641571
///
15651572
/// Noteworthy cases of types *not* being ABI-compatible in general are `bool` vs `u8`, and `i32` vs
15661573
/// `u32`: on some targets, the calling conventions for these types differ in terms of what they
15671574
/// guarantee for the remaining bits in the register that are not used by the value. `i32` vs `f32`
1568-
/// has already been mentioned above.
1575+
/// are not compatible either, as has already been mentioned above.
15691576
///
15701577
/// Note that these rules describe when two completely known types are ABI-compatible. When
15711578
/// considering ABI compatibility of a type declared in another crate (including the standard

0 commit comments

Comments
 (0)