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.
1
4
//@ run-pass
2
5
//@ aux-build:struct_field_default.rs
3
6
#![ feature( const_trait_impl, default_field_values, generic_const_exprs) ]
@@ -7,12 +10,14 @@ extern crate struct_field_default as xc;
7
10
8
11
pub struct S ;
9
12
13
+ // Basic expressions and `Default` expansion
10
14
#[ derive( Default ) ]
11
15
pub struct Foo {
12
16
pub bar : S = S ,
13
17
pub baz : i32 = 42 + 3 ,
14
18
}
15
19
20
+ // Enum support for deriving `Default` when all fields have default values
16
21
#[ derive( Default ) ]
17
22
pub enum Bar {
18
23
#[ default]
@@ -33,13 +38,13 @@ impl const ConstDefault for i32 {
33
38
}
34
39
35
40
pub 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
43
48
}
44
49
45
50
impl < A , const C : i32 , X : const ConstDefault > Qux < A , C , X > {
0 commit comments