Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lukas-code opened this issue Mar 3, 2020 · 3 comments
Closed
Labels
A-parser Area: The parsing of Rust source code to an AST.

Comments

@lukas-code
Copy link
Member

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
@lukas-code lukas-code added the C-bug Category: This is a bug. label Mar 3, 2020
@LeSeulArtichaut
Copy link
Contributor

@rustbot modify labels: A-parser

@rustbot rustbot added the A-parser Area: The parsing of Rust source code to an AST. label Mar 3, 2020
@ehuss
Copy link
Contributor

ehuss commented Mar 3, 2020

I believe this is working as expected. Attributes can be applied to blocks as statements, but not as expressions. In some cases, attributes can be used in expressions, but those were accidentally stabilized in #36995, and nobody noticed for a long time. The current stable rules are detailed in https://doc.rust-lang.org/reference/expressions/block-expr.html#attributes-on-block-expressions. Stabilization in other expression positions is tracked in the linked issue (#15701).

@Centril Centril removed the C-bug Category: This is a bug. label Mar 3, 2020
@Centril
Copy link
Contributor

Centril commented Mar 3, 2020

@ehuss's summary is accurate. Closing as not-a-bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The parsing of Rust source code to an AST.
Projects
None yet
Development

No branches or pull requests

5 participants