Skip to content

Commit 3b91303

Browse files
authored
Unrolled build for rust-lang#140216
Rollup merge of rust-lang#140216 - t5kd:master, r=tgross35 Document that "extern blocks must be unsafe" in Rust 2024 The [documentation on `extern`](https://doc.rust-lang.org/std/keyword.extern.html) contains the following code sample: ```rust #[link(name = "my_c_library")] extern "C" { fn my_c_function(x: i32) -> bool; } ``` Due to rust-lang#123743, attempting to compile such code with the 2024 edition of Rust fails: ``` error: extern blocks must be unsafe ``` This PR extends the `extern` documentation with a brief explanation of the new requirement. It also adds the missing `unsafe` keyword to the code sample, which should be compatible with rustc since v1.82. **Related docs:** - https://doc.rust-lang.org/reference/items/external-blocks.html - https://doc.rust-lang.org/edition-guide/rust-2024/unsafe-extern.html
2 parents d3508a8 + 1862feb commit 3b91303

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

library/std/src/keyword_docs.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,15 @@ mod enum_keyword {}
388388
/// lazy_static;`. The other use is in foreign function interfaces (FFI).
389389
///
390390
/// `extern` is used in two different contexts within FFI. The first is in the form of external
391-
/// blocks, for declaring function interfaces that Rust code can call foreign code by.
391+
/// blocks, for declaring function interfaces that Rust code can call foreign code by. This use
392+
/// of `extern` is unsafe, since we are asserting to the compiler that all function declarations
393+
/// are correct. If they are not, using these items may lead to undefined behavior.
392394
///
393395
/// ```rust ignore
396+
/// // SAFETY: The function declarations given below are in
397+
/// // line with the header files of `my_c_library`.
394398
/// #[link(name = "my_c_library")]
395-
/// extern "C" {
399+
/// unsafe extern "C" {
396400
/// fn my_c_function(x: i32) -> bool;
397401
/// }
398402
/// ```

0 commit comments

Comments
 (0)