From fbf34356b709cfc0debb01acaaff038d4e339aab Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 25 Oct 2020 16:50:08 -0700 Subject: [PATCH] Add `unsafe` for `mod` and `extern`. --- src/items/external-blocks.md | 7 ++++++- src/items/modules.md | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/items/external-blocks.md b/src/items/external-blocks.md index 7acb5ce3c..b31dd17d4 100644 --- a/src/items/external-blocks.md +++ b/src/items/external-blocks.md @@ -2,7 +2,7 @@ > **Syntax**\ > _ExternBlock_ :\ ->    `extern` [_Abi_]? `{`\ +>    `unsafe`? `extern` [_Abi_]? `{`\ >       [_InnerAttribute_]\*\ >       _ExternalItem_\*\ >    `}` @@ -38,6 +38,11 @@ Two kind of item _declarations_ are allowed in external blocks: [functions] and [statics]. Calling functions or accessing statics that are declared in external blocks is only allowed in an `unsafe` context. +The `unsafe` keyword is syntactically allowed to appear before the `extern` +keyword, but it is rejected at a semantic level. This allows macros to consume +the syntax and make use of the `unsafe` keyword, before removing it from the +token stream. + ## Functions Functions within external blocks are declared in the same way as other Rust diff --git a/src/items/modules.md b/src/items/modules.md index a58bd37a2..b688665c0 100644 --- a/src/items/modules.md +++ b/src/items/modules.md @@ -2,8 +2,8 @@ > **Syntax:**\ > _Module_ :\ ->       `mod` [IDENTIFIER] `;`\ ->    | `mod` [IDENTIFIER] `{`\ +>       `unsafe`? `mod` [IDENTIFIER] `;`\ +>    | `unsafe`? `mod` [IDENTIFIER] `{`\ >         [_InnerAttribute_]\*\ >         [_Item_]\*\ >       `}` @@ -40,6 +40,11 @@ struct, enumeration, union, type parameter or crate can't shadow the name of a module in scope, or vice versa. Items brought into scope with `use` also have this restriction. +The `unsafe` keyword is syntactically allowed to appear before the `mod` +keyword, but it is rejected at a semantic level. This allows macros to consume +the syntax and make use of the `unsafe` keyword, before removing it from the +token stream. + ## Module Source Filenames A module without a body is loaded from an external file. When the module does