Skip to content

Commit 51fc74a

Browse files
chorman0773ehuss
andcommitted
Apply suggestions from code review
Co-authored-by: Eric Huss <[email protected]>
1 parent 0c95719 commit 51fc74a

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/abi.md

+21-21
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
r[abi]
44

5-
## ABI Compatibility
5+
## ABI compatibility
66

77
r[abi.compatibility]
88

9-
r[abi.compatibilty.type]
9+
r[abi.compatibility.type]
1010
Two types, `T` and `U`, can be *abi compatible*.
1111

1212
r[abi.compatibility.equivalence]
@@ -19,27 +19,27 @@ Two types `T` and `U` are *abi compatible* if:
1919
> These properties are respectively called "reflexivity", "symmetry", and "transitivity". They ensure that *abi compatibility* is an equivalence relation.
2020
2121
r[abi.compatibility.integer]
22-
Two [integer types] are *abi compatible* if they have the same size and the same signedness
22+
Two [integer types] are *abi compatible* if they have the same size and the same signedness.
2323

2424
> [!NOTE]
2525
> In particular, `usize` is *abi compatible* with `uN`, and `isize` is *abi compatible* with `iN` where `N` is the target_pointer_width.
2626
> Two integer types with different signedness, such as `u8` and `i8` are not *abi compatible*.
2727
2828
```rust
29-
#[cfg(target_pointer_width="32")]
30-
fn foo(x: u32) -> u32{
29+
#[cfg(target_pointer_width = "32")]
30+
fn foo(x: u32) -> u32 {
3131
x
3232
}
33-
#[cfg(target_pointer_width="64")]
34-
fn foo(x: u64) -> u64{
33+
#[cfg(target_pointer_width = "64")]
34+
fn foo(x: u64) -> u64 {
3535
x
3636
}
3737

38-
fn main(){
39-
let f: fn(usize)->usize = unsafe{core::mem::transmute(foo as fn(_)->_)};
38+
fn main() {
39+
let f: fn(usize) -> usize = unsafe { core::mem::transmute(foo as fn(_) -> _) };
4040
let x = 0usize;
4141
let y = f(x);
42-
assert_eq!(x,y);
42+
assert_eq!(x, y);
4343
}
4444
```
4545

@@ -53,7 +53,7 @@ fn foo(x: char) -> u32{
5353

5454
fn main(){
5555
let f: fn(u32)->char = unsafe{core::mem::transmute(foo as fn(_)->_)};
56-
let x = b'A' as u32; // ascii character indecies are the same as Unicode character indecies
56+
let x = b'A' as u32; // ascii character indices are the same as Unicode character indices
5757
let y = f(x);
5858
assert_eq!(y, 'A');
5959
}
@@ -108,7 +108,7 @@ The types [`core::mem::MaybeUninit<T>`], [`core::cell::UnsafeCell<T>`], and [`co
108108
r[abi.compatibility.transparent]
109109
A [`struct`] declared with the `transparent` representation is *abi compatible* with its field that does not have size 0 and alignment 1, if such a field exists.
110110

111-
r[abi.compatibilty.zst]
111+
r[abi.compatibility.zst]
112112
Two types, `T` and `U`, are *abi compatible* if both have size 0 and alignment 1.
113113

114114
r[abi.compatibility.option]
@@ -138,7 +138,7 @@ Two function signatures are compatible if:
138138
139139
r[abi.compatibility.simd-abi]
140140
A type has *simd abi requirements* if:
141-
* It is a type declared with the standard-library repr-attrbute `simd`,
141+
* It is a type declared with the standard-library repr-attribute `simd`, or
142142
* It is a aggregate type[^1], which has a type with *simd abi requirements* as a field.
143143

144144
> [!NOTE]
@@ -158,13 +158,13 @@ A call to a function `f` via a function item or function pointer with a given si
158158
* The ABI tag of the signature is `extern "Rust"`, or
159159
* If any parameter type, the return type, or the type of any argument passed via C-varargs has *simd abi requirements*, each [*salient target features*][target_feature] of that type is either set at both the definition site of the function, and at the call site, or is set at neither site.
160160

161-
The behaviour a call that is not valid is undefined.
161+
The behavior of a call that is not valid is undefined.
162162

163163
> [!NOTE]
164-
> When parameter/return types do not exactly match, they are converted as though by calling [`core::mem::transmute`]. The representation and validity requirements of the type in the definition/return site still apply, for example, passing `0` to a function pointer `fn(u32)` that points to a function declared as `fn foo(x: NonZeroU32)` is undefined behaviour.
164+
> When parameter or return types do not exactly match, they are converted as though by calling [`core::mem::transmute`]. The representation and validity requirements of the type in the definition or return site still apply. For example, passing `0` to a function pointer `fn(u32)` that points to a function declared as `fn foo(x: NonZeroU32)` is undefined behavior.
165165
166166
> [!NOTE]
167-
> the ABI tag `extern "Rust"` is the default when the `extern` keyword is not used (either to declare the function within an [`extern` block], or as a [function qualifier][extern functions]). Thus it is safe to call most functions that use simd types.
167+
> The ABI tag `extern "Rust"` is the default when the `extern` keyword is not used (either to declare the function within an [`extern` block], or as a [function qualifier][extern functions]). Thus it is safe to call most functions that use simd types.
168168
169169
[^1]: The aggregate types, for the purposes of this clause, are [`struct`] types, [`enum`] types, [`union`] types, and [array] types.
170170

@@ -185,9 +185,9 @@ The behaviour a call that is not valid is undefined.
185185

186186
r[abi.used]
187187

188-
```abnf
189-
MetaItemUsed := "used"
190-
```
188+
> **<sup>Attribute Syntax</sup>**\
189+
> _MetaItemUsed_ :\
190+
> &nbsp;&nbsp; `used`
191191
192192
r[abi.used.syntax]
193193
The *`used` attribute* may be specified as a built-in attribute, using the [_MetaWord_] syntax.
@@ -275,7 +275,7 @@ extern "C" fn baz(x: i32) -> i32 {
275275
```rust,compile_fail
276276
extern "C" {
277277
#[export_name = "foo"]
278-
fn __foo(x: i32) -> i32;
278+
fn __foo(x: i32) -> i32; // error: not a free function, impl method, or static
279279
}
280280
```
281281

@@ -284,7 +284,7 @@ extern "C" {
284284
285285

286286
r[abi.symbol-name.exported]
287-
An item with either the *`no_mangle` attrbute* or the *`export_name` attribute* is an *exported item*.
287+
An item with either the *`no_mangle` attribute* or the *`export_name` attribute* is an *exported item*.
288288

289289
r[abi.symbol-name.no_mangle]
290290
The *`no_mangle` attribute* may be specified as a built-in attribute, using the [_MetaWord_] syntax. The *export name* of an item with the *`no_mangle` attribute* is the declaration name of the item.

0 commit comments

Comments
 (0)