Skip to content

Commit 64fb10c

Browse files
committed
Revert "Remove 2024 unsafe extern block notes"
This reverts commit 875b905.
1 parent da0f6da commit 64fb10c

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

src/items/external-blocks.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ r[items.extern]
55
r[items.extern.syntax]
66
> **<sup>Syntax</sup>**\
77
> _ExternBlock_ :\
8-
> &nbsp;&nbsp; `unsafe`<sup>?</sup> `extern` [_Abi_]<sup>?</sup> `{`\
8+
> &nbsp;&nbsp; `unsafe`<sup>?</sup>[^unsafe-2024] `extern` [_Abi_]<sup>?</sup> `{`\
99
> &nbsp;&nbsp; &nbsp;&nbsp; [_InnerAttribute_]<sup>\*</sup>\
1010
> &nbsp;&nbsp; &nbsp;&nbsp; _ExternalItem_<sup>\*</sup>\
1111
> &nbsp;&nbsp; `}`
@@ -15,6 +15,8 @@ r[items.extern.syntax]
1515
> &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; [_MacroInvocationSemi_]\
1616
> &nbsp;&nbsp; &nbsp;&nbsp; | ( [_Visibility_]<sup>?</sup> ( [_StaticItem_] | [_Function_] ) )\
1717
> &nbsp;&nbsp; )
18+
>
19+
> [^unsafe-2024]: Starting with the 2024 Edition, the `unsafe` keyword is required semantically.
1820
1921
r[items.extern.intro]
2022
External blocks provide _declarations_ of items that are not _defined_ in the
@@ -31,6 +33,11 @@ Calling functions or accessing statics that are declared in external blocks is o
3133
r[items.extern.namespace]
3234
The external block defines its functions and statics in the [value namespace] of the module or block where it is located.
3335

36+
**Edition differences**: Starting in the 2024 edition, the `unsafe` keyword is
37+
required to appear before the `extern` keyword on external blocks. In previous
38+
editions, it is accepted but not required. The `safe` and `unsafe` item qualifiers
39+
are only allowed if the external block itself is marked as `unsafe`.
40+
3441
## Functions
3542

3643
r[items.extern.fn]

src/items/functions.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ r[items.fn.syntax]
1111
> &nbsp;&nbsp; &nbsp;&nbsp; ( [_BlockExpression_] | `;` )
1212
>
1313
> _FunctionQualifiers_ :\
14-
> &nbsp;&nbsp; `const`<sup>?</sup> `async`[^async-edition]<sup>?</sup> _ItemSafety_<sup>?</sup> (`extern` _Abi_<sup>?</sup>)<sup>?</sup>
14+
> &nbsp;&nbsp; `const`<sup>?</sup> `async`[^async-edition]<sup>?</sup> _ItemSafety_<sup>?</sup>[^extern-qualifiers] (`extern` _Abi_<sup>?</sup>)<sup>?</sup>
1515
>
1616
> _ItemSafety_ :\
1717
> &nbsp;&nbsp; `safe`[^extern-safe] | `unsafe`
@@ -48,6 +48,10 @@ r[items.fn.syntax]
4848
> [^extern-safe]: The `safe` function qualifier is only allowed semantically within
4949
> `extern` blocks.
5050
>
51+
> [^extern-qualifiers]: *Relevant to editions earlier than Rust 2024*: Within
52+
> `extern` blocks, the `safe` or `unsafe` function qualifier is only allowed
53+
> when the `extern` is qualified as `unsafe`.
54+
>
5155
> [^fn-param-2015]: Function parameters with only a type are only allowed
5256
> in an associated function of a [trait item] in the 2015 edition.
5357

src/unsafe-keyword.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ r[unsafe.extern]
8181

8282
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`.
8383

84+
**Edition differences**: Prior to edition 2024, `extern` blocks were allowed without being qualified as `unsafe`.
85+
8486
[external block]: items/external-blocks.md
8587

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

src/unsafety.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ r[safety.unsafe-impl]
2626
- Implementing an [unsafe trait].
2727

2828
r[safety.unsafe-extern]
29-
- Declaring an [`extern`] block.
29+
- Declaring an [`extern`] block[^extern-2024].
3030

3131
r[safety.unsafe-attribute]
3232
- Applying an [unsafe attribute] to an item.
3333

34+
[^extern-2024]: Prior to the 2024 edition, extern blocks were allowed to be declared without `unsafe`.
35+
3436
[`extern`]: items/external-blocks.md
3537
[`union`]: items/unions.md
3638
[mutable]: items/static-items.md#mutable-statics

0 commit comments

Comments
 (0)