Permit attributes on 'if' expressions by Aaron1011 · Pull Request #69201 · rust-lang/rust (original) (raw)
From #68658 (comment):
We discussed this in today's language team meeting (2020-02-13).
Those present, in particular myself and @joshtriplett, felt that of the options available (1. keep the status quo, 2. accept only syntactically, 3. accept semantically also), that the 3rd option would be the simplest, and least complex approach.
Specifically, we would like to allow
#[attr]
onif
both syntactically (in the parser) and semantically (expansion / conditional compilation, subject to existing feature gates forstmt_expr_attributes
, e.g.#[allow()] match 0 { _ => {} };
(ungated) vs.let _ = #[allow()] match 0 { _ => {} };
(gated)).In reaching this conclusion, we did consult RFC 16 regarding attributes on
if
expressions. We noted in particular that neither ofelse #[cfg(not(bar))] if cond2
orelse #[cfg(not(baz))] {
. Moreover, as @petrochenkov notes in #68658 (comment):It's pretty established now that macros and attributes work with expressions/statements and not arbitrary syntactic fragments, so the choice in favor of the alternative 2 from https://github.com/rust-lang/rfcs/blob/master/text/0016-more-attributes.md#if is unlikely.
We also noted that while many users interpret code in a linear / textual fashion as opposed to as a tree-like structure, we still believe that the semantics of e.g.
#[allow(...)] if ...
is something that can be learned as necessary.
Based on this, let's:
@rfcbot merge