|
| 1 | +- Feature Name: `reserve_throw_fail` |
| 2 | +- Start Date: 2018-05-14 |
| 3 | +- RFC PR: |
| 4 | +- Rust Issue: |
| 5 | + |
| 6 | +# Summary |
| 7 | +[summary]: #summary |
| 8 | + |
| 9 | +The keywords `throw` and `fail` are reserved in edition 2018 and beyond. |
| 10 | + |
| 11 | +# Motivation |
| 12 | +[motivation]: #motivation |
| 13 | + |
| 14 | +[RFC 2426]: https://github.com/rust-lang/rfcs/pull/2426 |
| 15 | + |
| 16 | +The motivation for reserving `fail` and `throw` are so that we have the option |
| 17 | +to later use them for some `fail expr` or `throw expr`-like construct such as |
| 18 | +proposed in [RFC 2426]. |
| 19 | + |
| 20 | +Since edition 2018 is approaching, we are under time constraints to get the |
| 21 | +keyword reserved even if the details of [RFC 2426] or similar proposals have |
| 22 | +not been fully fleshed out. |
| 23 | + |
| 24 | +The reason we are reserving two keywords is so that we can delay the choice |
| 25 | +between them since there isn't consensus for which one to pick. |
| 26 | + |
| 27 | +# Guide-level explanation |
| 28 | +[guide-level-explanation]: #guide-level-explanation |
| 29 | + |
| 30 | +The words `fail` and `throw` are reserved as keywords in edition 2018. |
| 31 | +This means that code in edition 2018 can't use it directly as an identifier. |
| 32 | +However, you can always use raw identifiers as in `r#fail` if you need |
| 33 | +to refer to `fail`, used in a crate from 2015, from an edition 2018 crate. |
| 34 | + |
| 35 | +# Reference-level explanation |
| 36 | +[reference-level-explanation]: #reference-level-explanation |
| 37 | + |
| 38 | +[list of keywords]: https://doc.rust-lang.org/book/second-edition/appendix-01-keywords.html |
| 39 | + |
| 40 | +The words `fail` and `throw` are reserved as keywords in edition 2018 and |
| 41 | +added to the [list of keywords]. |
| 42 | + |
| 43 | +# Drawbacks |
| 44 | +[drawbacks]: #drawbacks |
| 45 | + |
| 46 | +## It might not end up being used |
| 47 | + |
| 48 | +Simply put, we *might* not end up using any of the keywords. |
| 49 | +We can also be certain that only one of the keywords will be used in the end. |
| 50 | + |
| 51 | +## Edition breakage |
| 52 | + |
| 53 | +Some code will break when transitioning from edition 2015 to 2018. |
| 54 | +Most of this will be easily fixable with `rustfix`. |
| 55 | +However, transitioning between editions will add some churn. |
| 56 | + |
| 57 | +### For `throw` |
| 58 | + |
| 59 | +We analyse the extent of the breakage and find that `throw`: |
| 60 | + |
| 61 | ++ is not used as an identifier in the standard library. |
| 62 | ++ is used as the name of a [crate](https://crates.io/crates/throw). |
| 63 | + This crate has zero reverse dependencies. |
| 64 | ++ is found 3+ times by [sourcegraph](https://sourcegraph.com/search?q=repogroup:crates+case:yes++\b((let|const|type|)\s%2Bthrow\s%2B%3D|(fn|impl|mod|struct|enum|union|trait)\s%2Bthrow)\b+max:400). |
| 65 | + The extent of breakage is minimal. |
| 66 | + |
| 67 | +### For `fail` |
| 68 | + |
| 69 | +We analyse the extent of the breakage and find that `fail`: |
| 70 | + |
| 71 | ++ is not used as an identifier in the standard library. |
| 72 | ++ is used as the name of a [crate](https://crates.io/crates/fail). |
| 73 | + This one does have 5 reverse dependencies. |
| 74 | + However, they are all written by the same author. |
| 75 | + |
| 76 | ++ is found 20+ times by [sourcegraph](https://sourcegraph.com/search?q=repogroup:crates+case:yes++%5Cb%28%28let%7Cconst%7Ctype%7C%29%5Cs%2Bfail%5Cs%2B%3D%7C%28fn%7Cimpl%7Cmod%7Cstruct%7Cenum%7Cunion%7Ctrait%29%5Cs%2Bfail%29%5Cb+max:400). |
| 77 | + The extent of breakage is fairly minimal. |
| 78 | + |
| 79 | +# Rationale and alternatives |
| 80 | +[alternatives]: #alternatives |
| 81 | + |
| 82 | +A more frugal option to reserving two words would be to reserve one word. |
| 83 | +However, as mentioned before, there is no consensus for which word that would be. |
| 84 | + |
| 85 | +Another option is to simply not reserve anything, which would limit our options |
| 86 | +for the future. However, we feel confident that we should keep this option open |
| 87 | +to us right now. Not doing so would mean that we couldn't use the words `fail` |
| 88 | +or `throw` as keywords for another 3 years or so. |
| 89 | + |
| 90 | +[keyword policy]: https://paper.dropbox.com/doc/Keyword-policy-SmIMziXBzoQOEQmRgjJPm |
| 91 | +[permalink]: https://gist.github.com/Centril/4c82c19b3cb02cc565622a37d1591785 |
| 92 | + |
| 93 | +The keywords also can't be contextual since `fail {}` would clash with a struct |
| 94 | +named `fail`. See [RFC 2426] for a longer discussion. |
| 95 | +Furthermore, a recent [keyword policy] ([permalink]), adopted by the language |
| 96 | +team, decided that moving forward, keywords for new features in new editions |
| 97 | +should be real keywords instead of being contextual. The main motivation |
| 98 | +for this was to optimize for maintenance (and reduce technical debt). |
| 99 | + |
| 100 | +With respect to the choice of keyword, it is also discussed in [RFC 2426]. |
| 101 | +We pick `fail` as the non-exceptional alternative and `throw` as the most |
| 102 | +popular exceptional alternative. Since `raise` is exceptional terminology but |
| 103 | +not as frequently used as `throw`, we will not reserve it. |
| 104 | + |
| 105 | +# Prior art |
| 106 | +[prior-art]: #prior-art |
| 107 | + |
| 108 | +For usage of a `throw` like construct, see [RFC 2426](https://github.com/Centril/rfcs/blob/rfc/throw-expr/text/0000-throw-expr.md#prior-art)'s prior art. |
| 109 | + |
| 110 | +# Unresolved questions |
| 111 | +[unresolved]: #unresolved-questions |
| 112 | + |
| 113 | +None. |
0 commit comments