Skip to content

Commit c13d2d2

Browse files
committed
Revise language of warning about safe variadics
Let's adjust this language so that it talks about the guarantees that the function must make, and so that it says what may lead to UB rather than what "is" UB, as the latter implies immediate language UB, when this is actually library UB. Let's also add a `SAFETY` comment to the function in the example.
1 parent f02d746 commit c13d2d2

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/items/external-blocks.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,14 @@ unsafe extern "C" {
179179
unsafe fn foo(...);
180180
unsafe fn bar(x: i32, ...);
181181
unsafe fn with_name(format: *const u8, args: ...);
182+
// SAFETY: This function guarantees it will not access
183+
// variadic arguments.
182184
safe fn ignores_variadic_arguments(x: i32, ...);
183185
}
184186
```
185187

186188
> [!WARNING]
187-
> `safe` should only be used in cases where the function does not look at the variadic arguments at all. Passing an unexpected number of arguments or arguments of an unexpected type to a variadic function is [undefined behavior][undefined].
189+
> The `safe` qualifier should not be used on a function in an `extern` block unless that function guarantees that it will not access the variadic arguments at all. Passing an unexpected number of arguments or arguments of unexpected type to a variadic function may lead to [undefined behavior][undefined].
188190
189191
r[items.extern.attributes]
190192
## Attributes on extern blocks

0 commit comments

Comments
 (0)