@@ -723,19 +723,20 @@ enum ReplaceOpt {
723
723
}
724
724
725
725
trait Merge {
726
- fn merge ( & mut self , other : Self , replace : ReplaceOpt ) ;
726
+ fn merge ( & mut self , extension_path : Option < PathBuf > , other : Self , replace : ReplaceOpt ) ;
727
727
}
728
728
729
729
impl Merge for TomlConfig {
730
730
fn merge (
731
731
& mut self ,
732
+ extension_path : Option < PathBuf > ,
732
733
TomlConfig { build, install, llvm, gcc, rust, dist, target, profile, change_id, include } : Self ,
733
734
replace : ReplaceOpt ,
734
735
) {
735
736
fn do_merge < T : Merge > ( x : & mut Option < T > , y : Option < T > , replace : ReplaceOpt ) {
736
737
if let Some ( new) = y {
737
738
if let Some ( original) = x {
738
- original. merge ( new, replace) ;
739
+ original. merge ( None , new, replace) ;
739
740
} else {
740
741
* x = Some ( new) ;
741
742
}
@@ -750,11 +751,20 @@ impl Merge for TomlConfig {
750
751
) ;
751
752
exit ! ( 2 ) ;
752
753
} ) ;
753
- self . merge ( included_toml, ReplaceOpt :: Override ) ;
754
+
755
+ if let Some ( extension_path) = & extension_path {
756
+ assert ! (
757
+ !included_toml. include. clone( ) . unwrap_or_default( ) . contains( extension_path) ,
758
+ "Recursive inclusion detected in extension: {}" ,
759
+ extension_path. display( )
760
+ ) ;
761
+ }
762
+
763
+ self . merge ( Some ( include_path) , included_toml, ReplaceOpt :: Override ) ;
754
764
}
755
765
756
- self . change_id . inner . merge ( change_id. inner , replace) ;
757
- self . profile . merge ( profile, replace) ;
766
+ self . change_id . inner . merge ( None , change_id. inner , replace) ;
767
+ self . profile . merge ( None , profile, replace) ;
758
768
759
769
do_merge ( & mut self . build , build, replace) ;
760
770
do_merge ( & mut self . install , install, replace) ;
@@ -769,7 +779,7 @@ impl Merge for TomlConfig {
769
779
( Some ( original_target) , Some ( new_target) ) => {
770
780
for ( triple, new) in new_target {
771
781
if let Some ( original) = original_target. get_mut ( & triple) {
772
- original. merge ( new, replace) ;
782
+ original. merge ( None , new, replace) ;
773
783
} else {
774
784
original_target. insert ( triple, new) ;
775
785
}
@@ -790,7 +800,7 @@ macro_rules! define_config {
790
800
}
791
801
792
802
impl Merge for $name {
793
- fn merge( & mut self , other: Self , replace: ReplaceOpt ) {
803
+ fn merge( & mut self , _extension_path : Option < PathBuf > , other: Self , replace: ReplaceOpt ) {
794
804
$(
795
805
match replace {
796
806
ReplaceOpt :: IgnoreDuplicate => {
@@ -890,7 +900,7 @@ macro_rules! define_config {
890
900
}
891
901
892
902
impl < T > Merge for Option < T > {
893
- fn merge ( & mut self , other : Self , replace : ReplaceOpt ) {
903
+ fn merge ( & mut self , _extension_path : Option < PathBuf > , other : Self , replace : ReplaceOpt ) {
894
904
match replace {
895
905
ReplaceOpt :: IgnoreDuplicate => {
896
906
if self . is_none ( ) {
@@ -1585,7 +1595,7 @@ impl Config {
1585
1595
) ;
1586
1596
exit ! ( 2 ) ;
1587
1597
} ) ;
1588
- toml. merge ( included_toml, ReplaceOpt :: IgnoreDuplicate ) ;
1598
+ toml. merge ( None , included_toml, ReplaceOpt :: IgnoreDuplicate ) ;
1589
1599
}
1590
1600
1591
1601
for include_path in toml. include . clone ( ) . unwrap_or_default ( ) {
@@ -1596,7 +1606,7 @@ impl Config {
1596
1606
) ;
1597
1607
exit ! ( 2 ) ;
1598
1608
} ) ;
1599
- toml. merge ( included_toml, ReplaceOpt :: Override ) ;
1609
+ toml. merge ( Some ( include_path ) , included_toml, ReplaceOpt :: Override ) ;
1600
1610
}
1601
1611
1602
1612
let mut override_toml = TomlConfig :: default ( ) ;
@@ -1607,7 +1617,7 @@ impl Config {
1607
1617
1608
1618
let mut err = match get_table ( option) {
1609
1619
Ok ( v) => {
1610
- override_toml. merge ( v, ReplaceOpt :: ErrorOnDuplicate ) ;
1620
+ override_toml. merge ( None , v, ReplaceOpt :: ErrorOnDuplicate ) ;
1611
1621
continue ;
1612
1622
}
1613
1623
Err ( e) => e,
@@ -1618,7 +1628,7 @@ impl Config {
1618
1628
if !value. contains ( '"' ) {
1619
1629
match get_table ( & format ! ( r#"{key}="{value}""# ) ) {
1620
1630
Ok ( v) => {
1621
- override_toml. merge ( v, ReplaceOpt :: ErrorOnDuplicate ) ;
1631
+ override_toml. merge ( None , v, ReplaceOpt :: ErrorOnDuplicate ) ;
1622
1632
continue ;
1623
1633
}
1624
1634
Err ( e) => err = e,
@@ -1628,7 +1638,7 @@ impl Config {
1628
1638
eprintln ! ( "failed to parse override `{option}`: `{err}" ) ;
1629
1639
exit ! ( 2 )
1630
1640
}
1631
- toml. merge ( override_toml, ReplaceOpt :: Override ) ;
1641
+ toml. merge ( None , override_toml, ReplaceOpt :: Override ) ;
1632
1642
1633
1643
config. change_id = toml. change_id . inner ;
1634
1644
0 commit comments