Skip to content

Commit 9fa9987

Browse files
authored
Merge pull request #2276 from ehuss/unwrap-last
Unwrap a few remaining chapters
2 parents 3c5c1c2 + 6ace9ab commit 9fa9987

9 files changed

Lines changed: 125 additions & 417 deletions

src/abi.md

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ r[abi]
22
# Application binary interface (ABI)
33

44
r[abi.intro]
5-
This section documents features that affect the ABI of the compiled output of
6-
a crate.
5+
This section documents features that affect the ABI of the compiled output of a crate.
76

8-
See *[extern functions]* for information on specifying the ABI for exporting
9-
functions. See *[external blocks]* for information on specifying the ABI for
10-
linking external libraries.
7+
See *[extern functions]* for information on specifying the ABI for exporting functions. See *[external blocks]* for information on specifying the ABI for linking external libraries.
118

129
<!-- template:attributes -->
1310
r[abi.used]
@@ -68,17 +65,13 @@ r[abi.no_mangle]
6865
## The `no_mangle` attribute
6966
7067
r[abi.no_mangle.intro]
71-
The *`no_mangle` attribute* may be used on any [item] to disable standard
72-
symbol name mangling. The symbol for the item will be the identifier of the
73-
item's name.
68+
The *`no_mangle` attribute* may be used on any [item] to disable standard symbol name mangling. The symbol for the item will be the identifier of the item's name.
7469
7570
r[abi.no_mangle.publicly-exported]
76-
Additionally, the item will be publicly exported from the produced library or
77-
object file, similar to the [`used` attribute](#the-used-attribute).
71+
Additionally, the item will be publicly exported from the produced library or object file, similar to the [`used` attribute](#the-used-attribute).
7872
7973
r[abi.no_mangle.unsafe]
80-
This attribute is unsafe as an unmangled symbol may collide with another symbol
81-
with the same name (or with a well-known symbol), leading to undefined behavior.
74+
This attribute is unsafe as an unmangled symbol may collide with another symbol with the same name (or with a well-known symbol), leading to undefined behavior.
8275
8376
```rust
8477
#[unsafe(no_mangle)]
@@ -93,8 +86,7 @@ r[abi.link_section]
9386
## The `link_section` attribute
9487
9588
r[abi.link_section.intro]
96-
The *`link_section` attribute* specifies the section of the object file that a
97-
[function] or [static]'s content will be placed into.
89+
The *`link_section` attribute* specifies the section of the object file that a [function] or [static]'s content will be placed into.
9890
9991
r[abi.link_section.syntax]
10092
The `link_section` attribute uses the [MetaNameValueStr] syntax to specify the section name.
@@ -109,8 +101,7 @@ pub static VAR1: u32 = 1;
109101
```
110102
111103
r[abi.link_section.unsafe]
112-
This attribute is unsafe as it allows users to place data and code into sections
113-
of memory not expecting them, such as mutable data into read-only areas.
104+
This attribute is unsafe as it allows users to place data and code into sections of memory not expecting them, such as mutable data into read-only areas.
114105

115106
r[abi.link_section.duplicates]
116107
Only the first use of `link_section` on an item has effect.
@@ -126,8 +117,7 @@ r[abi.export_name]
126117
## The `export_name` attribute
127118

128119
r[abi.export_name.intro]
129-
The *`export_name` attribute* specifies the name of the symbol that will be
130-
exported on a [function] or [static].
120+
The *`export_name` attribute* specifies the name of the symbol that will be exported on a [function] or [static].
131121

132122
r[abi.export_name.syntax]
133123
The `export_name `attribute uses the [MetaNameValueStr] syntax to specify the symbol name.
@@ -138,9 +128,7 @@ pub fn name_in_rust() { }
138128
```
139129

140130
r[abi.export_name.unsafe]
141-
This attribute is unsafe as a symbol with a custom name may collide with another
142-
symbol with the same name (or with a well-known symbol), leading to undefined
143-
behavior.
131+
This attribute is unsafe as a symbol with a custom name may collide with another symbol with the same name (or with a well-known symbol), leading to undefined behavior.
144132

145133
r[abi.export_name.duplicates]
146134
Only the first use of `export_name` on an item has effect.

src/behavior-considered-undefined.md

Lines changed: 30 additions & 89 deletions
Large diffs are not rendered by default.
Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Behavior not considered `unsafe`
22

3-
The Rust compiler does not consider the following behaviors _unsafe_,
4-
though a programmer may (should) find them undesirable, unexpected,
5-
or erroneous.
3+
The Rust compiler does not consider the following behaviors _unsafe_, though a programmer may (should) find them undesirable, unexpected, or erroneous.
64

75
- Deadlocks
86
- Leaks of memory and other resources
@@ -11,47 +9,22 @@ or erroneous.
119

1210
## Integer overflow
1311

14-
If a program contains arithmetic overflow, the programmer has made an
15-
error. In the following discussion, we maintain a distinction between
16-
arithmetic overflow and wrapping arithmetic. The first is erroneous,
17-
while the second is intentional.
12+
If a program contains arithmetic overflow, the programmer has made an error. In the following discussion, we maintain a distinction between arithmetic overflow and wrapping arithmetic. The first is erroneous, while the second is intentional.
1813

19-
When the programmer has enabled `debug_assert!` assertions (for
20-
example, by enabling a non-optimized build), implementations must
21-
insert dynamic checks that `panic` on overflow. Other kinds of builds
22-
may result in `panics` or silently wrapped values on overflow, at the
23-
implementation's discretion.
14+
When the programmer has enabled `debug_assert!` assertions (for example, by enabling a non-optimized build), implementations must insert dynamic checks that `panic` on overflow. Other kinds of builds may result in `panics` or silently wrapped values on overflow, at the implementation's discretion.
2415

25-
In the case of implicitly-wrapped overflow, implementations must
26-
provide well-defined (even if still considered erroneous) results by
27-
using two's complement overflow conventions.
16+
In the case of implicitly-wrapped overflow, implementations must provide well-defined (even if still considered erroneous) results by using two's complement overflow conventions.
2817

29-
The integral types provide inherent methods to allow programmers
30-
explicitly to perform wrapping arithmetic. For example,
31-
`i32::wrapping_add` provides two's complement, wrapping addition.
18+
The integral types provide inherent methods to allow programmers explicitly to perform wrapping arithmetic. For example, `i32::wrapping_add` provides two's complement, wrapping addition.
3219

33-
The standard library also provides a `Wrapping<T>` newtype which
34-
ensures all standard arithmetic operations for `T` have wrapping
35-
semantics.
20+
The standard library also provides a `Wrapping<T>` newtype which ensures all standard arithmetic operations for `T` have wrapping semantics.
3621

37-
See [RFC 560] for error conditions, rationale, and more details about
38-
integer overflow.
22+
See [RFC 560] for error conditions, rationale, and more details about integer overflow.
3923

4024
## Logic errors
4125

42-
Safe code may impose extra logical constraints that can be checked
43-
at neither compile-time nor runtime. If a program breaks such
44-
a constraint, the behavior may be unspecified but will not result in
45-
undefined behavior. This could include panics, incorrect results,
46-
aborts, and non-termination. The behavior may also differ between
47-
runs, builds, or kinds of build.
48-
49-
For example, implementing both `Hash` and `Eq` requires that values
50-
considered equal have equal hashes. Another example are data structures
51-
like `BinaryHeap`, `BTreeMap`, `BTreeSet`, `HashMap` and `HashSet`
52-
which describe constraints on the modification of their keys while
53-
they are in the data structure. Violating such constraints is not
54-
considered unsafe, yet the program is considered erroneous and
55-
its behavior unpredictable.
26+
Safe code may impose extra logical constraints that can be checked at neither compile-time nor runtime. If a program breaks such a constraint, the behavior may be unspecified but will not result in undefined behavior. This could include panics, incorrect results, aborts, and non-termination. The behavior may also differ between runs, builds, or kinds of build.
27+
28+
For example, implementing both `Hash` and `Eq` requires that values considered equal have equal hashes. Another example are data structures like `BinaryHeap`, `BTreeMap`, `BTreeSet`, `HashMap` and `HashSet` which describe constraints on the modification of their keys while they are in the data structure. Violating such constraints is not considered unsafe, yet the program is considered erroneous and its behavior unpredictable.
5629

5730
[RFC 560]: https://github.com/rust-lang/rfcs/blob/master/text/0560-integer-overflow.md

0 commit comments

Comments
 (0)