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

#[cfg] attribute is not handled properly on struct fields #2983

Open
CohenArthur opened this issue May 13, 2024 · 0 comments
Open

#[cfg] attribute is not handled properly on struct fields #2983

CohenArthur opened this issue May 13, 2024 · 0 comments
Labels

Comments

@CohenArthur
Copy link
Member

pub struct ReadDir {
    pub inner: i32,
    #[cfg(not(A))]
    pub end_of_stream: bool,
    #[cfg(A)]
    pub end_of_stream_but_different: bool,
}

fn main() {
    let _ = ReadDir {
        inner: 14,
        end_of_stream: false,
        end_of_stream_but_different: false,
    };
}

slightly modified version of an exemple from std 1.49. This code should error out in all cases as both cfg directives are contradictory, so at least one field should be nonexistent in the instantiation. rustc outputs the following with no particular cfg command line options:

error[E0560]: struct `ReadDir` has no field named `end_of_stream_but_different`
  --> test.rs:13:9
   |
13 |         end_of_stream_but_different: false,
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ReadDir` does not have this field
   |
   = note: all struct fields are already assigned

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0560`.

but gccrs compiles the file happily

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

No branches or pull requests

1 participant