Skip to content

Commit f707c78

Browse files
committed
revert rust-lang#11080 and assert precondition for --directory flag
1 parent b5a19b3 commit f707c78

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/bin/cargo/cli.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ pub fn main(config: &mut LazyConfig) -> CliResult {
2828
let args = cli().try_get_matches()?;
2929

3030
// Update the process-level notion of cwd
31+
// This must be completed before config is initialized
32+
assert_eq!(config.is_init(), false);
3133
if let Some(new_cwd) = args.get_one::<std::path::PathBuf>("directory") {
3234
std::env::set_current_dir(&new_cwd).context("could not change to requested directory")?;
3335
}
@@ -509,6 +511,13 @@ impl LazyConfig {
509511
Self { config: None }
510512
}
511513

514+
/// Check whether the config is loaded
515+
///
516+
/// This is useful for asserts in case the environment needs to be setup before loading
517+
pub fn is_init(&self) -> bool {
518+
self.config.is_some()
519+
}
520+
512521
/// Get the config, loading it if needed
513522
///
514523
/// On error, the process is terminated

0 commit comments

Comments
 (0)