@@ -745,19 +745,20 @@ enum ReplaceOpt {
745
745
}
746
746
747
747
trait Merge {
748
- fn merge ( & mut self , other : Self , replace : ReplaceOpt ) ;
748
+ fn merge ( & mut self , extension_path : Option < PathBuf > , other : Self , replace : ReplaceOpt ) ;
749
749
}
750
750
751
751
impl Merge for TomlConfig {
752
752
fn merge (
753
753
& mut self ,
754
+ extension_path : Option < PathBuf > ,
754
755
TomlConfig { build, install, llvm, gcc, rust, dist, target, profile, change_id, include } : Self ,
755
756
replace : ReplaceOpt ,
756
757
) {
757
758
fn do_merge < T : Merge > ( x : & mut Option < T > , y : Option < T > , replace : ReplaceOpt ) {
758
759
if let Some ( new) = y {
759
760
if let Some ( original) = x {
760
- original. merge ( new, replace) ;
761
+ original. merge ( None , new, replace) ;
761
762
} else {
762
763
* x = Some ( new) ;
763
764
}
@@ -772,11 +773,20 @@ impl Merge for TomlConfig {
772
773
) ;
773
774
exit ! ( 2 ) ;
774
775
} ) ;
775
- self . merge ( included_toml, ReplaceOpt :: Override ) ;
776
+
777
+ if let Some ( extension_path) = & extension_path {
778
+ assert ! (
779
+ !included_toml. include. clone( ) . unwrap_or_default( ) . contains( extension_path) ,
780
+ "Recursive inclusion detected in extension: {}" ,
781
+ extension_path. display( )
782
+ ) ;
783
+ }
784
+
785
+ self . merge ( Some ( include_path) , included_toml, ReplaceOpt :: Override ) ;
776
786
}
777
787
778
- self . change_id . inner . merge ( change_id. inner , replace) ;
779
- self . profile . merge ( profile, replace) ;
788
+ self . change_id . inner . merge ( None , change_id. inner , replace) ;
789
+ self . profile . merge ( None , profile, replace) ;
780
790
781
791
do_merge ( & mut self . build , build, replace) ;
782
792
do_merge ( & mut self . install , install, replace) ;
@@ -791,7 +801,7 @@ impl Merge for TomlConfig {
791
801
( Some ( original_target) , Some ( new_target) ) => {
792
802
for ( triple, new) in new_target {
793
803
if let Some ( original) = original_target. get_mut ( & triple) {
794
- original. merge ( new, replace) ;
804
+ original. merge ( None , new, replace) ;
795
805
} else {
796
806
original_target. insert ( triple, new) ;
797
807
}
@@ -812,7 +822,7 @@ macro_rules! define_config {
812
822
}
813
823
814
824
impl Merge for $name {
815
- fn merge( & mut self , other: Self , replace: ReplaceOpt ) {
825
+ fn merge( & mut self , _extension_path : Option < PathBuf > , other: Self , replace: ReplaceOpt ) {
816
826
$(
817
827
match replace {
818
828
ReplaceOpt :: IgnoreDuplicate => {
@@ -912,7 +922,7 @@ macro_rules! define_config {
912
922
}
913
923
914
924
impl < T > Merge for Option < T > {
915
- fn merge ( & mut self , other : Self , replace : ReplaceOpt ) {
925
+ fn merge ( & mut self , _extension_path : Option < PathBuf > , other : Self , replace : ReplaceOpt ) {
916
926
match replace {
917
927
ReplaceOpt :: IgnoreDuplicate => {
918
928
if self . is_none ( ) {
@@ -1608,7 +1618,7 @@ impl Config {
1608
1618
) ;
1609
1619
exit ! ( 2 ) ;
1610
1620
} ) ;
1611
- toml. merge ( included_toml, ReplaceOpt :: IgnoreDuplicate ) ;
1621
+ toml. merge ( None , included_toml, ReplaceOpt :: IgnoreDuplicate ) ;
1612
1622
}
1613
1623
1614
1624
for include_path in toml. include . clone ( ) . unwrap_or_default ( ) {
@@ -1619,7 +1629,7 @@ impl Config {
1619
1629
) ;
1620
1630
exit ! ( 2 ) ;
1621
1631
} ) ;
1622
- toml. merge ( included_toml, ReplaceOpt :: Override ) ;
1632
+ toml. merge ( Some ( include_path ) , included_toml, ReplaceOpt :: Override ) ;
1623
1633
}
1624
1634
1625
1635
let mut override_toml = TomlConfig :: default ( ) ;
@@ -1630,7 +1640,7 @@ impl Config {
1630
1640
1631
1641
let mut err = match get_table ( option) {
1632
1642
Ok ( v) => {
1633
- override_toml. merge ( v, ReplaceOpt :: ErrorOnDuplicate ) ;
1643
+ override_toml. merge ( None , v, ReplaceOpt :: ErrorOnDuplicate ) ;
1634
1644
continue ;
1635
1645
}
1636
1646
Err ( e) => e,
@@ -1641,7 +1651,7 @@ impl Config {
1641
1651
if !value. contains ( '"' ) {
1642
1652
match get_table ( & format ! ( r#"{key}="{value}""# ) ) {
1643
1653
Ok ( v) => {
1644
- override_toml. merge ( v, ReplaceOpt :: ErrorOnDuplicate ) ;
1654
+ override_toml. merge ( None , v, ReplaceOpt :: ErrorOnDuplicate ) ;
1645
1655
continue ;
1646
1656
}
1647
1657
Err ( e) => err = e,
@@ -1651,7 +1661,7 @@ impl Config {
1651
1661
eprintln ! ( "failed to parse override `{option}`: `{err}" ) ;
1652
1662
exit ! ( 2 )
1653
1663
}
1654
- toml. merge ( override_toml, ReplaceOpt :: Override ) ;
1664
+ toml. merge ( None , override_toml, ReplaceOpt :: Override ) ;
1655
1665
1656
1666
config. change_id = toml. change_id . inner ;
1657
1667
0 commit comments