Skip to content

Commit 10c16ca

Browse files
authored
Merge pull request #898 from ehuss/add-unsafe-mod-extern
Add `unsafe` for `mod` and `extern`.
2 parents d850fd2 + fbf3435 commit 10c16ca

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Diff for: src/items/external-blocks.md

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

33
> **<sup>Syntax</sup>**\
44
> _ExternBlock_ :\
5-
> &nbsp;&nbsp; `extern` [_Abi_]<sup>?</sup> `{`\
5+
> &nbsp;&nbsp; `unsafe`<sup>?</sup> `extern` [_Abi_]<sup>?</sup> `{`\
66
> &nbsp;&nbsp; &nbsp;&nbsp; [_InnerAttribute_]<sup>\*</sup>\
77
> &nbsp;&nbsp; &nbsp;&nbsp; _ExternalItem_<sup>\*</sup>\
88
> &nbsp;&nbsp; `}`
@@ -38,6 +38,11 @@ Two kind of item _declarations_ are allowed in external blocks: [functions] and
3838
[statics]. Calling functions or accessing statics that are declared in external
3939
blocks is only allowed in an `unsafe` context.
4040

41+
The `unsafe` keyword is syntactically allowed to appear before the `extern`
42+
keyword, but it is rejected at a semantic level. This allows macros to consume
43+
the syntax and make use of the `unsafe` keyword, before removing it from the
44+
token stream.
45+
4146
## Functions
4247

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

Diff for: src/items/modules.md

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

33
> **<sup>Syntax:</sup>**\
44
> _Module_ :\
5-
> &nbsp;&nbsp; &nbsp;&nbsp; `mod` [IDENTIFIER] `;`\
6-
> &nbsp;&nbsp; | `mod` [IDENTIFIER] `{`\
5+
> &nbsp;&nbsp; &nbsp;&nbsp; `unsafe`<sup>?</sup> `mod` [IDENTIFIER] `;`\
6+
> &nbsp;&nbsp; | `unsafe`<sup>?</sup> `mod` [IDENTIFIER] `{`\
77
> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; [_InnerAttribute_]<sup>\*</sup>\
88
> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; [_Item_]<sup>\*</sup>\
99
> &nbsp;&nbsp; &nbsp;&nbsp; `}`
@@ -40,6 +40,11 @@ struct, enumeration, union, type parameter or crate can't shadow the name of a
4040
module in scope, or vice versa. Items brought into scope with `use` also have
4141
this restriction.
4242

43+
The `unsafe` keyword is syntactically allowed to appear before the `mod`
44+
keyword, but it is rejected at a semantic level. This allows macros to consume
45+
the syntax and make use of the `unsafe` keyword, before removing it from the
46+
token stream.
47+
4348
## Module Source Filenames
4449

4550
A module without a body is loaded from an external file. When the module does

0 commit comments

Comments
 (0)