Skip to content

Commit 1862feb

Browse files
committed
Update extern docs for Rust 2024 and add safety remarks
1 parent e3e432d commit 1862feb

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
@@ -381,11 +381,15 @@ mod enum_keyword {}
381381
/// lazy_static;`. The other use is in foreign function interfaces (FFI).
382382
///
383383
/// `extern` is used in two different contexts within FFI. The first is in the form of external
384-
/// blocks, for declaring function interfaces that Rust code can call foreign code by.
384+
/// blocks, for declaring function interfaces that Rust code can call foreign code by. This use
385+
/// of `extern` is unsafe, since we are asserting to the compiler that all function declarations
386+
/// are correct. If they are not, using these items may lead to undefined behavior.
385387
///
386388
/// ```rust ignore
389+
/// // SAFETY: The function declarations given below are in
390+
/// // line with the header files of `my_c_library`.
387391
/// #[link(name = "my_c_library")]
388-
/// extern "C" {
392+
/// unsafe extern "C" {
389393
/// fn my_c_function(x: i32) -> bool;
390394
/// }
391395
/// ```

0 commit comments

Comments
 (0)