diff --git a/src/items/external-blocks.md b/src/items/external-blocks.md index c08303d507471..4916ad5bb8fce 100644 --- a/src/items/external-blocks.md +++ b/src/items/external-blocks.md @@ -101,9 +101,14 @@ specified name. extern { } ``` -The type of a function declared in an extern block is `extern "abi" fn(A1, ..., -An) -> R`, where `A1...An` are the declared types of its arguments and `R` is -the declared return type. +A function declared in an extern block is implicitly `unsafe`. When coerced to +a function pointer, a function declared in an extern block has type `unsafe +extern "abi" for<'l1, ..., 'lm> fn(A1, ..., An) -> R`, where `'l1`, ... `'lm` +are its lifetime parameters, `A1`, ..., `An` are the declared types of its +parameters and `R` is the declared return type. + +It is `unsafe` to access a static item declared in an extern block, whether or +not it's mutable. It is valid to add the `link` attribute on an empty extern block. You can use this to satisfy the linking requirements of extern blocks elsewhere in your diff --git a/src/unsafety.md b/src/unsafety.md index e5331e6a2205b..0f4fab9e6f924 100644 --- a/src/unsafety.md +++ b/src/unsafety.md @@ -7,14 +7,14 @@ The following language level features cannot be used in the safe subset of Rust: - Dereferencing a [raw pointer]. -- Reading or writing a [mutable static variable]. -- Reading a field of a [`union`], or writing to a field of a - union that isn't [`Copy`]. +- Reading or writing a [mutable] or [external] static variable. +- Accessing a field of a [`union`], other than to assign to it. - Calling an unsafe function (including an intrinsic or foreign function). - Implementing an [unsafe trait]. [`Copy`]: special-types-and-traits.html#copy [`union`]: items/unions.html [mutable static variable]: items/static-items.html#mutable-statics +[external static variable]: items/external-blocks.html [raw pointer]: types.html#pointer-types [unsafe trait]: items/traits.html#unsafe-traits