Skip to content

Commit 176d73f

Browse files
committed
Clarify extent of UB
An incorrect declaration in an `extern` block may cause undefined behavior in the resulting program. Let's clarify that in the text. (Thanks to Waffle for raising this point.)
1 parent 842bd55 commit 176d73f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

text/0000-unsafe-extern-blocks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ unsafe extern {
5656
}
5757
```
5858

59-
`extern` blocks are `unsafe` because if the declaration doesn't match the actual external function, or the actual external data, then it causes compile time Undefined Behavior (UB).
59+
`extern` blocks are `unsafe` because if the declaration doesn't match the actual external function, or the actual external data, then the behavior of the resulting program may be undefined.
6060

6161
Once they are unsafely declared, a `safe` item can be used outside the `extern` block as if it were any other safe function or static value declared within rust.
6262
The unsafe obligation of ensuring that the correct items are being linked to is performed by the crate making the declaration, not the crate using that declaration.
@@ -77,7 +77,7 @@ Replace the *Functions* and *Statics* sections with the following:
7777
### Functions
7878
Functions within external blocks are declared in the same way as other Rust functions, with the exception that they must not have a body and are instead terminated by a semicolon. Patterns are not allowed in parameters, only IDENTIFIER or _ may be used. The function qualifiers `const`, `async`, and `extern` are not allowed. If the function is unsafe to call, then the function should use the `unsafe` qualifier. If the function is safe to call, then the function should use the `safe` qualifier (a contextual keyword). Functions that are not qualified as `unsafe` or `safe` are assumed to be `unsafe`.
7979

80-
If the function signature declared in Rust is incompatible with the function signature as declared in the foreign code it is Undefined Behavior to compile and link the code.
80+
If the function signature declared in Rust is incompatible with the function signature as declared in the foreign code, the behavior of the resulting program may be undefined.
8181

8282
Functions within external blocks may be called by Rust code, just like functions defined in Rust. The Rust compiler will automatically use the correct foreign ABI when making the call.
8383

0 commit comments

Comments
 (0)