@@ -723,19 +723,20 @@ enum ReplaceOpt {
723723}
724724
725725trait Merge {
726- fn merge ( & mut self , other : Self , replace : ReplaceOpt ) ;
726+ fn merge ( & mut self , extension_path : Option < PathBuf > , other : Self , replace : ReplaceOpt ) ;
727727}
728728
729729impl Merge for TomlConfig {
730730 fn merge (
731731 & mut self ,
732+ extension_path : Option < PathBuf > ,
732733 TomlConfig { build, install, llvm, gcc, rust, dist, target, profile, change_id, include } : Self ,
733734 replace : ReplaceOpt ,
734735 ) {
735736 fn do_merge < T : Merge > ( x : & mut Option < T > , y : Option < T > , replace : ReplaceOpt ) {
736737 if let Some ( new) = y {
737738 if let Some ( original) = x {
738- original. merge ( new, replace) ;
739+ original. merge ( None , new, replace) ;
739740 } else {
740741 * x = Some ( new) ;
741742 }
@@ -750,11 +751,20 @@ impl Merge for TomlConfig {
750751 ) ;
751752 exit ! ( 2 ) ;
752753 } ) ;
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 ) ;
754764 }
755765
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) ;
758768
759769 do_merge ( & mut self . build , build, replace) ;
760770 do_merge ( & mut self . install , install, replace) ;
@@ -769,7 +779,7 @@ impl Merge for TomlConfig {
769779 ( Some ( original_target) , Some ( new_target) ) => {
770780 for ( triple, new) in new_target {
771781 if let Some ( original) = original_target. get_mut ( & triple) {
772- original. merge ( new, replace) ;
782+ original. merge ( None , new, replace) ;
773783 } else {
774784 original_target. insert ( triple, new) ;
775785 }
@@ -790,7 +800,7 @@ macro_rules! define_config {
790800 }
791801
792802 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 ) {
794804 $(
795805 match replace {
796806 ReplaceOpt :: IgnoreDuplicate => {
@@ -890,7 +900,7 @@ macro_rules! define_config {
890900}
891901
892902impl < 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 ) {
894904 match replace {
895905 ReplaceOpt :: IgnoreDuplicate => {
896906 if self . is_none ( ) {
@@ -1585,7 +1595,7 @@ impl Config {
15851595 ) ;
15861596 exit ! ( 2 ) ;
15871597 } ) ;
1588- toml. merge ( included_toml, ReplaceOpt :: IgnoreDuplicate ) ;
1598+ toml. merge ( None , included_toml, ReplaceOpt :: IgnoreDuplicate ) ;
15891599 }
15901600
15911601 for include_path in toml. include . clone ( ) . unwrap_or_default ( ) {
@@ -1596,7 +1606,7 @@ impl Config {
15961606 ) ;
15971607 exit ! ( 2 ) ;
15981608 } ) ;
1599- toml. merge ( included_toml, ReplaceOpt :: Override ) ;
1609+ toml. merge ( Some ( include_path ) , included_toml, ReplaceOpt :: Override ) ;
16001610 }
16011611
16021612 let mut override_toml = TomlConfig :: default ( ) ;
@@ -1607,7 +1617,7 @@ impl Config {
16071617
16081618 let mut err = match get_table ( option) {
16091619 Ok ( v) => {
1610- override_toml. merge ( v, ReplaceOpt :: ErrorOnDuplicate ) ;
1620+ override_toml. merge ( None , v, ReplaceOpt :: ErrorOnDuplicate ) ;
16111621 continue ;
16121622 }
16131623 Err ( e) => e,
@@ -1618,7 +1628,7 @@ impl Config {
16181628 if !value. contains ( '"' ) {
16191629 match get_table ( & format ! ( r#"{key}="{value}""# ) ) {
16201630 Ok ( v) => {
1621- override_toml. merge ( v, ReplaceOpt :: ErrorOnDuplicate ) ;
1631+ override_toml. merge ( None , v, ReplaceOpt :: ErrorOnDuplicate ) ;
16221632 continue ;
16231633 }
16241634 Err ( e) => err = e,
@@ -1628,7 +1638,7 @@ impl Config {
16281638 eprintln ! ( "failed to parse override `{option}`: `{err}" ) ;
16291639 exit ! ( 2 )
16301640 }
1631- toml. merge ( override_toml, ReplaceOpt :: Override ) ;
1641+ toml. merge ( None , override_toml, ReplaceOpt :: Override ) ;
16321642
16331643 config. change_id = toml. change_id . inner ;
16341644
0 commit comments