mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-22 03:24:08 +00:00
additional use of Self, remove * and & where not needed (#15091)
continuation of #15074.
This commit is contained in:
parent
bda9ea957a
commit
3d3856ffd5
14 changed files with 71 additions and 71 deletions
|
@ -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),
|
||||
|
|
|
@ -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<DisplaySafeUrl, ToUrlError> {
|
||||
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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 },
|
||||
}
|
||||
|
|
|
@ -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<VerbatimParsedUrl> {
|
||||
match &self {
|
||||
match self {
|
||||
Self::Registry { .. } => None,
|
||||
Self::Url {
|
||||
location,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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"),
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<bool> {
|
||||
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<u64> {
|
||||
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<Timestamp> {
|
||||
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<InlineTable, toml_edit::ser::Error> {
|
||||
let mut table = InlineTable::new();
|
||||
match &self {
|
||||
match self {
|
||||
Self::Metadata { .. } => {}
|
||||
Self::Url { url, .. } => {
|
||||
table.insert("url", Value::from(url.as_ref()));
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue