diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-07-20 07:09:41 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-07-20 07:28:42 +0900 |
| commit | 632ed8528c3566d67dda2804beb6d9e4e9511a72 (patch) | |
| tree | c11d3972666a6394eef79d679efe64cdb7e9eb4c /crates/shirabe | |
| parent | 63a77b1495944ad9707fe036a73f99eaec189897 (diff) | |
| download | php-shirabe-632ed8528c3566d67dda2804beb6d9e4e9511a72.tar.gz php-shirabe-632ed8528c3566d67dda2804beb6d9e4e9511a72.tar.zst php-shirabe-632ed8528c3566d67dda2804beb6d9e4e9511a72.zip | |
fix(require-command): drop input borrows before determine_requirements
The Ref temporaries created by input.borrow() inside the argument
expressions of the determine_requirements call lived until the end of
the whole call statement, so ConsoleIO::ask_question's borrow_mut() on
the same shared input RefCell panicked with "RefCell already borrowed"
when the command prompted for packages. Hoist the argument computations
into locals so no borrow is held across the call, and un-ignore the
run_require CLI test.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe')
| -rw-r--r-- | crates/shirabe/src/command/require_command.rs | 48 | ||||
| -rw-r--r-- | crates/shirabe/src/lib.rs | 1 |
2 files changed, 27 insertions, 22 deletions
diff --git a/crates/shirabe/src/command/require_command.rs b/crates/shirabe/src/command/require_command.rs index 16bc73f0..05f86480 100644 --- a/crates/shirabe/src/command/require_command.rs +++ b/crates/shirabe/src/command/require_command.rs @@ -301,32 +301,38 @@ impl Command for RequireCommand { composer.get_package().get_minimum_stability().to_string() }; + // Hoist argument computations into locals so no borrow of `input` is held across the + // call: `determine_requirements` may prompt via ConsoleIO, which mutably borrows the + // same input RefCell. + let packages: Vec<String> = input + .borrow() + .get_argument("packages")? + .as_list() + .map(|l| { + l.iter() + .filter_map(|v| v.as_string().map(|s| s.to_string())) + .collect() + }) + .unwrap_or_default(); + // if there is no update, we need to use the best possible version constraint directly as we cannot rely on the solver to guess the best constraint + let no_update = input + .borrow() + .get_option("no-update")? + .as_bool() + .unwrap_or(false); + let fixed = input + .borrow() + .get_option("fixed")? + .as_bool() + .unwrap_or(false); let requirements_result = self.determine_requirements( input.clone(), output.clone(), - input - .borrow() - .get_argument("packages")? - .as_list() - .map(|l| { - l.iter() - .filter_map(|v| v.as_string().map(|s| s.to_string())) - .collect() - }) - .unwrap_or_default(), + packages, Some(&platform_repo), &preferred_stability, - // if there is no update, we need to use the best possible version constraint directly as we cannot rely on the solver to guess the best constraint - input - .borrow() - .get_option("no-update")? - .as_bool() - .unwrap_or(false), - input - .borrow() - .get_option("fixed")? - .as_bool() - .unwrap_or(false), + no_update, + fixed, ); let requirements = match requirements_result { diff --git a/crates/shirabe/src/lib.rs b/crates/shirabe/src/lib.rs index 2db47fcd..8d0a58bc 100644 --- a/crates/shirabe/src/lib.rs +++ b/crates/shirabe/src/lib.rs @@ -196,7 +196,6 @@ mod cli_tests { run_reinstall => "reinstall", run_remove => "remove", run_repository => "repository", - #[ignore = "currently panics"] run_require => "require", run_run_script => "run-script", run_search => "search", |
