Skip to content

Commit c1d4c89

Browse files
committed
Explain what makes unsafe extern blocks sound
1 parent ec00ddb commit c1d4c89

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

library/std/src/keyword_docs.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,13 @@ 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")]
388392
/// unsafe extern "C" {
389393
/// fn my_c_function(x: i32) -> bool;

0 commit comments

Comments
 (0)