diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-24 03:56:26 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-24 03:57:46 +0900 |
| commit | f1af14b1cc503ac20f56a79a96c7780d02bdfe75 (patch) | |
| tree | 3f8661e1dc4d2092ac16b45c574c90ec2d8bec2a /crates/shirabe/src/command/package_discovery_trait.rs | |
| parent | c5fc34a106a706ac12925c4df273a926811d260b (diff) | |
| download | php-shirabe-f1af14b1cc503ac20f56a79a96c7780d02bdfe75.tar.gz php-shirabe-f1af14b1cc503ac20f56a79a96c7780d02bdfe75.tar.zst php-shirabe-f1af14b1cc503ac20f56a79a96c7780d02bdfe75.zip | |
fix(console): make Command/BaseCommand methods take &self
The Command trait and Composer's BaseCommand took &mut self, so dispatch
held a borrow_mut on the command's RefCell for the whole call. A command
re-entering itself (e.g. the help command describing itself) then panicked
with "RefCell already borrowed".
All Command/BaseCommand methods now take &self and the command state is
interior-mutable (Cell/RefCell). Shared borrows coexist, so re-entrant
describe paths no longer conflict. Getters that returned references now
return Ref guards; the descriptor describe_* methods take &dyn Command;
mixin accessors return Ref/RefMut.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/command/package_discovery_trait.rs')
| -rw-r--r-- | crates/shirabe/src/command/package_discovery_trait.rs | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/crates/shirabe/src/command/package_discovery_trait.rs b/crates/shirabe/src/command/package_discovery_trait.rs index 9be30f5..943eeaf 100644 --- a/crates/shirabe/src/command/package_discovery_trait.rs +++ b/crates/shirabe/src/command/package_discovery_trait.rs @@ -37,12 +37,14 @@ use crate::util::Filesystem; pub trait PackageDiscoveryTrait: BaseCommand { // PHP: private $repos; private $repositorySets; // TODO(phase-b): trait fields require an associated state struct in Rust; expose via accessors - fn get_repos_mut(&mut self) -> &mut Option<crate::repository::RepositoryInterfaceHandle>; + fn get_repos_mut( + &self, + ) -> std::cell::RefMut<'_, Option<crate::repository::RepositoryInterfaceHandle>>; fn get_repository_sets_mut( - &mut self, - ) -> &mut IndexMap<String, std::rc::Rc<std::cell::RefCell<RepositorySet>>>; + &self, + ) -> std::cell::RefMut<'_, IndexMap<String, std::rc::Rc<std::cell::RefCell<RepositorySet>>>>; - fn get_repos(&mut self) -> crate::repository::RepositoryInterfaceHandle { + fn get_repos(&self) -> crate::repository::RepositoryInterfaceHandle { if self.get_repos_mut().is_none() { // PHP: array_merge([new PlatformRepository], RepositoryFactory::defaultReposWithDefaultManager($this->getIO())) let mut repos: Vec<crate::repository::RepositoryInterfaceHandle> = @@ -67,7 +69,7 @@ pub trait PackageDiscoveryTrait: BaseCommand { /// @param key-of<BasePackage::STABILITIES>|null $minimumStability fn get_repository_set( - &mut self, + &self, input: std::rc::Rc<std::cell::RefCell<dyn InputInterface>>, minimum_stability: Option<&str>, ) -> std::rc::Rc<std::cell::RefCell<RepositorySet>> { @@ -134,7 +136,7 @@ pub trait PackageDiscoveryTrait: BaseCommand { #[allow(clippy::too_many_arguments, reason = "to keep PHP signature")] fn determine_requirements( - &mut self, + &self, input: std::rc::Rc<std::cell::RefCell<dyn InputInterface>>, _output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>, mut requires: Vec<String>, @@ -463,7 +465,7 @@ pub trait PackageDiscoveryTrait: BaseCommand { /// @throws \InvalidArgumentException /// @return array{string, string} name version fn find_best_version_and_name_for_package( - &mut self, + &self, io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, input: std::rc::Rc<std::cell::RefCell<dyn InputInterface>>, name: &str, @@ -759,7 +761,7 @@ pub trait PackageDiscoveryTrait: BaseCommand { } /// @return array<string> - fn find_similar(&mut self, package: &str) -> Result<Vec<String>> { + fn find_similar(&self, package: &str) -> Result<Vec<String>> { let results: Vec<SearchResult> = match (|| -> Result<Vec<SearchResult>> { if self.get_repos_mut().is_none() { return Err(LogicException { |
