Skip to content

#[cfg] on struct field permits empty unusable struct #16819

Description

@klutzy
struct S {
    #[cfg(untrue)]
    a: int,
}

fn main() {
    let s = S;
}
<anon>:7:13: 7:14 error: `S` is a structure name, but this expression uses it like a function name
<anon>:7     let s = S;
                     ^
<anon>:7:13: 7:14 note: Did you mean to write: `S { /* fields */ }`?
<anon>:7     let s = S;
                     ^

Here S { } is suggested but it is also not allowed:

<anon>:7:14: 7:15 error: structure literal must either have at least one field or use functional structure update syntax
<anon>:7     let s = S{};
                      ^

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-grammarArea: The grammar of Rust

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions