From 1fe1cd3fe9da3f34d8529a0c4cc89fdc61af5065 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 17 May 2026 17:44:03 +0900 Subject: fix(compile): add dyn keyword to all trait object usages (E0782) Co-Authored-By: Claude Sonnet 4.6 --- crates/shirabe/src/repository/array_repository.rs | 26 +++++------ .../shirabe/src/repository/artifact_repository.rs | 5 ++- .../shirabe/src/repository/composer_repository.rs | 50 +++++++++++----------- .../shirabe/src/repository/composite_repository.rs | 6 +-- crates/shirabe/src/repository/filter_repository.rs | 6 +-- .../shirabe/src/repository/installed_repository.rs | 12 +++--- .../shirabe/src/repository/repository_interface.rs | 8 ++-- crates/shirabe/src/repository/repository_set.rs | 12 +++--- crates/shirabe/src/repository/vcs_repository.rs | 2 +- 9 files changed, 65 insertions(+), 62 deletions(-) (limited to 'crates/shirabe/src/repository') diff --git a/crates/shirabe/src/repository/array_repository.rs b/crates/shirabe/src/repository/array_repository.rs index 7bb7e81..5262b5e 100644 --- a/crates/shirabe/src/repository/array_repository.rs +++ b/crates/shirabe/src/repository/array_repository.rs @@ -31,10 +31,10 @@ use crate::repository::repository_interface::{ pub struct ArrayRepository { /// @var ?array // TODO(phase-b): RefCell models PHP's lazy init via getPackages()/count() under &self - pub(crate) packages: RefCell>>>, + pub(crate) packages: RefCell>>>, /// @var ?array indexed by package unique name and used to cache hasPackage calls - pub(crate) package_map: RefCell>>>, + pub(crate) package_map: RefCell>>>, } impl ArrayRepository { @@ -63,9 +63,9 @@ impl ArrayRepository { } .into()); } - // TODO(phase-b): convert Box to Box - let mut package: Box = - todo!("downcast Box to Box"); + // TODO(phase-b): convert Box to Box + let mut package: Box = + todo!("downcast Box to Box"); if self.packages.borrow().is_none() { self.initialize(); @@ -73,7 +73,7 @@ impl ArrayRepository { // TODO(phase-b): pass a reference to self, not a clone package.set_repository(todo!("self as Box"))?; - let aliased_package: Option> = + let aliased_package: Option> = if let Some(alias) = (package.as_any() as &dyn Any).downcast_ref::() { Some(alias.get_alias_of().clone_box()) } else { @@ -97,10 +97,10 @@ impl ArrayRepository { /// @return AliasPackage|CompleteAliasPackage pub(crate) fn create_alias_package( &self, - mut package: Box, + mut package: Box, alias: String, pretty_alias: String, - ) -> Box { + ) -> Box { while let Some(alias_pkg) = (package.as_any() as &dyn Any).downcast_ref::() { package = alias_pkg.get_alias_of().clone_box(); } @@ -173,7 +173,7 @@ impl RepositoryInterface for ArrayRepository { ) -> LoadPackagesResult { let packages = self.get_packages(); - let mut result: IndexMap> = IndexMap::new(); + let mut result: IndexMap> = IndexMap::new(); let mut names_found: IndexMap = IndexMap::new(); for package in &packages { if package_name_map.contains_key(package.get_name()) { @@ -231,7 +231,7 @@ impl RepositoryInterface for ArrayRepository { &self, name: String, constraint: FindPackageConstraint, - ) -> Option> { + ) -> Option> { let name = strtolower(&name); let constraint: Box = match constraint { @@ -259,7 +259,7 @@ impl RepositoryInterface for ArrayRepository { &self, name: String, constraint: Option, - ) -> Vec> { + ) -> Vec> { // normalize name let name = strtolower(&name); let mut packages = vec![]; @@ -377,7 +377,7 @@ impl RepositoryInterface for ArrayRepository { fn has_package(&self, package: &dyn PackageInterface) -> bool { if self.package_map.borrow().is_none() { - let mut map: IndexMap> = IndexMap::new(); + let mut map: IndexMap> = IndexMap::new(); for repo_package in self.get_packages() { map.insert(repo_package.get_unique_name(), repo_package); } @@ -419,7 +419,7 @@ impl RepositoryInterface for ArrayRepository { result } - fn get_packages(&self) -> Vec> { + fn get_packages(&self) -> Vec> { if self.packages.borrow().is_none() { self.initialize(); } diff --git a/crates/shirabe/src/repository/artifact_repository.rs b/crates/shirabe/src/repository/artifact_repository.rs index d869156..faef831 100644 --- a/crates/shirabe/src/repository/artifact_repository.rs +++ b/crates/shirabe/src/repository/artifact_repository.rs @@ -133,7 +133,10 @@ impl ArtifactRepository { Ok(()) } - fn get_composer_information(&self, file: &Path) -> anyhow::Result>> { + fn get_composer_information( + &self, + file: &Path, + ) -> anyhow::Result>> { let mut json: Option = None; let file_extension = file .extension() diff --git a/crates/shirabe/src/repository/composer_repository.rs b/crates/shirabe/src/repository/composer_repository.rs index ea73090..15ea084 100644 --- a/crates/shirabe/src/repository/composer_repository.rs +++ b/crates/shirabe/src/repository/composer_repository.rs @@ -119,21 +119,21 @@ pub struct ComposerRepository { #[derive(Debug)] pub enum FindPackageReturn { - Package(Box), - Packages(Vec>), + Package(Box), + Packages(Vec>), None, } #[derive(Debug)] pub struct LoadPackagesResult { pub names_found: Vec, - pub packages: IndexMap>, + pub packages: IndexMap>, } #[derive(Debug)] pub struct LoadAsyncPackagesResult { pub names_found: IndexMap, - pub packages: IndexMap>, + pub packages: IndexMap>, } impl ConfigurableRepositoryInterface for ComposerRepository { @@ -326,7 +326,7 @@ impl ComposerRepository { &mut self, name: String, constraint: PhpMixed, - ) -> anyhow::Result>> { + ) -> anyhow::Result>> { // this call initializes loadRootServerFile which is needed for the rest below to work let has_providers = self.has_providers()?; @@ -347,7 +347,7 @@ impl ComposerRepository { .map_or(false, |m| m.contains_key(&name)) { let packages = self.what_provides(&name, None, None, IndexMap::new())?; - let packages_vec: Vec> = packages.into_values().collect(); + let packages_vec: Vec> = packages.into_values().collect(); return Ok( match self.filter_packages(packages_vec, Some(&*constraint), true) { FindPackageReturn::Package(p) => Some(p), @@ -376,7 +376,7 @@ impl ComposerRepository { if name == provider_name { let packages = self.what_provides(&provider_name, None, None, IndexMap::new())?; - let packages_vec: Vec> = packages.into_values().collect(); + let packages_vec: Vec> = packages.into_values().collect(); return Ok( match self.filter_packages(packages_vec, Some(&*constraint), true) { FindPackageReturn::Package(p) => Some(p), @@ -397,7 +397,7 @@ impl ComposerRepository { &mut self, name: String, constraint: Option, - ) -> anyhow::Result>> { + ) -> anyhow::Result>> { // this call initializes loadRootServerFile which is needed for the rest below to work let has_providers = self.has_providers()?; @@ -416,7 +416,7 @@ impl ComposerRepository { .map_or(false, |m| m.contains_key(&name)) { let packages = self.what_provides(&name, None, None, IndexMap::new())?; - let packages_vec: Vec> = packages.into_values().collect(); + let packages_vec: Vec> = packages.into_values().collect(); return Ok( match self.filter_packages(packages_vec, constraint.as_deref(), false) { FindPackageReturn::Packages(v) => v, @@ -441,7 +441,7 @@ impl ComposerRepository { if name == provider_name { let packages = self.what_provides(&provider_name, None, None, IndexMap::new())?; - let packages_vec: Vec> = packages.into_values().collect(); + let packages_vec: Vec> = packages.into_values().collect(); return Ok( match self.filter_packages(packages_vec, constraint.as_deref(), false) { FindPackageReturn::Packages(v) => v, @@ -459,7 +459,7 @@ impl ComposerRepository { fn filter_packages( &self, - packages: Vec>, + packages: Vec>, constraint: Option<&dyn ConstraintInterface>, return_first_match: bool, ) -> FindPackageReturn { @@ -475,7 +475,7 @@ impl ComposerRepository { } let constraint = constraint.unwrap(); - let mut filtered_packages: Vec> = Vec::new(); + let mut filtered_packages: Vec> = Vec::new(); for package in packages.into_iter() { let pkg_constraint = Constraint::new("==", package.get_version().to_string()); @@ -496,7 +496,7 @@ impl ComposerRepository { FindPackageReturn::Packages(filtered_packages) } - pub fn get_packages(&mut self) -> anyhow::Result>> { + pub fn get_packages(&mut self) -> anyhow::Result>> { let has_providers = self.has_providers()?; if self.lazy_providers_url.is_some() { @@ -723,13 +723,13 @@ impl ComposerRepository { ); } - let mut packages: IndexMap> = IndexMap::new(); + let mut packages: IndexMap> = IndexMap::new(); let mut names_found: IndexMap = IndexMap::new(); if has_providers || self.has_partial_packages()? { let names: Vec = package_name_map.keys().cloned().collect(); for name in names { - let mut matches: IndexMap> = IndexMap::new(); + let mut matches: IndexMap> = IndexMap::new(); // if a repo has no providers but only partial packages and the partial packages are missing // then we don't want to call whatProvides as it would try to load from the providers and fail @@ -1383,7 +1383,7 @@ impl ComposerRepository { acceptable_stabilities: Option<&IndexMap>, stability_flags: Option<&IndexMap>, already_loaded: IndexMap>>, - ) -> anyhow::Result>> { + ) -> anyhow::Result>> { let mut packages_source: Option = None; let packages: IndexMap; let loading_partial_package: bool; @@ -1600,7 +1600,7 @@ impl ComposerRepository { loading_partial_package = true; } - let mut result: IndexMap> = IndexMap::new(); + let mut result: IndexMap> = IndexMap::new(); let mut versions_to_load: IndexMap> = IndexMap::new(); let packages_inner = packages .get("packages") @@ -1749,7 +1749,7 @@ impl ComposerRepository { } /// Adds a new package to the repository - pub fn add_package(&mut self, mut package: Box) { + pub fn add_package(&mut self, mut package: Box) { // configurePackageTransportOptions(*package); self.configure_package_transport_options(&mut *package); self.inner.add_package(package); @@ -1765,7 +1765,7 @@ impl ComposerRepository { ) -> anyhow::Result { self.load_root_server_file(None)?; - let mut packages: IndexMap> = IndexMap::new(); + let mut packages: IndexMap> = IndexMap::new(); let mut names_found: IndexMap = IndexMap::new(); let mut promises: Vec> = Vec::new(); @@ -1952,7 +1952,7 @@ impl ComposerRepository { } } - let loaded_packages: Vec> = + let loaded_packages: Vec> = ComposerRepository::create_packages_static( versions_to_load, packages_source, @@ -2708,13 +2708,13 @@ impl ComposerRepository { &mut self, packages: Vec>, source: Option, - ) -> anyhow::Result>> { + ) -> anyhow::Result>> { if packages.is_empty() { return Ok(vec![]); } let mut packages = packages; - let result = (|| -> anyhow::Result>> { + let result = (|| -> anyhow::Result>> { for data in packages.iter_mut() { if !data.contains_key("notification-url") { data.insert( @@ -2729,7 +2729,7 @@ impl ComposerRepository { let package_instances = self.loader.load_packages(packages.clone())?; - let mut results: Vec> = Vec::new(); + let mut results: Vec> = Vec::new(); for mut package in package_instances.into_iter() { if let Some(src_type) = package.get_source_type() { if let Some(mirrors) = @@ -2768,7 +2768,7 @@ impl ComposerRepository { fn create_packages_static( packages: Vec>, _source: Option, - ) -> anyhow::Result>> { + ) -> anyhow::Result>> { if packages.is_empty() { return Ok(vec![]); } @@ -3448,7 +3448,7 @@ fn clone_root_data(rd: &RootData) -> RootData { } } -fn dyn_clone_box(_pkg: &BasePackage) -> Box { +fn dyn_clone_box(_pkg: &dyn BasePackage) -> Box { todo!() } diff --git a/crates/shirabe/src/repository/composite_repository.rs b/crates/shirabe/src/repository/composite_repository.rs index e34a5f8..4914538 100644 --- a/crates/shirabe/src/repository/composite_repository.rs +++ b/crates/shirabe/src/repository/composite_repository.rs @@ -80,7 +80,7 @@ impl RepositoryInterface for CompositeRepository { &self, name: String, constraint: FindPackageConstraint, - ) -> Option> { + ) -> Option> { for repository in &self.repositories { let package = repository.find_package(name.clone(), constraint.clone()); if package.is_some() { @@ -94,7 +94,7 @@ impl RepositoryInterface for CompositeRepository { &self, name: String, constraint: Option, - ) -> Vec> { + ) -> Vec> { let mut packages = vec![]; for repository in &self.repositories { packages.extend(repository.find_packages(name.clone(), constraint.clone())); @@ -102,7 +102,7 @@ impl RepositoryInterface for CompositeRepository { packages } - fn get_packages(&self) -> Vec> { + fn get_packages(&self) -> Vec> { let mut packages = vec![]; for repository in &self.repositories { packages.extend(repository.get_packages()); diff --git a/crates/shirabe/src/repository/filter_repository.rs b/crates/shirabe/src/repository/filter_repository.rs index eeb1306..ce6a38a 100644 --- a/crates/shirabe/src/repository/filter_repository.rs +++ b/crates/shirabe/src/repository/filter_repository.rs @@ -161,7 +161,7 @@ impl RepositoryInterface for FilterRepository { &self, name: String, constraint: FindPackageConstraint, - ) -> Option> { + ) -> Option> { if !self.is_allowed(&name) { return None; } @@ -173,7 +173,7 @@ impl RepositoryInterface for FilterRepository { &self, name: String, constraint: Option, - ) -> Vec> { + ) -> Vec> { if !self.is_allowed(&name) { return Vec::new(); } @@ -222,7 +222,7 @@ impl RepositoryInterface for FilterRepository { result } - fn get_packages(&self) -> Vec> { + fn get_packages(&self) -> Vec> { let mut result = Vec::new(); for package in self.repo.get_packages() { if self.is_allowed(package.get_name()) { diff --git a/crates/shirabe/src/repository/installed_repository.rs b/crates/shirabe/src/repository/installed_repository.rs index bb56c94..3b6563d 100644 --- a/crates/shirabe/src/repository/installed_repository.rs +++ b/crates/shirabe/src/repository/installed_repository.rs @@ -26,7 +26,7 @@ pub enum NeedleInput { } pub struct DependentsEntry( - pub Box, + pub Box, pub Link, pub Option>, ); @@ -51,7 +51,7 @@ impl InstalledRepository { &self, name: String, constraint: Option, - ) -> Vec> { + ) -> Vec> { let name = name.to_lowercase(); let constraint: Option> = match constraint { @@ -117,7 +117,7 @@ impl InstalledRepository { let mut packages_found = packages_found.unwrap_or_else(|| needles.clone()); - let mut root_package: Option> = None; + let mut root_package: Option> = None; for package in self.inner.get_packages() { if package.as_any().is::() { root_package = Some(package); @@ -422,7 +422,7 @@ impl RepositoryInterface for InstalledRepository { &self, name: String, constraint: FindPackageConstraint, - ) -> Option> { + ) -> Option> { self.inner.find_package(name, constraint) } @@ -430,11 +430,11 @@ impl RepositoryInterface for InstalledRepository { &self, name: String, constraint: Option, - ) -> Vec> { + ) -> Vec> { self.inner.find_packages(name, constraint) } - fn get_packages(&self) -> Vec> { + fn get_packages(&self) -> Vec> { self.inner.get_packages() } diff --git a/crates/shirabe/src/repository/repository_interface.rs b/crates/shirabe/src/repository/repository_interface.rs index 777d3f6..c321908 100644 --- a/crates/shirabe/src/repository/repository_interface.rs +++ b/crates/shirabe/src/repository/repository_interface.rs @@ -14,7 +14,7 @@ pub enum FindPackageConstraint { pub struct LoadPackagesResult { pub names_found: Vec, - pub packages: Vec>, + pub packages: Vec>, } pub enum AbandonedInfo { @@ -46,15 +46,15 @@ pub trait RepositoryInterface: Countable { &self, name: String, constraint: FindPackageConstraint, - ) -> Option>; + ) -> Option>; fn find_packages( &self, name: String, constraint: Option, - ) -> Vec>; + ) -> Vec>; - fn get_packages(&self) -> Vec>; + fn get_packages(&self) -> Vec>; fn load_packages( &self, diff --git a/crates/shirabe/src/repository/repository_set.rs b/crates/shirabe/src/repository/repository_set.rs index e25bd29..6985a18 100644 --- a/crates/shirabe/src/repository/repository_set.rs +++ b/crates/shirabe/src/repository/repository_set.rs @@ -211,11 +211,11 @@ impl RepositorySet { name: &str, constraint: Option>, flags: i64, - ) -> Vec> { + ) -> Vec> { let ignore_stability = (flags & Self::ALLOW_UNACCEPTABLE_STABILITIES) != 0; let load_from_all_repos = (flags & Self::ALLOW_SHADOWED_REPOSITORIES) != 0; - let mut packages: Vec>> = vec![]; + let mut packages: Vec>> = vec![]; if load_from_all_repos { for repository in &self.repositories { // PHP: $repository->findPackages($name, $constraint) ?: [] @@ -262,7 +262,7 @@ impl RepositorySet { } // PHP: $candidates = $packages ? array_merge(...$packages) : []; - let candidates: Vec> = if !packages.is_empty() { + let candidates: Vec> = if !packages.is_empty() { packages.into_iter().flatten().collect() } else { vec![] @@ -273,7 +273,7 @@ impl RepositorySet { return candidates; } - let mut result: Vec> = vec![]; + let mut result: Vec> = vec![]; for candidate in candidates { if self.is_package_acceptable(&candidate.get_names(true), candidate.get_stability()) { result.push(candidate); @@ -518,7 +518,7 @@ impl RepositorySet { self.locked = true; - let mut packages: Vec> = vec![]; + let mut packages: Vec> = vec![]; for repository in &self.repositories { for mut package in repository.get_packages() { let name = package.get_name().to_string(); @@ -532,7 +532,7 @@ impl RepositorySet { { package = alias_pkg.get_alias_of().clone_box(); } - let alias_package: Box = if (package.as_any() as &dyn Any) + let alias_package: Box = if (package.as_any() as &dyn Any) .downcast_ref::() .is_some() { diff --git a/crates/shirabe/src/repository/vcs_repository.rs b/crates/shirabe/src/repository/vcs_repository.rs index 9499790..4374130 100644 --- a/crates/shirabe/src/repository/vcs_repository.rs +++ b/crates/shirabe/src/repository/vcs_repository.rs @@ -973,7 +973,7 @@ impl VcsRepository { enum CachedPackageResult { None, Missing, - Package(Box), + Package(Box), } #[derive(Debug)] -- cgit v1.3.1