rust/tests/ui/structs/default-field-values-non_exhaustive.rs
Esteban Küber b3cc9b9620 Restrict #[non_exaustive] on structs with default field values
Do not allow users to apply `#[non_exaustive]` to a struct when they have also used default field values.
2024-12-20 17:18:54 +00:00

19 lines
367 B
Rust

#![feature(default_field_values)]
#[derive(Default)]
#[non_exhaustive] //~ ERROR `#[non_exhaustive]` can't be used to annotate items with default field values
struct Foo {
x: i32 = 42 + 3,
}
#[derive(Default)]
enum Bar {
#[non_exhaustive]
#[default]
Baz { //~ ERROR default variant must be exhaustive
x: i32 = 42 + 3,
}
}
fn main () {}