Skip to content

Commit

Permalink
Remove unnecessary prefixes (#10158)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored Dec 25, 2024
1 parent 3cb7232 commit bec8468
Show file tree
Hide file tree
Showing 31 changed files with 124 additions and 175 deletions.
8 changes: 4 additions & 4 deletions crates/uv-auth/src/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl Credentials {
///
/// Any existing credentials will be overridden.
#[must_use]
pub(crate) fn authenticate(&self, mut request: reqwest::Request) -> reqwest::Request {
pub(crate) fn authenticate(&self, mut request: Request) -> Request {
request
.headers_mut()
.insert(reqwest::header::AUTHORIZATION, Self::to_header_value(self));
Expand Down Expand Up @@ -296,7 +296,7 @@ mod tests {
auth_url.set_password(Some("password")).unwrap();
let credentials = Credentials::from_url(&auth_url).unwrap();

let mut request = reqwest::Request::new(reqwest::Method::GET, url);
let mut request = Request::new(reqwest::Method::GET, url);
request = credentials.authenticate(request);

let mut header = request
Expand All @@ -318,7 +318,7 @@ mod tests {
auth_url.set_password(Some("password")).unwrap();
let credentials = Credentials::from_url(&auth_url).unwrap();

let mut request = reqwest::Request::new(reqwest::Method::GET, url);
let mut request = Request::new(reqwest::Method::GET, url);
request = credentials.authenticate(request);

let mut header = request
Expand All @@ -340,7 +340,7 @@ mod tests {
auth_url.set_password(Some("password==")).unwrap();
let credentials = Credentials::from_url(&auth_url).unwrap();

let mut request = reqwest::Request::new(reqwest::Method::GET, url);
let mut request = Request::new(reqwest::Method::GET, url);
request = credentials.authenticate(request);

let mut header = request
Expand Down
4 changes: 2 additions & 2 deletions crates/uv-client/src/cached_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub trait Cacheable: Sized {
/// Deserialize a value from bytes aligned to a 16-byte boundary.
fn from_aligned_bytes(bytes: AlignedVec) -> Result<Self::Target, Error>;
/// Serialize bytes to a possibly owned byte buffer.
fn to_bytes(&self) -> Result<Cow<'_, [u8]>, crate::Error>;
fn to_bytes(&self) -> Result<Cow<'_, [u8]>, Error>;
/// Convert this type into its final form.
fn into_target(self) -> Self::Target;
}
Expand Down Expand Up @@ -814,7 +814,7 @@ impl DataWithCachePolicy {
/// If the given byte buffer is not in a valid format or if the reader
/// fails, then this returns an error.
pub fn from_reader(mut rdr: impl std::io::Read) -> Result<Self, Error> {
let mut aligned_bytes = rkyv::util::AlignedVec::new();
let mut aligned_bytes = AlignedVec::new();
aligned_bytes
.extend_from_reader(&mut rdr)
.map_err(ErrorKind::Io)?;
Expand Down
9 changes: 3 additions & 6 deletions crates/uv-client/src/httpcache/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,7 @@ impl<'b, B: 'b + ?Sized + AsRef<[u8]>, I: Iterator<Item = &'b B>> CacheControlPa
/// given iterator should yield elements that satisfy `AsRef<[u8]>`.
fn new<II: IntoIterator<IntoIter = I>>(headers: II) -> CacheControlParser<'b, I> {
let mut directives = headers.into_iter();
let cur = directives
.next()
.map(std::convert::AsRef::as_ref)
.unwrap_or(b"");
let cur = directives.next().map(AsRef::as_ref).unwrap_or(b"");
CacheControlParser {
cur,
directives,
Expand Down Expand Up @@ -265,7 +262,7 @@ impl<'b, B: 'b + ?Sized + AsRef<[u8]>, I: Iterator<Item = &'b B>> CacheControlPa
self.cur = &self.cur[1..];
self.parse_quoted_string()
} else {
self.parse_token().map(std::string::String::into_bytes)
self.parse_token().map(String::into_bytes)
}
}

Expand Down Expand Up @@ -371,7 +368,7 @@ impl<'b, B: 'b + ?Sized + AsRef<[u8]>, I: Iterator<Item = &'b B>> Iterator
fn next(&mut self) -> Option<CacheControlDirective> {
loop {
if self.cur.is_empty() {
self.cur = self.directives.next().map(std::convert::AsRef::as_ref)?;
self.cur = self.directives.next().map(AsRef::as_ref)?;
}
while !self.cur.is_empty() {
self.skip_whitespace();
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-client/src/registry_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ mod tests {
.iter()
.map(|file| uv_pypi_types::base_url_join_relative(base.as_url().as_str(), &file.url))
.collect::<Result<Vec<_>, JoinRelativeError>>()?;
let urls = urls.iter().map(reqwest::Url::as_str).collect::<Vec<_>>();
let urls = urls.iter().map(Url::as_str).collect::<Vec<_>>();
insta::assert_debug_snapshot!(urls, @r###"
[
"https://account.d.codeartifact.us-west-2.amazonaws.com/pypi/shared-packages-pypi/simple/0.1/Flask-0.1.tar.gz#sha256=9da884457e910bf0847d396cb4b778ad9f3c3d17db1c5997cb861937bd284237",
Expand Down
6 changes: 3 additions & 3 deletions crates/uv-client/src/rkyvutil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ where
///
/// If the bytes fail validation (e.g., contains unaligned pointers or
/// strings aren't valid UTF-8), then this returns an error.
pub fn new(raw: rkyv::util::AlignedVec) -> Result<Self, Error> {
pub fn new(raw: AlignedVec) -> Result<Self, Error> {
// We convert the error to a simple string because... the error type
// does not implement Send. And I don't think we really need to keep
// the error type around anyway.
let _ = rkyv::access::<A::Archived, rkyv::rancor::Error>(&raw)
let _ = rkyv::access::<A::Archived, rancor::Error>(&raw)
.map_err(|e| ErrorKind::ArchiveRead(e.to_string()))?;
Ok(Self {
raw,
Expand All @@ -98,7 +98,7 @@ where
/// If the bytes fail validation (e.g., contains unaligned pointers or
/// strings aren't valid UTF-8), then this returns an error.
pub fn from_reader<R: std::io::Read>(mut rdr: R) -> Result<Self, Error> {
let mut buf = rkyv::util::AlignedVec::with_capacity(1024);
let mut buf = AlignedVec::with_capacity(1024);
buf.extend_from_reader(&mut rdr).map_err(ErrorKind::Io)?;
Self::new(buf)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-configuration/src/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub enum KeyringProviderType {
// See <https://pip.pypa.io/en/stable/topics/authentication/#keyring-support> for details.

impl KeyringProviderType {
pub fn to_provider(&self) -> Option<uv_auth::KeyringProvider> {
pub fn to_provider(&self) -> Option<KeyringProvider> {
match self {
Self::Disabled => None,
Self::Subprocess => Some(KeyringProvider::subprocess()),
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-configuration/src/trusted_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub enum TrustedHostError {
InvalidPort(String),
}

impl std::str::FromStr for TrustedHost {
impl FromStr for TrustedHost {
type Err = TrustedHostError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-distribution-types/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl FileLocation {
}

impl Display for FileLocation {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::RelativeUrl(_base, url) => Display::fmt(&url, f),
Self::AbsoluteUrl(url) => Display::fmt(&url.0, f),
Expand Down
16 changes: 4 additions & 12 deletions crates/uv-distribution-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,20 +1341,12 @@ mod test {
/// Ensure that we don't accidentally grow the `Dist` sizes.
#[test]
fn dist_size() {
assert!(size_of::<Dist>() <= 336, "{}", size_of::<Dist>());
assert!(size_of::<BuiltDist>() <= 336, "{}", size_of::<BuiltDist>());
assert!(
std::mem::size_of::<Dist>() <= 336,
size_of::<SourceDist>() <= 264,
"{}",
std::mem::size_of::<Dist>()
);
assert!(
std::mem::size_of::<BuiltDist>() <= 336,
"{}",
std::mem::size_of::<BuiltDist>()
);
assert!(
std::mem::size_of::<SourceDist>() <= 264,
"{}",
std::mem::size_of::<SourceDist>()
size_of::<SourceDist>()
);
}

Expand Down
4 changes: 2 additions & 2 deletions crates/uv-install-wheel/src/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ fn copy_wheel_files(
let mut count = 0usize;

// Walk over the directory.
for entry in walkdir::WalkDir::new(&wheel) {
for entry in WalkDir::new(&wheel) {
let entry = entry?;
let path = entry.path();

Expand Down Expand Up @@ -499,7 +499,7 @@ fn hardlink_wheel_files(
let mut count = 0usize;

// Walk over the directory.
for entry in walkdir::WalkDir::new(&wheel) {
for entry in WalkDir::new(&wheel) {
let entry = entry?;
let path = entry.path();

Expand Down
6 changes: 3 additions & 3 deletions crates/uv-macros/src/options_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub(crate) fn derive_impl(input: DeriveInput) -> syn::Result<TokenStream> {
/// For a field with type `Option<Foobar>` where `Foobar` itself is a struct
/// deriving `ConfigurationOptions`, create code that calls retrieves options
/// from that group: `Foobar::get_available_options()`
fn handle_option_group(field: &Field) -> syn::Result<proc_macro2::TokenStream> {
fn handle_option_group(field: &Field) -> syn::Result<TokenStream> {
let ident = field
.ident
.as_ref()
Expand Down Expand Up @@ -145,7 +145,7 @@ fn handle_option_group(field: &Field) -> syn::Result<proc_macro2::TokenStream> {
/// Parse a `doc` attribute into it a string literal.
fn parse_doc(doc: &Attribute) -> syn::Result<String> {
match &doc.meta {
syn::Meta::NameValue(syn::MetaNameValue {
Meta::NameValue(syn::MetaNameValue {
value:
syn::Expr::Lit(ExprLit {
lit: Lit::Str(lit_str),
Expand All @@ -159,7 +159,7 @@ fn parse_doc(doc: &Attribute) -> syn::Result<String> {

/// Parse an `#[option(doc="...", default="...", value_type="...",
/// example="...")]` attribute and return data in the form of an `OptionField`.
fn handle_option(field: &Field, attr: &Attribute) -> syn::Result<proc_macro2::TokenStream> {
fn handle_option(field: &Field, attr: &Attribute) -> syn::Result<TokenStream> {
let docs: Vec<&Attribute> = field
.attrs
.iter()
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-normalize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn is_normalized(name: impl AsRef<str>) -> Result<bool, InvalidNameError> {
Ok(true)
}

/// Invalid [`crate::PackageName`] or [`crate::ExtraName`].
/// Invalid [`PackageName`] or [`ExtraName`].
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct InvalidNameError(String);

Expand Down
2 changes: 1 addition & 1 deletion crates/uv-pep440/src/version_ranges.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Convert [`VersionSpecifiers`] to [`version_ranges::Ranges`].
//! Convert [`VersionSpecifiers`] to [`Ranges`].
use version_ranges::Ranges;

Expand Down
2 changes: 1 addition & 1 deletion crates/uv-pep440/src/version_specifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ impl VersionSpecifier {
Operator::ExactEqual => {
#[cfg(feature = "tracing")]
{
tracing::warn!("Using arbitrary equality (`===`) is discouraged");
warn!("Using arbitrary equality (`===`) is discouraged");
}
self.version.to_string() == version.to_string()
}
Expand Down
13 changes: 5 additions & 8 deletions crates/uv-pep508/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,12 @@ impl<T: Pep508Url> Requirement<T> {
}
}

/// Type to parse URLs from `name @ <url>` into. Defaults to [`url::Url`].
/// Type to parse URLs from `name @ <url>` into. Defaults to [`Url`].
pub trait Pep508Url: Display + Debug + Sized {
/// String to URL parsing error
type Err: Error + Debug;

/// Parse a url from `name @ <url>`. Defaults to [`url::Url::parse_url`].
/// Parse a url from `name @ <url>`. Defaults to [`Url::parse_url`].
fn parse_url(url: &str, working_dir: Option<&Path>) -> Result<Self, Self::Err>;
}

Expand Down Expand Up @@ -1069,7 +1069,7 @@ mod tests {
marker: MarkerTree::expression(MarkerExpression::Version {
key: MarkerValueVersion::PythonFullVersion,
specifier: VersionSpecifier::from_pattern(
uv_pep440::Operator::LessThan,
Operator::LessThan,
"2.7".parse().unwrap(),
)
.unwrap(),
Expand Down Expand Up @@ -1333,11 +1333,8 @@ mod tests {

let mut a = MarkerTree::expression(MarkerExpression::Version {
key: MarkerValueVersion::PythonVersion,
specifier: VersionSpecifier::from_pattern(
uv_pep440::Operator::Equal,
"2.7".parse().unwrap(),
)
.unwrap(),
specifier: VersionSpecifier::from_pattern(Operator::Equal, "2.7".parse().unwrap())
.unwrap(),
});
let mut b = MarkerTree::expression(MarkerExpression::String {
key: MarkerValueString::SysPlatform,
Expand Down
22 changes: 11 additions & 11 deletions crates/uv-pep508/src/marker/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub enum MarkerValueVersion {
}

impl Display for MarkerValueVersion {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::ImplementationVersion => f.write_str("implementation_version"),
Self::PythonFullVersion => f.write_str("python_full_version"),
Expand Down Expand Up @@ -97,7 +97,7 @@ pub enum MarkerValueString {

impl Display for MarkerValueString {
/// Normalizes deprecated names to the proper ones
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::ImplementationName => f.write_str("implementation_name"),
Self::OsName | Self::OsNameDeprecated => f.write_str("os_name"),
Expand Down Expand Up @@ -175,7 +175,7 @@ impl FromStr for MarkerValue {
}

impl Display for MarkerValue {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::MarkerEnvVersion(marker_value_version) => marker_value_version.fmt(f),
Self::MarkerEnvString(marker_value_string) => marker_value_string.fmt(f),
Expand Down Expand Up @@ -341,7 +341,7 @@ impl FromStr for MarkerOperator {
}

impl Display for MarkerOperator {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Equal => "==",
Self::NotEqual => "!=",
Expand Down Expand Up @@ -386,7 +386,7 @@ impl FromStr for StringVersion {
}

impl Display for StringVersion {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
self.string.fmt(f)
}
}
Expand Down Expand Up @@ -446,7 +446,7 @@ impl MarkerValueExtra {
}

impl Display for MarkerValueExtra {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::Extra(extra) => extra.fmt(f),
Self::Arbitrary(string) => string.fmt(f),
Expand Down Expand Up @@ -538,7 +538,7 @@ impl ExtraOperator {
}

impl Display for ExtraOperator {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Equal => "==",
Self::NotEqual => "!=",
Expand Down Expand Up @@ -590,7 +590,7 @@ impl MarkerExpression {
}

impl Display for MarkerExpression {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
MarkerExpression::Version { key, specifier } => {
let (op, version) = (specifier.operator(), specifier.version());
Expand Down Expand Up @@ -1198,7 +1198,7 @@ impl MarkerTree {
MarkerTreeDebugRaw { marker: self }
}

fn fmt_graph(self, f: &mut fmt::Formatter<'_>, level: usize) -> fmt::Result {
fn fmt_graph(self, f: &mut Formatter<'_>, level: usize) -> fmt::Result {
match self.kind() {
MarkerTreeKind::True => return write!(f, "true"),
MarkerTreeKind::False => return write!(f, "false"),
Expand Down Expand Up @@ -1296,7 +1296,7 @@ pub struct MarkerTreeDebugGraph<'a> {
}

impl fmt::Debug for MarkerTreeDebugGraph<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
self.marker.fmt_graph(f, 0)
}
}
Expand All @@ -1313,7 +1313,7 @@ pub struct MarkerTreeDebugRaw<'a> {
}

impl fmt::Debug for MarkerTreeDebugRaw<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let node = INTERNER.shared.node(self.marker.0);
f.debug_tuple("MarkerTreeDebugRaw").field(node).finish()
}
Expand Down
Loading

0 comments on commit bec8468

Please sign in to comment.