From 64fb10c409cf2c958c628ae9ccc5f3677e6a31d0 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 9 Aug 2024 15:41:03 -0700 Subject: [PATCH 1/2] Revert "Remove 2024 unsafe extern block notes" This reverts commit 875b905a389455c5329ae088600c0b5f7222104d. --- src/items/external-blocks.md | 9 ++++++++- src/items/functions.md | 6 +++++- src/unsafe-keyword.md | 2 ++ src/unsafety.md | 4 +++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/items/external-blocks.md b/src/items/external-blocks.md index 5839f242b..c2d159117 100644 --- a/src/items/external-blocks.md +++ b/src/items/external-blocks.md @@ -5,7 +5,7 @@ r[items.extern] r[items.extern.syntax] > **Syntax**\ > _ExternBlock_ :\ ->    `unsafe`? `extern` [_Abi_]? `{`\ +>    `unsafe`?[^unsafe-2024] `extern` [_Abi_]? `{`\ >       [_InnerAttribute_]\*\ >       _ExternalItem_\*\ >    `}` @@ -15,6 +15,8 @@ r[items.extern.syntax] >          [_MacroInvocationSemi_]\ >       | ( [_Visibility_]? ( [_StaticItem_] | [_Function_] ) )\ >    ) +> +> [^unsafe-2024]: Starting with the 2024 Edition, the `unsafe` keyword is required semantically. r[items.extern.intro] 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 r[items.extern.namespace] The external block defines its functions and statics in the [value namespace] of the module or block where it is located. +**Edition differences**: Starting in the 2024 edition, the `unsafe` keyword is +required to appear before the `extern` keyword on external blocks. In previous +editions, it is accepted but not required. The `safe` and `unsafe` item qualifiers +are only allowed if the external block itself is marked as `unsafe`. + ## Functions r[items.extern.fn] diff --git a/src/items/functions.md b/src/items/functions.md index 8300ad19d..1fe173e70 100644 --- a/src/items/functions.md +++ b/src/items/functions.md @@ -11,7 +11,7 @@ r[items.fn.syntax] >       ( [_BlockExpression_] | `;` ) > > _FunctionQualifiers_ :\ ->    `const`? `async`[^async-edition]? _ItemSafety_? (`extern` _Abi_?)? +>    `const`? `async`[^async-edition]? _ItemSafety_?[^extern-qualifiers] (`extern` _Abi_?)? > > _ItemSafety_ :\ >    `safe`[^extern-safe] | `unsafe` @@ -48,6 +48,10 @@ r[items.fn.syntax] > [^extern-safe]: The `safe` function qualifier is only allowed semantically within > `extern` blocks. > +> [^extern-qualifiers]: *Relevant to editions earlier than Rust 2024*: Within +> `extern` blocks, the `safe` or `unsafe` function qualifier is only allowed +> when the `extern` is qualified as `unsafe`. +> > [^fn-param-2015]: Function parameters with only a type are only allowed > in an associated function of a [trait item] in the 2015 edition. diff --git a/src/unsafe-keyword.md b/src/unsafe-keyword.md index 232fcca1b..e78ab1b46 100644 --- a/src/unsafe-keyword.md +++ b/src/unsafe-keyword.md @@ -81,6 +81,8 @@ r[unsafe.extern] 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`. +**Edition differences**: Prior to edition 2024, `extern` blocks were allowed without being qualified as `unsafe`. + [external block]: items/external-blocks.md ## Unsafe attributes (`#[unsafe(attr)]`) diff --git a/src/unsafety.md b/src/unsafety.md index daa6834b5..88aaf373b 100644 --- a/src/unsafety.md +++ b/src/unsafety.md @@ -26,11 +26,13 @@ r[safety.unsafe-impl] - Implementing an [unsafe trait]. r[safety.unsafe-extern] -- Declaring an [`extern`] block. +- Declaring an [`extern`] block[^extern-2024]. r[safety.unsafe-attribute] - Applying an [unsafe attribute] to an item. +[^extern-2024]: Prior to the 2024 edition, extern blocks were allowed to be declared without `unsafe`. + [`extern`]: items/external-blocks.md [`union`]: items/unions.md [mutable]: items/static-items.md#mutable-statics From bbc678562db983afce10bdb6c9be8d85efd72f28 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 4 Nov 2024 10:22:25 -0800 Subject: [PATCH 2/2] Update edition differences for unsafe extern blocks This follows the style that the main text should describe the current edition, and that edition differences are in a blockquote, and they describe what is different. --- src/items/external-blocks.md | 9 +++++---- src/unsafe-keyword.md | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/items/external-blocks.md b/src/items/external-blocks.md index c2d159117..74aa5cedb 100644 --- a/src/items/external-blocks.md +++ b/src/items/external-blocks.md @@ -33,10 +33,11 @@ Calling functions or accessing statics that are declared in external blocks is o r[items.extern.namespace] The external block defines its functions and statics in the [value namespace] of the module or block where it is located. -**Edition differences**: Starting in the 2024 edition, the `unsafe` keyword is -required to appear before the `extern` keyword on external blocks. In previous -editions, it is accepted but not required. The `safe` and `unsafe` item qualifiers -are only allowed if the external block itself is marked as `unsafe`. +r[items.extern.unsafe-required] +The `unsafe` keyword is semantically required to appear before the `extern` keyword on external blocks. + +r[items.extern.edition2024] +> **Edition differences**: Prior to the 2024 edition, the `unsafe` keyword is optional. The `safe` and `unsafe` item qualifiers are only allowed if the external block itself is marked as `unsafe`. ## Functions diff --git a/src/unsafe-keyword.md b/src/unsafe-keyword.md index e78ab1b46..333140dd1 100644 --- a/src/unsafe-keyword.md +++ b/src/unsafe-keyword.md @@ -81,7 +81,8 @@ r[unsafe.extern] 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`. -**Edition differences**: Prior to edition 2024, `extern` blocks were allowed without being qualified as `unsafe`. +r[unsafe.extern.edition2024] +> **Edition differences**: Prior to edition 2024, `extern` blocks were allowed without being qualified as `unsafe`. [external block]: items/external-blocks.md