@@ -1454,7 +1454,6 @@ fn struct_with_overlapping_inner_struct_and_defaults() {
1454
1454
// If, in the future, we can handle this more correctly, feel free to delete
1455
1455
// this case.
1456
1456
#[ derive( Deserialize , Default ) ]
1457
- #[ serde( default ) ]
1458
1457
struct PrefixContainer {
1459
1458
inn : bool ,
1460
1459
inner : Inner ,
@@ -1466,7 +1465,7 @@ fn struct_with_overlapping_inner_struct_and_defaults() {
1466
1465
. get :: < PrefixContainer > ( "prefixcontainer" )
1467
1466
. err ( )
1468
1467
. unwrap ( ) ;
1469
- assert ! ( format!( "{}" , err) . contains( "missing config key `prefixcontainer. inn`" ) ) ;
1468
+ assert ! ( format!( "{}" , err) . contains( "missing field ` inn`" ) ) ;
1470
1469
let gctx = GlobalContextBuilder :: new ( )
1471
1470
. env ( "CARGO_PREFIXCONTAINER_INNER_VALUE" , "12" )
1472
1471
. env ( "CARGO_PREFIXCONTAINER_INN" , "true" )
@@ -1475,6 +1474,22 @@ fn struct_with_overlapping_inner_struct_and_defaults() {
1475
1474
assert_eq ! ( f. inner. value, 12 ) ;
1476
1475
assert_eq ! ( f. inn, true ) ;
1477
1476
1477
+ // Use default attribute of serde, then we can skip setting the inn field
1478
+ #[ derive( Deserialize , Default ) ]
1479
+ #[ serde( default ) ]
1480
+ struct PrefixContainerFieldDefault {
1481
+ inn : bool ,
1482
+ inner : Inner ,
1483
+ }
1484
+ let gctx = GlobalContextBuilder :: new ( )
1485
+ . env ( "CARGO_PREFIXCONTAINER_INNER_VALUE" , "12" )
1486
+ . build ( ) ;
1487
+ let f = gctx
1488
+ . get :: < PrefixContainerFieldDefault > ( "prefixcontainer" )
1489
+ . unwrap ( ) ;
1490
+ assert_eq ! ( f. inner. value, 12 ) ;
1491
+ assert_eq ! ( f. inn, false ) ;
1492
+
1478
1493
// Containing struct where the inner value's field is a prefix of another
1479
1494
//
1480
1495
// This is a limitation of mapping environment variables on to a hierarchy.
0 commit comments