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

Inconsistent "attributes on expressions are experimental" error #59144

Closed
joshlf opened this issue Mar 12, 2019 · 4 comments
Closed

Inconsistent "attributes on expressions are experimental" error #59144

joshlf opened this issue Mar 12, 2019 · 4 comments
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-stability Area: `#[stable]`, `#[unstable]` etc.

Comments

@joshlf
Copy link
Contributor

joshlf commented Mar 12, 2019

Given the following code:

fn main() {
    #[allow(unused)]
    let mut x = 1;
    
    #[allow(unused)]
    x = 1;
}

There's an error generated about the x = 1; line, but not the let mut x = 1; line. I would expect that either a) neither of these are errors (since they're both statements, not expressions) or, b) both of these are errors.

(cc @cramertj )

@jonas-schievink jonas-schievink added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-stability Area: `#[stable]`, `#[unstable]` etc. labels Mar 12, 2019
@ehuss
Copy link
Contributor

ehuss commented Mar 12, 2019

I suspect the attribute is binding tightly to the place expression, instead of the entire statement. Attributes on statements are stable, but attributes on expressions are limited. This is partially documented here: https://doc.rust-lang.org/nightly/reference/expressions.html#expression-attributes. I'm curious if that precedence is intended. It makes sense to me, but I see how it is confusing. A work around is to wrap the assignment expression in {} or ().

@Centril
Copy link
Contributor

Centril commented Mar 13, 2019

cc #15701

@ehuss
Copy link
Contributor

ehuss commented Mar 13, 2019

Oh, I didn't see that the RFC specifies "Attributes bind tighter than any operator", so it is intended.

@Enselic
Copy link
Member

Enselic commented Nov 24, 2023

so it is intended.

Triage: Closing as works as designed.

@Enselic Enselic closed this as not planned Won't fix, can't repro, duplicate, stale Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-stability Area: `#[stable]`, `#[unstable]` etc.
Projects
None yet
Development

No branches or pull requests

5 participants