@@ -149,8 +149,10 @@ pub struct Config {
149149 offline : bool ,
150150 /// A global static IPC control mechanism (used for managing parallel builds)
151151 jobserver : Option < jobserver:: Client > ,
152- /// Cli flags of the form "-Z something"
152+ /// Cli flags of the form "-Z something" merged with config file values
153153 unstable_flags : CliUnstable ,
154+ /// Cli flags of the form "-Z something"
155+ unstable_flags_cli : Option < Vec < String > > ,
154156 /// A handle on curl easy mode for http calls
155157 easy : LazyCell < RefCell < Easy > > ,
156158 /// Cache of the `SourceId` for crates.io
@@ -231,6 +233,7 @@ impl Config {
231233 }
232234 } ,
233235 unstable_flags : CliUnstable :: default ( ) ,
236+ unstable_flags_cli : None ,
234237 easy : LazyCell :: new ( ) ,
235238 crates_io_source_id : LazyCell :: new ( ) ,
236239 cache_rustc_info,
@@ -427,6 +430,7 @@ impl Config {
427430 let values = self . load_values_from ( path. as_ref ( ) ) ?;
428431 self . values . replace ( values) ;
429432 self . merge_cli_args ( ) ?;
433+ self . load_unstable_flags_from_config ( ) ?;
430434 Ok ( ( ) )
431435 }
432436
@@ -703,6 +707,11 @@ impl Config {
703707 cli_config : & [ String ] ,
704708 ) -> CargoResult < ( ) > {
705709 self . unstable_flags . parse ( unstable_flags) ?;
710+ if !unstable_flags. is_empty ( ) {
711+ // store a copy of the cli flags separately for `load_unstable_flags_from_config`
712+ // (we might also need it again for `reload_rooted_at`)
713+ self . unstable_flags_cli = Some ( unstable_flags. to_vec ( ) ) ;
714+ }
706715 if !cli_config. is_empty ( ) {
707716 self . unstable_flags . fail_if_stable_opt ( "--config" , 6699 ) ?;
708717 self . cli_config = Some ( cli_config. iter ( ) . map ( |s| s. to_string ( ) ) . collect ( ) ) ;
@@ -756,17 +765,25 @@ impl Config {
756765 . unwrap_or ( false ) ;
757766 self . target_dir = cli_target_dir;
758767
768+ self . load_unstable_flags_from_config ( ) ?;
769+
770+ Ok ( ( ) )
771+ }
772+
773+ fn load_unstable_flags_from_config ( & mut self ) -> CargoResult < ( ) > {
759774 // If nightly features are enabled, allow setting Z-flags from config
760775 // using the `unstable` table. Ignore that block otherwise.
761776 if nightly_features_allowed ( ) {
762- if let Some ( unstable_flags) = self . get :: < Option < CliUnstable > > ( "unstable" ) ? {
763- self . unstable_flags = unstable_flags;
777+ self . unstable_flags = self
778+ . get :: < Option < CliUnstable > > ( "unstable" ) ?
779+ . unwrap_or_default ( ) ;
780+ if let Some ( unstable_flags_cli) = & self . unstable_flags_cli {
781+ // NB. It's not ideal to parse these twice, but doing it again here
782+ // allows the CLI to override config files for both enabling
783+ // and disabling, and doing it up top allows CLI Zflags to
784+ // control config parsing behavior.
785+ self . unstable_flags . parse ( unstable_flags_cli) ?;
764786 }
765- // NB. It's not ideal to parse these twice, but doing it again here
766- // allows the CLI to override config files for both enabling
767- // and disabling, and doing it up top allows CLI Zflags to
768- // control config parsing behavior.
769- self . unstable_flags . parse ( unstable_flags) ?;
770787 }
771788
772789 Ok ( ( ) )
0 commit comments