Skip to content

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

Closed
@yizhepku

Description

@yizhepku

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};
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions