Skip to content

Commit aae9ae2

Browse files
committed
Revert "Remove 2024 unsafe extern block notes"
This reverts commit 875b905.
1 parent b3e33db commit aae9ae2

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

src/items/external-blocks.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
> **<sup>Syntax</sup>**\
44
> _ExternBlock_ :\
5-
> &nbsp;&nbsp; `unsafe`<sup>?</sup> `extern` [_Abi_]<sup>?</sup> `{`\
5+
> &nbsp;&nbsp; `unsafe`<sup>?</sup>[^unsafe-2024] `extern` [_Abi_]<sup>?</sup> `{`\
66
> &nbsp;&nbsp; &nbsp;&nbsp; [_InnerAttribute_]<sup>\*</sup>\
77
> &nbsp;&nbsp; &nbsp;&nbsp; _ExternalItem_<sup>\*</sup>\
88
> &nbsp;&nbsp; `}`
@@ -12,6 +12,8 @@
1212
> &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; [_MacroInvocationSemi_]\
1313
> &nbsp;&nbsp; &nbsp;&nbsp; | ( [_Visibility_]<sup>?</sup> ( [_StaticItem_] | [_Function_] ) )\
1414
> &nbsp;&nbsp; )
15+
>
16+
> [^unsafe-2024]: Starting with the 2024 Edition, the `unsafe` keyword is required semantically.
1517
1618
External blocks provide _declarations_ of items that are not _defined_ in the
1719
current crate and are the basis of Rust's foreign function interface. These are
@@ -23,6 +25,11 @@ blocks is only allowed in an `unsafe` context.
2325

2426
The external block defines its functions and statics in the [value namespace] of the module or block where it is located.
2527

28+
**Edition differences**: Starting in the 2024 edition, the `unsafe` keyword is
29+
required to appear before the `extern` keyword on external blocks. In previous
30+
editions, it is accepted but not required. The `safe` and `unsafe` item qualifiers
31+
are only allowed if the external block itself is marked as `unsafe`.
32+
2633
## Functions
2734

2835
Functions within external blocks are declared in the same way as other Rust

src/items/functions.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
> &nbsp;&nbsp; &nbsp;&nbsp; ( [_BlockExpression_] | `;` )
99
>
1010
> _FunctionQualifiers_ :\
11-
> &nbsp;&nbsp; `const`<sup>?</sup> `async`[^async-edition]<sup>?</sup> _ItemSafety_<sup>?</sup> (`extern` _Abi_<sup>?</sup>)<sup>?</sup>
11+
> &nbsp;&nbsp; `const`<sup>?</sup> `async`[^async-edition]<sup>?</sup> _ItemSafety_<sup>?</sup>[^extern-qualifiers] (`extern` _Abi_<sup>?</sup>)<sup>?</sup>
1212
>
1313
> _ItemSafety_ :\
1414
> &nbsp;&nbsp; `safe`[^extern-safe] | `unsafe`
@@ -45,6 +45,10 @@
4545
> [^extern-safe]: The `safe` function qualifier is only allowed semantically within
4646
> `extern` blocks.
4747
>
48+
> [^extern-qualifiers]: *Relevant to editions earlier than Rust 2024*: Within
49+
> `extern` blocks, the `safe` or `unsafe` function qualifier is only allowed
50+
> when the `extern` is qualified as `unsafe`.
51+
>
4852
> [^fn-param-2015]: Function parameters with only a type are only allowed
4953
> in an associated function of a [trait item] in the 2015 edition.
5054

src/unsafe-keyword.md

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ Unsafe trait implementations are the logical dual to unsafe traits: where unsafe
6161

6262
The programmer who declares an [external block] must assure that the signatures of the items contained within are correct. Failing to do so may lead to undefined behavior. That this obligation has been met is indicated by writing `unsafe extern`.
6363

64+
**Edition differences**: Prior to edition 2024, `extern` blocks were allowed without being qualified as `unsafe`.
65+
6466
[external block]: items/external-blocks.md
6567

6668
## Unsafe attributes (`#[unsafe(attr)]`)

src/unsafety.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ Rust:
1111
- Accessing a field of a [`union`], other than to assign to it.
1212
- Calling an unsafe function (including an intrinsic or foreign function).
1313
- Implementing an [unsafe trait].
14-
- Declaring an [`extern`] block.
14+
- Declaring an [`extern`] block[^extern-2024].
1515
- Applying an [unsafe attribute] to an item.
1616

17+
[^extern-2024]: Prior to the 2024 edition, extern blocks were allowed to be declared without `unsafe`.
18+
1719
[`extern`]: items/external-blocks.md
1820
[`union`]: items/unions.md
1921
[mutable]: items/static-items.md#mutable-statics

0 commit comments

Comments
 (0)