From 3d3856ffd5583c8413d4abc2076ce1285a22acdb Mon Sep 17 00:00:00 2001 From: adamnemecek Date: Tue, 5 Aug 2025 13:19:56 -0700 Subject: [PATCH] additional use of Self, remove * and & where not needed (#15091) continuation of #15074. --- .../uv-configuration/src/package_options.rs | 6 ++-- crates/uv-distribution-types/src/file.rs | 6 ++-- crates/uv-distribution-types/src/index_url.rs | 2 +- .../src/prioritized_distribution.rs | 20 +++++------ .../uv-distribution-types/src/requirement.rs | 2 +- crates/uv-globfilter/src/portable_glob.rs | 4 +-- crates/uv-pep440/src/version.rs | 6 ++-- crates/uv-pep508/src/marker/tree.rs | 2 +- crates/uv-platform-tags/src/platform.rs | 2 +- crates/uv-pypi-types/src/conflicts.rs | 34 +++++++++---------- crates/uv-requirements-txt/src/lib.rs | 2 +- crates/uv-resolver/src/lock/mod.rs | 32 ++++++++--------- crates/uv-resolver/src/resolution/output.rs | 12 +++---- crates/uv-resolver/src/universal_marker.rs | 12 +++---- 14 files changed, 71 insertions(+), 71 deletions(-) diff --git a/crates/uv-configuration/src/package_options.rs b/crates/uv-configuration/src/package_options.rs index b07fb8a50..a8654089e 100644 --- a/crates/uv-configuration/src/package_options.rs +++ b/crates/uv-configuration/src/package_options.rs @@ -51,7 +51,7 @@ impl Reinstall { /// Returns `true` if the specified package should be reinstalled. pub fn contains_package(&self, package_name: &PackageName) -> bool { - match &self { + match self { Self::None => false, Self::All => true, Self::Packages(packages, ..) => packages.contains(package_name), @@ -60,7 +60,7 @@ impl Reinstall { /// Returns `true` if the specified path should be reinstalled. pub fn contains_path(&self, path: &Path) -> bool { - match &self { + match self { Self::None => false, Self::All => true, Self::Packages(.., paths) => paths @@ -194,7 +194,7 @@ impl Upgrade { /// Returns `true` if the specified package should be upgraded. pub fn contains(&self, package_name: &PackageName) -> bool { - match &self { + match self { Self::None => false, Self::All => true, Self::Packages(packages) => packages.contains_key(package_name), diff --git a/crates/uv-distribution-types/src/file.rs b/crates/uv-distribution-types/src/file.rs index eb4794152..3b8a0d6ad 100644 --- a/crates/uv-distribution-types/src/file.rs +++ b/crates/uv-distribution-types/src/file.rs @@ -97,8 +97,8 @@ impl FileLocation { /// example, the location is a path and the path isn't valid UTF-8. /// (Because URLs must be valid UTF-8.) pub fn to_url(&self) -> Result { - match *self { - Self::RelativeUrl(ref base, ref path) => { + match self { + Self::RelativeUrl(base, path) => { let base_url = DisplaySafeUrl::parse(base).map_err(|err| ToUrlError::InvalidBase { base: base.to_string(), @@ -111,7 +111,7 @@ impl FileLocation { })?; Ok(joined) } - Self::AbsoluteUrl(ref absolute) => absolute.to_url(), + Self::AbsoluteUrl(absolute) => absolute.to_url(), } } } diff --git a/crates/uv-distribution-types/src/index_url.rs b/crates/uv-distribution-types/src/index_url.rs index 32cf12bc4..a96e00f79 100644 --- a/crates/uv-distribution-types/src/index_url.rs +++ b/crates/uv-distribution-types/src/index_url.rs @@ -260,7 +260,7 @@ impl Deref for IndexUrl { type Target = Url; fn deref(&self) -> &Self::Target { - match &self { + match self { Self::Pypi(url) => url, Self::Url(url) => url, Self::Path(url) => url, diff --git a/crates/uv-distribution-types/src/prioritized_distribution.rs b/crates/uv-distribution-types/src/prioritized_distribution.rs index 4f64cc6f8..f2c4e267d 100644 --- a/crates/uv-distribution-types/src/prioritized_distribution.rs +++ b/crates/uv-distribution-types/src/prioritized_distribution.rs @@ -620,15 +620,15 @@ impl PrioritizedDist { impl<'a> CompatibleDist<'a> { /// Return the [`ResolvedDistRef`] to use during resolution. pub fn for_resolution(&self) -> ResolvedDistRef<'a> { - match *self { - CompatibleDist::InstalledDist(dist) => ResolvedDistRef::Installed { dist }, - CompatibleDist::SourceDist { sdist, prioritized } => { + match self { + Self::InstalledDist(dist) => ResolvedDistRef::Installed { dist }, + Self::SourceDist { sdist, prioritized } => { ResolvedDistRef::InstallableRegistrySourceDist { sdist, prioritized } } - CompatibleDist::CompatibleWheel { + Self::CompatibleWheel { wheel, prioritized, .. } => ResolvedDistRef::InstallableRegistryBuiltDist { wheel, prioritized }, - CompatibleDist::IncompatibleWheel { + Self::IncompatibleWheel { wheel, prioritized, .. } => ResolvedDistRef::InstallableRegistryBuiltDist { wheel, prioritized }, } @@ -636,15 +636,15 @@ impl<'a> CompatibleDist<'a> { /// Return the [`ResolvedDistRef`] to use during installation. pub fn for_installation(&self) -> ResolvedDistRef<'a> { - match *self { - CompatibleDist::InstalledDist(dist) => ResolvedDistRef::Installed { dist }, - CompatibleDist::SourceDist { sdist, prioritized } => { + match self { + Self::InstalledDist(dist) => ResolvedDistRef::Installed { dist }, + Self::SourceDist { sdist, prioritized } => { ResolvedDistRef::InstallableRegistrySourceDist { sdist, prioritized } } - CompatibleDist::CompatibleWheel { + Self::CompatibleWheel { wheel, prioritized, .. } => ResolvedDistRef::InstallableRegistryBuiltDist { wheel, prioritized }, - CompatibleDist::IncompatibleWheel { + Self::IncompatibleWheel { sdist, prioritized, .. } => ResolvedDistRef::InstallableRegistrySourceDist { sdist, prioritized }, } diff --git a/crates/uv-distribution-types/src/requirement.rs b/crates/uv-distribution-types/src/requirement.rs index 4c845a8df..25676d999 100644 --- a/crates/uv-distribution-types/src/requirement.rs +++ b/crates/uv-distribution-types/src/requirement.rs @@ -571,7 +571,7 @@ impl RequirementSource { /// Convert the source to a [`VerbatimParsedUrl`], if it's a URL source. pub fn to_verbatim_parsed_url(&self) -> Option { - match &self { + match self { Self::Registry { .. } => None, Self::Url { location, diff --git a/crates/uv-globfilter/src/portable_glob.rs b/crates/uv-globfilter/src/portable_glob.rs index 3ae232c37..451f7441c 100644 --- a/crates/uv-globfilter/src/portable_glob.rs +++ b/crates/uv-globfilter/src/portable_glob.rs @@ -164,7 +164,7 @@ impl PortableGlobParser { } start_or_slash = false; } else if c == '\\' { - match *self { + match self { Self::Pep639 => { return Err(PortableGlobError::InvalidBackslash { glob: glob.to_string(), @@ -194,7 +194,7 @@ impl PortableGlobParser { } } } else { - let err = match *self { + let err = match self { Self::Pep639 => PortableGlobError::InvalidCharacter { glob: glob.to_string(), pos, diff --git a/crates/uv-pep440/src/version.rs b/crates/uv-pep440/src/version.rs index 5f52de0ab..8b42acdd6 100644 --- a/crates/uv-pep440/src/version.rs +++ b/crates/uv-pep440/src/version.rs @@ -2405,9 +2405,9 @@ impl ReleaseNumbers { /// Returns the release components as a slice. fn as_slice(&self) -> &[u64] { - match *self { - Self::Inline { ref numbers, len } => &numbers[..len], - Self::Vec(ref vec) => vec, + match self { + Self::Inline { numbers, len } => &numbers[..*len], + Self::Vec(vec) => vec, } } } diff --git a/crates/uv-pep508/src/marker/tree.rs b/crates/uv-pep508/src/marker/tree.rs index e33d5f5ab..450096e50 100644 --- a/crates/uv-pep508/src/marker/tree.rs +++ b/crates/uv-pep508/src/marker/tree.rs @@ -581,7 +581,7 @@ impl ExtraOperator { /// Negates this operator. pub(crate) fn negate(&self) -> Self { - match *self { + match self { Self::Equal => Self::NotEqual, Self::NotEqual => Self::Equal, } diff --git a/crates/uv-platform-tags/src/platform.rs b/crates/uv-platform-tags/src/platform.rs index 88c36714b..406facd5d 100644 --- a/crates/uv-platform-tags/src/platform.rs +++ b/crates/uv-platform-tags/src/platform.rs @@ -56,7 +56,7 @@ pub enum Os { impl fmt::Display for Os { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { + match self { Self::Manylinux { .. } => write!(f, "manylinux"), Self::Musllinux { .. } => write!(f, "musllinux"), Self::Windows => write!(f, "windows"), diff --git a/crates/uv-pypi-types/src/conflicts.rs b/crates/uv-pypi-types/src/conflicts.rs index 9200402f4..5ebeb160a 100644 --- a/crates/uv-pypi-types/src/conflicts.rs +++ b/crates/uv-pypi-types/src/conflicts.rs @@ -450,8 +450,8 @@ impl ConflictPackage { /// If this conflict corresponds to an extra, then return the /// extra name. pub fn extra(&self) -> Option<&ExtraName> { - match *self { - Self::Extra(ref extra) => Some(extra), + match self { + Self::Extra(extra) => Some(extra), Self::Group(_) => None, } } @@ -459,17 +459,17 @@ impl ConflictPackage { /// If this conflict corresponds to a group, then return the /// group name. pub fn group(&self) -> Option<&GroupName> { - match *self { - Self::Group(ref group) => Some(group), + match self { + Self::Group(group) => Some(group), Self::Extra(_) => None, } } /// Returns this conflict as a new type with its fields borrowed. pub fn as_ref(&self) -> ConflictPackageRef<'_> { - match *self { - Self::Extra(ref extra) => ConflictPackageRef::Extra(extra), - Self::Group(ref group) => ConflictPackageRef::Group(group), + match self { + Self::Extra(extra) => ConflictPackageRef::Extra(extra), + Self::Group(group) => ConflictPackageRef::Group(group), } } } @@ -487,39 +487,39 @@ impl<'a> ConflictPackageRef<'a> { /// If this conflict corresponds to an extra, then return the /// extra name. pub fn extra(&self) -> Option<&'a ExtraName> { - match *self { - ConflictPackageRef::Extra(extra) => Some(extra), - ConflictPackageRef::Group(_) => None, + match self { + Self::Extra(extra) => Some(extra), + Self::Group(_) => None, } } /// If this conflict corresponds to a group, then return the /// group name. pub fn group(&self) -> Option<&'a GroupName> { - match *self { - ConflictPackageRef::Group(group) => Some(group), - ConflictPackageRef::Extra(_) => None, + match self { + Self::Group(group) => Some(group), + Self::Extra(_) => None, } } /// Converts this borrowed conflict to its owned variant. pub fn to_owned(&self) -> ConflictPackage { match *self { - ConflictPackageRef::Extra(extra) => ConflictPackage::Extra(extra.clone()), - ConflictPackageRef::Group(group) => ConflictPackage::Group(group.clone()), + Self::Extra(extra) => ConflictPackage::Extra(extra.clone()), + Self::Group(group) => ConflictPackage::Group(group.clone()), } } } impl<'a> From<&'a ExtraName> for ConflictPackageRef<'a> { fn from(extra: &'a ExtraName) -> Self { - ConflictPackageRef::Extra(extra) + Self::Extra(extra) } } impl<'a> From<&'a GroupName> for ConflictPackageRef<'a> { fn from(group: &'a GroupName) -> Self { - ConflictPackageRef::Group(group) + Self::Group(group) } } diff --git a/crates/uv-requirements-txt/src/lib.rs b/crates/uv-requirements-txt/src/lib.rs index 4209dd6d4..a5c9945a2 100644 --- a/crates/uv-requirements-txt/src/lib.rs +++ b/crates/uv-requirements-txt/src/lib.rs @@ -1131,7 +1131,7 @@ impl Display for RequirementsTxtParserError { impl std::error::Error for RequirementsTxtParserError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - match &self { + match self { Self::Io(err) => err.source(), Self::Url { source, .. } => Some(source), Self::FileUrl { .. } => None, diff --git a/crates/uv-resolver/src/lock/mod.rs b/crates/uv-resolver/src/lock/mod.rs index 79baa320e..5a7affdf2 100644 --- a/crates/uv-resolver/src/lock/mod.rs +++ b/crates/uv-resolver/src/lock/mod.rs @@ -3540,7 +3540,7 @@ impl Source { /// Returns `true` if the source is that of a wheel. fn is_wheel(&self) -> bool { - match &self { + match self { Self::Path(path) => { matches!( DistExtension::from_path(path).ok(), @@ -3579,8 +3579,8 @@ impl Source { fn to_toml(&self, table: &mut Table) { let mut source_table = InlineTable::new(); - match *self { - Self::Registry(ref source) => match source { + match self { + Self::Registry(source) => match source { RegistrySource::Url(url) => { source_table.insert("registry", Value::from(url.as_ref())); } @@ -3591,10 +3591,10 @@ impl Source { ); } }, - Self::Git(ref url, _) => { + Self::Git(url, _) => { source_table.insert("git", Value::from(url.as_ref())); } - Self::Direct(ref url, DirectSource { ref subdirectory }) => { + Self::Direct(url, DirectSource { subdirectory }) => { source_table.insert("url", Value::from(url.as_ref())); if let Some(ref subdirectory) = *subdirectory { source_table.insert( @@ -3603,22 +3603,22 @@ impl Source { ); } } - Self::Path(ref path) => { + Self::Path(path) => { source_table.insert("path", Value::from(PortablePath::from(path).to_string())); } - Self::Directory(ref path) => { + Self::Directory(path) => { source_table.insert( "directory", Value::from(PortablePath::from(path).to_string()), ); } - Self::Editable(ref path) => { + Self::Editable(path) => { source_table.insert( "editable", Value::from(PortablePath::from(path).to_string()), ); } - Self::Virtual(ref path) => { + Self::Virtual(path) => { source_table.insert("virtual", Value::from(PortablePath::from(path).to_string())); } } @@ -3645,7 +3645,7 @@ impl Display for Source { impl Source { fn name(&self) -> &str { - match *self { + match self { Self::Registry(..) => "registry", Self::Git(..) => "git", Self::Direct(..) => "direct", @@ -3664,7 +3664,7 @@ impl Source { /// /// Returns `None` to indicate that the source kind _may_ include a hash. fn requires_hash(&self) -> Option { - match *self { + match self { Self::Registry(..) => None, Self::Direct(..) | Self::Path(..) => Some(true), Self::Git(..) | Self::Directory(..) | Self::Editable(..) | Self::Virtual(..) => { @@ -3927,7 +3927,7 @@ impl SourceDist { } fn url(&self) -> Option<&UrlString> { - match &self { + match self { Self::Metadata { .. } => None, Self::Url { url, .. } => Some(url), Self::Path { .. } => None, @@ -3935,7 +3935,7 @@ impl SourceDist { } pub(crate) fn hash(&self) -> Option<&Hash> { - match &self { + match self { Self::Metadata { metadata } => metadata.hash.as_ref(), Self::Url { metadata, .. } => metadata.hash.as_ref(), Self::Path { metadata, .. } => metadata.hash.as_ref(), @@ -3943,7 +3943,7 @@ impl SourceDist { } pub(crate) fn size(&self) -> Option { - match &self { + match self { Self::Metadata { metadata } => metadata.size, Self::Url { metadata, .. } => metadata.size, Self::Path { metadata, .. } => metadata.size, @@ -3951,7 +3951,7 @@ impl SourceDist { } pub(crate) fn upload_time(&self) -> Option { - match &self { + match self { Self::Metadata { metadata } => metadata.upload_time, Self::Url { metadata, .. } => metadata.upload_time, Self::Path { metadata, .. } => metadata.upload_time, @@ -4169,7 +4169,7 @@ impl SourceDist { /// Returns the TOML representation of this source distribution. fn to_toml(&self) -> Result { let mut table = InlineTable::new(); - match &self { + match self { Self::Metadata { .. } => {} Self::Url { url, .. } => { table.insert("url", Value::from(url.as_ref())); diff --git a/crates/uv-resolver/src/resolution/output.rs b/crates/uv-resolver/src/resolution/output.rs index e1da40f25..c69c2e21e 100644 --- a/crates/uv-resolver/src/resolution/output.rs +++ b/crates/uv-resolver/src/resolution/output.rs @@ -74,9 +74,9 @@ impl ResolutionGraphNode { } pub(crate) fn package_extra_names(&self) -> Option<(&PackageName, &ExtraName)> { - match *self { + match self { Self::Root => None, - Self::Dist(ref dist) => { + Self::Dist(dist) => { let extra = dist.extra.as_ref()?; Some((&dist.name, extra)) } @@ -84,9 +84,9 @@ impl ResolutionGraphNode { } pub(crate) fn package_group_names(&self) -> Option<(&PackageName, &GroupName)> { - match *self { + match self { Self::Root => None, - Self::Dist(ref dist) => { + Self::Dist(dist) => { let group = dist.dev.as_ref()?; Some((&dist.name, group)) } @@ -94,9 +94,9 @@ impl ResolutionGraphNode { } pub(crate) fn package_name(&self) -> Option<&PackageName> { - match *self { + match self { Self::Root => None, - Self::Dist(ref dist) => Some(&dist.name), + Self::Dist(dist) => Some(&dist.name), } } } diff --git a/crates/uv-resolver/src/universal_marker.rs b/crates/uv-resolver/src/universal_marker.rs index 4114825fb..e0643520b 100644 --- a/crates/uv-resolver/src/universal_marker.rs +++ b/crates/uv-resolver/src/universal_marker.rs @@ -588,8 +588,8 @@ impl<'a> ParsedRawExtra<'a> { name_error, } })?; - match *self { - ParsedRawExtra::Extra { extra, .. } => { + match self { + Self::Extra { extra, .. } => { let extra = ExtraName::from_str(extra).map_err(|name_error| { ResolveError::InvalidValueInConflictMarker { kind: "extra", @@ -598,7 +598,7 @@ impl<'a> ParsedRawExtra<'a> { })?; Ok(ConflictItem::from((package, extra))) } - ParsedRawExtra::Group { group, .. } => { + Self::Group { group, .. } => { let group = GroupName::from_str(group).map_err(|name_error| { ResolveError::InvalidValueInConflictMarker { kind: "group", @@ -611,9 +611,9 @@ impl<'a> ParsedRawExtra<'a> { } fn package(&self) -> &'a str { - match *self { - ParsedRawExtra::Extra { package, .. } => package, - ParsedRawExtra::Group { package, .. } => package, + match self { + Self::Extra { package, .. } => package, + Self::Group { package, .. } => package, } } }