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

Mistake on where attributes are allowed in StructExpr and more #1021

Closed
YizhePKU opened this issue May 9, 2021 · 2 comments · Fixed by #1051
Closed

Mistake on where attributes are allowed in StructExpr and more #1021

YizhePKU opened this issue May 9, 2021 · 2 comments · Fixed by #1051

Comments

@YizhePKU
Copy link

YizhePKU commented May 9, 2021

According to the reference, only inner attributes are allowed in an StructExpr:

StructExprStruct :
   PathInExpression { InnerAttribute* (StructExprFields | StructBase)? }

However, this seems not to be the behaviour of rustc. rustc instead accepts only outer attributes for each field, but not inner attributes for the entire expression.

For example, this compiles in rustc:

struct S { x: i64, y: i64 }
fn main() {
    let s =  S { x: 1, #[deprecated] y: 2};
}

But not this:

struct S { x: i64, y: i64 }
fn main() {
    let s =  S { #![deprecated] x: 1, y: 2};
}
@YizhePKU
Copy link
Author

YizhePKU commented May 9, 2021

Same issue goes to TupleExpr and ArrayExpr.

@YizhePKU YizhePKU changed the title Mistake on where attributes are allowed in StructExpr Mistake on where attributes are allowed in StructExpr and TupleExpr May 9, 2021
@YizhePKU YizhePKU changed the title Mistake on where attributes are allowed in StructExpr and TupleExpr Mistake on where attributes are allowed in StructExpr and more May 9, 2021
@ehuss
Copy link
Contributor

ehuss commented May 9, 2021

They were accepted syntactically, but that was recently removed in nightly in rust-lang/rust#83312. There is discussion in rust-lang/rust#84879 about reverting that change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants