mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
974ccc12e6
Introduce `default_field_values` feature Initial implementation of `#[feature(default_field_values]`, proposed in https://github.com/rust-lang/rfcs/pull/3681. We now parse const expressions after a `=` in a field definition, to specify a `struct` field default value. We now allow `Struct { field, .. }` where there's no base after `..`. `#[derive(Default)]` now uses the default value if present, continuing to use `Default::default()` if not. ```rust #[derive(Debug)] pub struct S; #[derive(Debug, Default)] pub struct Foo { pub bar: S = S, pub baz: i32 = 42 + 3, } fn main () { let x = Foo { .. }; let y = Foo::default(); let z = Foo { baz: 1, .. }; assert_eq!(45, x.baz); assert_eq!(45, y.baz); assert_eq!(1, z.baz); } ```