Skip to content

Commit f7a0a3a

Browse files
committed
use soundness in explaining the safety invariant
1 parent e8860ce commit f7a0a3a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Diff for: reference/src/glossary.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ fn main() { unsafe {
129129
The *safety* invariant is an invariant that safe code may assume all data to uphold.
130130
This invariant is used to justify which operations safe code can perform.
131131
The safety invariant can be temporarily violated by unsafe code, but must always be upheld when interfacing with unknown safe code.
132-
It is not relevant when arguing whether some *program* has UB, but it is relevant when arguing whether some code safely encapsulates its unsafety -- IOW, it is relevant when arguing whether some *library* can be used by safe code to *cause* UB.
132+
It is not relevant when arguing whether some *program* has UB, but it is relevant when arguing whether some code safely encapsulates its unsafety -- IOW, it is relevant when arguing whether some *library* is [sound][soundness]
133133

134134
In terms of code, some data computed by `TERM` (possibly constructed from some `arguments` that can be *assumed* to satisfy the safety invariant) is valid at type `T` if and only if the following library function can be safely exposed to arbitrary (safe) code as part of the public library interface:
135135
```rust,ignore
@@ -147,6 +147,7 @@ To summarize: *Data must always be valid, but it only must be safe in safe code.
147147
For some more information, see [this blog post](https://www.ralfj.de/blog/2018/08/22/two-kinds-of-invariants.html).
148148

149149
#### Soundness (of code / of a library)
150+
[soundness]: #soundness-of-code--of-a-library
150151

151152
We say that a library (or an individual function) is *sound* if it is impossible for safe code to cause Undefined Behavior using its public API.
152153
Conversely, the library/function is *unsound* if safe code *can* cause Undefined Behavior.

0 commit comments

Comments
 (0)