Skip to content

Commit

Permalink
Clippy pedantic (astral-sh#1963)
Browse files Browse the repository at this point in the history
Address a few pedantic lints

lints are separated into separate commits so they can be reviewed
individually.

I've not added enforcement for any of these lints, but that could be
added if desirable.
  • Loading branch information
danieleades authored Feb 25, 2024
1 parent b052291 commit 8d72183
Show file tree
Hide file tree
Showing 68 changed files with 635 additions and 673 deletions.
8 changes: 4 additions & 4 deletions crates/cache-key/src/canonical_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::cache_key::{CacheKey, CacheKeyHasher};
pub struct CanonicalUrl(Url);

impl CanonicalUrl {
pub fn new(url: &Url) -> CanonicalUrl {
pub fn new(url: &Url) -> Self {
let mut url = url.clone();

// Strip a trailing slash.
Expand Down Expand Up @@ -62,7 +62,7 @@ impl CanonicalUrl {
}
}

CanonicalUrl(url)
Self(url)
}

pub fn parse(url: &str) -> Result<Self, url::ParseError> {
Expand Down Expand Up @@ -104,7 +104,7 @@ impl std::fmt::Display for CanonicalUrl {
pub struct RepositoryUrl(Url);

impl RepositoryUrl {
pub fn new(url: &Url) -> RepositoryUrl {
pub fn new(url: &Url) -> Self {
let mut url = CanonicalUrl::new(url).0;

// If a Git URL ends in a reference (like a branch, tag, or commit), remove it.
Expand All @@ -122,7 +122,7 @@ impl RepositoryUrl {
url.set_fragment(None);
url.set_query(None);

RepositoryUrl(url)
Self(url)
}

pub fn parse(url: &str) -> Result<Self, url::ParseError> {
Expand Down
12 changes: 6 additions & 6 deletions crates/distribution-filename/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,24 @@ impl DistFilename {

pub fn name(&self) -> &PackageName {
match self {
DistFilename::SourceDistFilename(filename) => &filename.name,
DistFilename::WheelFilename(filename) => &filename.name,
Self::SourceDistFilename(filename) => &filename.name,
Self::WheelFilename(filename) => &filename.name,
}
}

pub fn version(&self) -> &Version {
match self {
DistFilename::SourceDistFilename(filename) => &filename.version,
DistFilename::WheelFilename(filename) => &filename.version,
Self::SourceDistFilename(filename) => &filename.version,
Self::WheelFilename(filename) => &filename.version,
}
}
}

impl Display for DistFilename {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
DistFilename::SourceDistFilename(filename) => Display::fmt(filename, f),
DistFilename::WheelFilename(filename) => Display::fmt(filename, f),
Self::SourceDistFilename(filename) => Display::fmt(filename, f),
Self::WheelFilename(filename) => Display::fmt(filename, f),
}
}
}
4 changes: 2 additions & 2 deletions crates/distribution-filename/src/source_dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ impl FromStr for SourceDistExtension {
impl Display for SourceDistExtension {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
SourceDistExtension::Zip => f.write_str("zip"),
SourceDistExtension::TarGz => f.write_str("tar.gz"),
Self::Zip => f.write_str("zip"),
Self::TarGz => f.write_str("tar.gz"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/distribution-filename/src/wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl WheelFilename {
.map_err(|err| WheelFilenameError::InvalidPackageName(filename.to_string(), err))?;
let version = Version::from_str(version)
.map_err(|err| WheelFilenameError::InvalidVersion(filename.to_string(), err))?;
Ok(WheelFilename {
Ok(Self {
name,
version,
python_tag: python_tag.split('.').map(String::from).collect(),
Expand Down
12 changes: 6 additions & 6 deletions crates/distribution-types/src/cached.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ impl CachedDist {
/// Return the [`DirectUrl`] of the distribution, if it exists.
pub fn direct_url(&self) -> Result<Option<DirectUrl>> {
match self {
CachedDist::Registry(_) => Ok(None),
CachedDist::Url(dist) => {
Self::Registry(_) => Ok(None),
Self::Url(dist) => {
if dist.editable {
assert_eq!(dist.url.scheme(), "file", "{}", dist.url);
Ok(Some(DirectUrl::LocalFile(LocalFileUrl {
Expand All @@ -106,15 +106,15 @@ impl CachedDist {

pub fn editable(&self) -> bool {
match self {
CachedDist::Registry(_) => false,
CachedDist::Url(dist) => dist.editable,
Self::Registry(_) => false,
Self::Url(dist) => dist.editable,
}
}

pub fn filename(&self) -> &WheelFilename {
match self {
CachedDist::Registry(dist) => &dist.filename,
CachedDist::Url(dist) => &dist.filename,
Self::Registry(dist) => &dist.filename,
Self::Url(dist) => &dist.filename,
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions crates/distribution-types/src/direct_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ impl TryFrom<&DirectUrl> for pypi_types::DirectUrl {

fn try_from(value: &DirectUrl) -> std::result::Result<Self, Self::Error> {
match value {
DirectUrl::LocalFile(value) => pypi_types::DirectUrl::try_from(value),
DirectUrl::Git(value) => pypi_types::DirectUrl::try_from(value),
DirectUrl::Archive(value) => pypi_types::DirectUrl::try_from(value),
DirectUrl::LocalFile(value) => Self::try_from(value),
DirectUrl::Git(value) => Self::try_from(value),
DirectUrl::Archive(value) => Self::try_from(value),
}
}
}
Expand All @@ -131,7 +131,7 @@ impl TryFrom<&LocalFileUrl> for pypi_types::DirectUrl {
type Error = Error;

fn try_from(value: &LocalFileUrl) -> Result<Self, Self::Error> {
Ok(pypi_types::DirectUrl::LocalDirectory {
Ok(Self::LocalDirectory {
url: value.url.to_string(),
dir_info: pypi_types::DirInfo {
editable: value.editable.then_some(true),
Expand All @@ -144,7 +144,7 @@ impl TryFrom<&DirectArchiveUrl> for pypi_types::DirectUrl {
type Error = Error;

fn try_from(value: &DirectArchiveUrl) -> Result<Self, Self::Error> {
Ok(pypi_types::DirectUrl::ArchiveUrl {
Ok(Self::ArchiveUrl {
url: value.url.to_string(),
archive_info: pypi_types::ArchiveInfo {
hash: None,
Expand All @@ -159,7 +159,7 @@ impl TryFrom<&DirectGitUrl> for pypi_types::DirectUrl {
type Error = Error;

fn try_from(value: &DirectGitUrl) -> Result<Self, Self::Error> {
Ok(pypi_types::DirectUrl::VcsUrl {
Ok(Self::VcsUrl {
url: value.url.repository().to_string(),
vcs_info: pypi_types::VcsInfo {
vcs: pypi_types::VcsKind::Git,
Expand Down Expand Up @@ -199,7 +199,7 @@ impl From<DirectArchiveUrl> for Url {

impl From<DirectGitUrl> for Url {
fn from(value: DirectGitUrl) -> Self {
let mut url = Url::parse(&format!("{}{}", "git+", Url::from(value.url).as_str()))
let mut url = Self::parse(&format!("{}{}", "git+", Self::from(value.url).as_str()))
.expect("Git URL is invalid");
if let Some(subdirectory) = value.subdirectory {
url.set_fragment(Some(&format!("subdirectory={}", subdirectory.display())));
Expand Down
6 changes: 3 additions & 3 deletions crates/distribution-types/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ pub enum FileLocation {
impl Display for FileLocation {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
FileLocation::RelativeUrl(_base, url) => Display::fmt(&url, f),
FileLocation::AbsoluteUrl(url) => Display::fmt(&url, f),
FileLocation::Path(path) => Display::fmt(&path.display(), f),
Self::RelativeUrl(_base, url) => Display::fmt(&url, f),
Self::AbsoluteUrl(url) => Display::fmt(&url, f),
Self::Path(path) => Display::fmt(&path.display(), f),
}
}
}
16 changes: 8 additions & 8 deletions crates/distribution-types/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ impl PackageId {
impl Display for PackageId {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
PackageId::NameVersion(name, version) => write!(f, "{name}-{version}"),
PackageId::Url(url) => write!(f, "{url}"),
Self::NameVersion(name, version) => write!(f, "{name}-{version}"),
Self::Url(url) => write!(f, "{url}"),
}
}
}
Expand Down Expand Up @@ -59,23 +59,23 @@ impl ResourceId {
}
}

impl From<&PackageId> for PackageId {
impl From<&Self> for PackageId {
/// Required for `WaitMap::wait`.
fn from(value: &PackageId) -> Self {
fn from(value: &Self) -> Self {
value.clone()
}
}

impl From<&DistributionId> for DistributionId {
impl From<&Self> for DistributionId {
/// Required for `WaitMap::wait`.
fn from(value: &DistributionId) -> Self {
fn from(value: &Self) -> Self {
value.clone()
}
}

impl From<&ResourceId> for ResourceId {
impl From<&Self> for ResourceId {
/// Required for `WaitMap::wait`.
fn from(value: &ResourceId) -> Self {
fn from(value: &Self) -> Self {
value.clone()
}
}
12 changes: 6 additions & 6 deletions crates/distribution-types/src/index_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pub enum IndexUrl {
impl Display for IndexUrl {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
IndexUrl::Pypi => Display::fmt(&*PYPI_URL, f),
IndexUrl::Url(url) => Display::fmt(url, f),
Self::Pypi => Display::fmt(&*PYPI_URL, f),
Self::Url(url) => Display::fmt(url, f),
}
}
}
Expand Down Expand Up @@ -61,8 +61,8 @@ impl Deref for IndexUrl {

fn deref(&self) -> &Self::Target {
match &self {
IndexUrl::Pypi => &PYPI_URL,
IndexUrl::Url(url) => url,
Self::Pypi => &PYPI_URL,
Self::Url(url) => url,
}
}
}
Expand Down Expand Up @@ -123,8 +123,8 @@ impl FromStr for FlatIndexLocation {
impl Display for FlatIndexLocation {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
FlatIndexLocation::Path(path) => Display::fmt(&path.display(), f),
FlatIndexLocation::Url(url) => Display::fmt(url, f),
Self::Path(path) => Display::fmt(&path.display(), f),
Self::Url(url) => Display::fmt(url, f),
}
}
}
Expand Down
42 changes: 21 additions & 21 deletions crates/distribution-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,15 @@ impl Dist {
/// Returns the [`File`] instance, if this dist is from a registry with simple json api support
pub fn file(&self) -> Option<&File> {
match self {
Dist::Built(built) => built.file(),
Dist::Source(source) => source.file(),
Self::Built(built) => built.file(),
Self::Source(source) => source.file(),
}
}

pub fn version(&self) -> Option<&Version> {
match self {
Dist::Built(wheel) => Some(wheel.version()),
Dist::Source(source_dist) => source_dist.version(),
Self::Built(wheel) => Some(wheel.version()),
Self::Source(source_dist) => source_dist.version(),
}
}
}
Expand All @@ -359,16 +359,16 @@ impl BuiltDist {
/// Returns the [`File`] instance, if this dist is from a registry with simple json api support
pub fn file(&self) -> Option<&File> {
match self {
BuiltDist::Registry(registry) => Some(&registry.file),
BuiltDist::DirectUrl(_) | BuiltDist::Path(_) => None,
Self::Registry(registry) => Some(&registry.file),
Self::DirectUrl(_) | Self::Path(_) => None,
}
}

pub fn version(&self) -> &Version {
match self {
BuiltDist::Registry(wheel) => &wheel.filename.version,
BuiltDist::DirectUrl(wheel) => &wheel.filename.version,
BuiltDist::Path(wheel) => &wheel.filename.version,
Self::Registry(wheel) => &wheel.filename.version,
Self::DirectUrl(wheel) => &wheel.filename.version,
Self::Path(wheel) => &wheel.filename.version,
}
}
}
Expand All @@ -377,26 +377,26 @@ impl SourceDist {
/// Returns the [`File`] instance, if this dist is from a registry with simple json api support
pub fn file(&self) -> Option<&File> {
match self {
SourceDist::Registry(registry) => Some(&registry.file),
SourceDist::DirectUrl(_) | SourceDist::Git(_) | SourceDist::Path(_) => None,
Self::Registry(registry) => Some(&registry.file),
Self::DirectUrl(_) | Self::Git(_) | Self::Path(_) => None,
}
}

pub fn version(&self) -> Option<&Version> {
match self {
SourceDist::Registry(source_dist) => Some(&source_dist.filename.version),
SourceDist::DirectUrl(_) | SourceDist::Git(_) | SourceDist::Path(_) => None,
Self::Registry(source_dist) => Some(&source_dist.filename.version),
Self::DirectUrl(_) | Self::Git(_) | Self::Path(_) => None,
}
}

#[must_use]
pub fn with_url(self, url: Url) -> Self {
match self {
SourceDist::DirectUrl(dist) => SourceDist::DirectUrl(DirectUrlSourceDist {
Self::DirectUrl(dist) => Self::DirectUrl(DirectUrlSourceDist {
url: VerbatimUrl::unknown(url),
..dist
}),
SourceDist::Git(dist) => SourceDist::Git(GitSourceDist {
Self::Git(dist) => Self::Git(GitSourceDist {
url: VerbatimUrl::unknown(url),
..dist
}),
Expand Down Expand Up @@ -799,17 +799,17 @@ impl Identifier for (&Url, &str) {
impl Identifier for FileLocation {
fn distribution_id(&self) -> DistributionId {
match self {
FileLocation::RelativeUrl(base, url) => (base.as_str(), url.as_str()).distribution_id(),
FileLocation::AbsoluteUrl(url) => url.distribution_id(),
FileLocation::Path(path) => path.distribution_id(),
Self::RelativeUrl(base, url) => (base.as_str(), url.as_str()).distribution_id(),
Self::AbsoluteUrl(url) => url.distribution_id(),
Self::Path(path) => path.distribution_id(),
}
}

fn resource_id(&self) -> ResourceId {
match self {
FileLocation::RelativeUrl(base, url) => (base.as_str(), url.as_str()).resource_id(),
FileLocation::AbsoluteUrl(url) => url.resource_id(),
FileLocation::Path(path) => path.resource_id(),
Self::RelativeUrl(base, url) => (base.as_str(), url.as_str()).resource_id(),
Self::AbsoluteUrl(url) => url.resource_id(),
Self::Path(path) => path.resource_id(),
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions crates/distribution-types/src/prioritized_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ impl Ord for WheelCompatibility {

impl PartialOrd for WheelCompatibility {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(WheelCompatibility::cmp(self, other))
Some(Self::cmp(self, other))
}
}

Expand All @@ -339,10 +339,8 @@ impl WheelCompatibility {
impl From<TagCompatibility> for WheelCompatibility {
fn from(value: TagCompatibility) -> Self {
match value {
TagCompatibility::Compatible(priority) => WheelCompatibility::Compatible(priority),
TagCompatibility::Incompatible(tag) => {
WheelCompatibility::Incompatible(IncompatibleWheel::Tag(tag))
}
TagCompatibility::Compatible(priority) => Self::Compatible(priority),
TagCompatibility::Incompatible(tag) => Self::Incompatible(IncompatibleWheel::Tag(tag)),
}
}
}
Loading

0 comments on commit 8d72183

Please sign in to comment.