Skip to content

Commit d1a7564

Browse files
traviscrossspastorino
authored andcommitted
Add missing changes to the grammar
Unsafe extern blocks imply some changes to the grammar. Let's make those and note the edition differences.
1 parent 2d83af6 commit d1a7564

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/items/external-blocks.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22

33
> **<sup>Syntax</sup>**\
44
> _ExternBlock_ :\
5-
> &nbsp;&nbsp; `unsafe`<sup>?</sup> `extern` [_Abi_]<sup>?</sup> `{`\
5+
> &nbsp;&nbsp; `unsafe`[^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; `}`
99
>
1010
> _ExternalItem_ :\
1111
> &nbsp;&nbsp; [_OuterAttribute_]<sup>\*</sup> (\
1212
> &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; [_MacroInvocationSemi_]\
13-
> &nbsp;&nbsp; &nbsp;&nbsp; | ( [_Visibility_]<sup>?</sup> ( [_StaticItem_] | [_Function_] ) )\
13+
> &nbsp;&nbsp; &nbsp;&nbsp; | ( [_Visibility_]<sup>?</sup> ( (`safe` | `unsafe`)<sup>?</sup>[^static-qualifiers] [_StaticItem_] | [_Function_] ) )\
1414
> &nbsp;&nbsp; )
15+
>
16+
> [^unsafe-2024]: Prior to the 2024 edition, the `unsafe` keyword is optional.
17+
>
18+
> [^static-qualifiers]: *Relevant to editions earlier than Rust 2024*: The `safe` or `unsafe` qualifier is only allowed when the `extern` is qualified as `unsafe`.
1519
1620
External blocks provide _declarations_ of items that are not _defined_ in the
1721
current crate and are the basis of Rust's foreign function interface. These are

src/items/functions.md

+8-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> `unsafe`<sup>?</sup> (`extern` _Abi_<sup>?</sup>)<sup>?</sup>
11+
> &nbsp;&nbsp; `const`<sup>?</sup> `async`[^async-edition]<sup>?</sup> (`safe`[^extern-safe] | `unsafe`)<sup>?</sup>[^extern-qualifiers] (`extern` _Abi_<sup>?</sup>)<sup>?</sup>
1212
>
1313
> _Abi_ :\
1414
> &nbsp;&nbsp; [STRING_LITERAL] | [RAW_STRING_LITERAL]
@@ -39,6 +39,13 @@
3939
>
4040
> [^async-edition]: The `async` qualifier is not allowed in the 2015 edition.
4141
>
42+
> [^extern-safe]: The `safe` function qualifier is only allowed within
43+
> `extern` blocks.
44+
>
45+
> [^extern-qualifiers]: *Relevant to editions earlier than Rust 2024*: Within
46+
> `extern` blocks, the `safe` or `unsafe` function qualifier is only allowed
47+
> when the `extern` is qualified as `unsafe`.
48+
>
4249
> [^fn-param-2015]: Function parameters with only a type are only allowed
4350
> in an associated function of a [trait item] in the 2015 edition.
4451

0 commit comments

Comments
 (0)