Skip to content

Inner attributes on block expressions on match arms are not allowed #69675

Closed
@lukas-code

Description

@lukas-code

I tried this code:

fn main() {
    match 0 {
        _ => {
            #![allow(unused_variables)]
        }
    }
}

I expected to see this happen: The code compiles.

Instead, this happened: The code fails to compile with the following error:

error[E0658]: attributes on expressions are experimental
 --> test.rs:4:13
  |
4 |             #![allow(unused_variables)]
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
  = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable

error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.

The following code compiles as expected:

fn main() {
    match 0 {
        _ => {{ // <-- double braces
            #![allow(unused_variables)]
        }}
    }
}

Meta

rustc --version --verbose:

binary: rustc
commit-hash: d3c79346a3e7ddbb5fb417810f226ac5a9209007
commit-date: 2020-02-29
host: x86_64-unknown-linux-gnu
release: 1.43.0-nightly
LLVM version: 9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-parserArea: The lexing & parsing of Rust source code to an AST

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions