During the throw
/fail
keyword reservation RFC, @aturon proposed an alternative to keyword reservation that was, later, enhanced by sfackler. I've restated the idea below.
Motivation
Rust editions present an opportunity to reserve keywords and other syntactic constructs, and in the 2018 edition, several such reservations were proposed, including keyword reservations for exception propagation, trait delegation, named arguments, and the !
type. The goal of these reservations was to decrease the pressure to propose a full RFC by reserving these constructs proactively, deferring further discussion until after Rust 2018 shipped. As form follows function, the syntax reservation RFCs included discussion of the feature at large, now with heightened urgency imposed by the edition. This created precisely the situation keyword reservation intended to avoid.
Keyword gates alleviate this pressure by allowing keyword reservation behind a specialized feature gate. Gated keywords are then promoted out of the gate in the next edition.
High-level explanation
Keyword gates are a meta-feature. The guide-level explanation applies to specific keywords. The following text demonstrates a guide-level explanation for a hypothetical keyword, yolo
:
In order to prevent unexpected name clashes with
yolo
, you have to activate the keyword. This example activatesyolo
within a module:#[keywords(yolo)] mod foo { // ... }
You can enable
yolo
for a whole crate by adding#![keywords(yolo)]
to the crate's lib.rs.
The two comments I linked above provide some additional context to the idea, notably @aturon's idea of limiting the scope of the annotation by strictly tying it to the edition cycle. est31, joshtriplett, warlord500, withoutboats, steveklabnik, centril, Ixrec, and I (illustrious-you) also offered their opinions during the throw/fail FCP.
I suggest reading those comments to regain the context I didn't cover in the strawman proposal above.
Thoughts?