Skip to content

Commit d6b5b53

Browse files
committed
Auto merge of #8656 - phil-opp:fix-8512, r=ehuss
Reload unstable table from config file in `reload_rooted_at` Fixes #8512 cc @ehuss
2 parents 6585cda + c5d8dcb commit d6b5b53

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

src/cargo/util/config/mod.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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(())

tests/testsuite/install.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,25 @@ fn install_ignores_local_cargo_config() {
14331433
assert_has_installed_exe(cargo_home(), "bar");
14341434
}
14351435

1436+
#[cargo_test]
1437+
fn install_ignores_unstable_table_in_local_cargo_config() {
1438+
pkg("bar", "0.0.1");
1439+
1440+
let p = project()
1441+
.file(
1442+
".cargo/config",
1443+
r#"
1444+
[unstable]
1445+
build-std = ["core"]
1446+
"#,
1447+
)
1448+
.file("src/main.rs", "fn main() {}")
1449+
.build();
1450+
1451+
p.cargo("install bar").masquerade_as_nightly_cargo().run();
1452+
assert_has_installed_exe(cargo_home(), "bar");
1453+
}
1454+
14361455
#[cargo_test]
14371456
fn install_global_cargo_config() {
14381457
pkg("bar", "0.0.1");

0 commit comments

Comments
 (0)