1+ // Exercise the `default_field_values` feature to confirm it interacts correctly with other nightly
2+ // features. In particular, we want to verify that interaction with consts coming from different
3+ // contexts are usable as a default field value.
14//@ run-pass
25//@ aux-build:struct_field_default.rs
36#![ feature( const_trait_impl, default_field_values, generic_const_exprs) ]
@@ -7,12 +10,14 @@ extern crate struct_field_default as xc;
710
811pub struct S ;
912
13+ // Basic expressions and `Default` expansion
1014#[ derive( Default ) ]
1115pub struct Foo {
1216 pub bar : S = S ,
1317 pub baz : i32 = 42 + 3 ,
1418}
1519
20+ // Enum support for deriving `Default` when all fields have default values
1621#[ derive( Default ) ]
1722pub enum Bar {
1823 #[ default]
@@ -33,13 +38,13 @@ impl const ConstDefault for i32 {
3338}
3439
3540pub struct Qux < A , const C : i32 , X : const ConstDefault > {
36- bar : S = Qux :: < A , C , X > :: S ,
37- baz : i32 = foo ( ) ,
38- bat : i32 = <Qux < A , C , X > as T >:: K ,
39- baq : i32 = Self :: K ,
40- bay : i32 = C ,
41- bak : Vec < A > = Vec :: new ( ) ,
42- ban : X = X :: value ( ) ,
41+ bar : S = Qux :: < A , C , X > :: S , // Associated constant from inherent impl
42+ baz : i32 = foo ( ) , // Constant function
43+ bat : i32 = <Qux < A , C , X > as T >:: K , // Associated constant from explicit trait
44+ baq : i32 = Self :: K , // Associated constant from implicit trait
45+ bay : i32 = C , // `const` parameter
46+ bak : Vec < A > = Vec :: new ( ) , // Associated constant function
47+ ban : X = X :: value ( ) , // Associated constant function from `const` trait parameter
4348}
4449
4550impl < A , const C : i32 , X : const ConstDefault > Qux < A , C , X > {
0 commit comments