]> git.lizzy.rs Git - rust.git/commit - src/tools/clippy
Rollup merge of #69201 - Aaron1011:feature/permit-if-attr, r=Centril
authorMazdak Farrokhzad <twingoow@gmail.com>
Mon, 9 Mar 2020 11:57:44 +0000 (12:57 +0100)
committerGitHub <noreply@github.com>
Mon, 9 Mar 2020 11:57:44 +0000 (12:57 +0100)
commit4ec997503c94913af44e7f9ec8a75a21c45b7bac
tree116ba3c94f542cf5860f1b7fb38689eca96742ed
parent2cb0b8582ebbf9784db9cec06fff517badbf4553
parente50fd5a3dc587b5b970b6b969eff7e8547dede70
Rollup merge of #69201 - Aaron1011:feature/permit-if-attr, r=Centril

Permit attributes on 'if' expressions

Previously, attributes on 'if' expressions (e.g. `#[attr] if true {}`)
were disallowed during parsing. This made it impossible for macros to
perform any custom handling of such attributes (e.g. stripping them
away), since a compilation error would be emitted before they ever had a
chance to run.

This PR permits attributes on 'if' expressions ('if-attrs' from here on).
Both built-in attributes (e.g. `#[allow]`, `#[cfg]`) and proc-macro attributes are supported.

We still do *not* accept attributes on 'other parts' of an if-else
chain. That is, the following code snippet still fails to parse:

```rust
if true {} #[attr] else if false {} else #[attr] if false {} #[attr]
else {}
```

Closes https://github.com/rust-lang/rust/issues/68618
src/librustc_parse/parser/expr.rs
src/test/ui/parser/attr-stmt-expr-attr-bad.stderr