From 1111bb477c0d4c78c7c8d6354ec6615d520b6730 Mon Sep 17 00:00:00 2001 From: adamnemecek Date: Thu, 8 May 2025 09:26:00 -0700 Subject: [PATCH] ran `cargo clippy --fix -- -Wclippy::use_self` --- data-url/src/forgiving_base64.rs | 2 +- form_urlencoded/src/lib.rs | 2 +- idna/src/deprecated.rs | 2 +- idna/src/lib.rs | 2 +- idna/src/punycode.rs | 2 +- idna/src/uts46.rs | 10 +++++----- percent_encoding/src/ascii_set.rs | 10 +++++----- percent_encoding/src/lib.rs | 2 +- url/src/host.rs | 22 ++++++++++----------- url/src/lib.rs | 32 +++++++++++++++---------------- url/src/origin.rs | 14 +++++++------- url/src/parser.rs | 18 ++++++++--------- 12 files changed, 59 insertions(+), 59 deletions(-) diff --git a/data-url/src/forgiving_base64.rs b/data-url/src/forgiving_base64.rs index ed713d8e1..600b8c52d 100644 --- a/data-url/src/forgiving_base64.rs +++ b/data-url/src/forgiving_base64.rs @@ -52,7 +52,7 @@ impl std::error::Error for DecodeError {} impl From for DecodeError { fn from(e: InvalidBase64Details) -> Self { - DecodeError::InvalidBase64(InvalidBase64(e)) + Self::InvalidBase64(InvalidBase64(e)) } } diff --git a/form_urlencoded/src/lib.rs b/form_urlencoded/src/lib.rs index 1d9582249..639545ae6 100644 --- a/form_urlencoded/src/lib.rs +++ b/form_urlencoded/src/lib.rs @@ -414,7 +414,7 @@ pub(crate) fn decode_utf8_lossy(input: Cow<'_, [u8]>) -> Cow<'_, str> { // First we do a debug_assert to confirm our description above. let raw_utf8: *const [u8] = utf8.as_bytes(); - debug_assert!(raw_utf8 == &*bytes as *const [u8]); + debug_assert!(core::ptr::eq(raw_utf8, &*bytes)); // Given we know the original input bytes are valid UTF-8, // and we have ownership of those bytes, we re-use them and diff --git a/idna/src/deprecated.rs b/idna/src/deprecated.rs index 534262cae..dd1a55205 100644 --- a/idna/src/deprecated.rs +++ b/idna/src/deprecated.rs @@ -142,7 +142,7 @@ pub struct Config { /// The defaults are that of _beStrict=false_ in the [WHATWG URL Standard](https://url.spec.whatwg.org/#idna) impl Default for Config { fn default() -> Self { - Config { + Self { use_std3_ascii_rules: false, transitional_processing: false, check_hyphens: false, diff --git a/idna/src/lib.rs b/idna/src/lib.rs index 81f315a0d..0730ec6be 100644 --- a/idna/src/lib.rs +++ b/idna/src/lib.rs @@ -66,7 +66,7 @@ pub use crate::deprecated::{Config, Idna}; pub struct Errors {} impl From for Result<(), Errors> { - fn from(e: Errors) -> Result<(), Errors> { + fn from(e: Errors) -> Self { Err(e) } } diff --git a/idna/src/punycode.rs b/idna/src/punycode.rs index 7194c32c6..ff7b6adac 100644 --- a/idna/src/punycode.rs +++ b/idna/src/punycode.rs @@ -350,7 +350,7 @@ pub(crate) enum PunycodeEncodeError { impl From for PunycodeEncodeError { fn from(_: core::fmt::Error) -> Self { - PunycodeEncodeError::Sink + Self::Sink } } diff --git a/idna/src/uts46.rs b/idna/src/uts46.rs index 9a450fa08..79223a2cc 100644 --- a/idna/src/uts46.rs +++ b/idna/src/uts46.rs @@ -319,7 +319,7 @@ impl AsciiDenyList { bits |= 1u128 << b; i += 1; } - AsciiDenyList { bits } + Self { bits } } /// No ASCII deny list. This corresponds to _UseSTD3ASCIIRules=false_. @@ -332,14 +332,14 @@ impl AsciiDenyList { /// but it's more efficient to use `AsciiDenyList` than post-processing, /// because the internals of this crate can optimize away checks in /// certain cases. - pub const EMPTY: AsciiDenyList = AsciiDenyList::new(false, ""); + pub const EMPTY: Self = Self::new(false, ""); /// The STD3 deny list. This corresponds to _UseSTD3ASCIIRules=true_. /// /// Note that this deny list rejects the underscore, which occurs in /// pseudo-hosts used by various TXT record-based protocols, and also /// characters that may occurs in non-DNS naming, such as NetBIOS. - pub const STD3: AsciiDenyList = AsciiDenyList { bits: ldh_mask() }; + pub const STD3: Self = Self { bits: ldh_mask() }; /// [Forbidden domain code point](https://url.spec.whatwg.org/#forbidden-domain-code-point) from the WHATWG URL Standard. /// @@ -348,7 +348,7 @@ impl AsciiDenyList { /// Note that this deny list rejects IPv6 addresses, so (as in URL /// parsing) you need to check for IPv6 addresses first and not /// put them through UTS 46 processing. - pub const URL: AsciiDenyList = AsciiDenyList::new(true, "%#/:<>?@[\\]^|"); + pub const URL: Self = Self::new(true, "%#/:<>?@[\\]^|"); } /// The _CheckHyphens_ mode. @@ -434,7 +434,7 @@ pub enum ProcessingError { impl From for ProcessingError { fn from(_: core::fmt::Error) -> Self { - ProcessingError::SinkError + Self::SinkError } } diff --git a/percent_encoding/src/ascii_set.rs b/percent_encoding/src/ascii_set.rs index 41cd235e2..26c66dde7 100644 --- a/percent_encoding/src/ascii_set.rs +++ b/percent_encoding/src/ascii_set.rs @@ -37,7 +37,7 @@ const BITS_PER_CHUNK: usize = 8 * mem::size_of::(); impl AsciiSet { /// An empty set. - pub const EMPTY: AsciiSet = AsciiSet { + pub const EMPTY: Self = Self { mask: [0; ASCII_RANGE_LEN / BITS_PER_CHUNK], }; @@ -56,13 +56,13 @@ impl AsciiSet { pub const fn add(&self, byte: u8) -> Self { let mut mask = self.mask; mask[byte as usize / BITS_PER_CHUNK] |= 1 << (byte as usize % BITS_PER_CHUNK); - AsciiSet { mask } + Self { mask } } pub const fn remove(&self, byte: u8) -> Self { let mut mask = self.mask; mask[byte as usize / BITS_PER_CHUNK] &= !(1 << (byte as usize % BITS_PER_CHUNK)); - AsciiSet { mask } + Self { mask } } /// Return the union of two sets. @@ -73,13 +73,13 @@ impl AsciiSet { self.mask[2] | other.mask[2], self.mask[3] | other.mask[3], ]; - AsciiSet { mask } + Self { mask } } /// Return the negation of the set. pub const fn complement(&self) -> Self { let mask = [!self.mask[0], !self.mask[1], !self.mask[2], !self.mask[3]]; - AsciiSet { mask } + Self { mask } } } diff --git a/percent_encoding/src/lib.rs b/percent_encoding/src/lib.rs index f4b23af61..ee36e0c5a 100644 --- a/percent_encoding/src/lib.rs +++ b/percent_encoding/src/lib.rs @@ -351,7 +351,7 @@ fn decode_utf8_lossy(input: Cow<'_, [u8]>) -> Cow<'_, str> { // First we do a debug_assert to confirm our description above. let raw_utf8: *const [u8] = utf8.as_bytes(); - debug_assert!(raw_utf8 == &*bytes as *const [u8]); + debug_assert!(core::ptr::eq(raw_utf8, &*bytes)); // Given we know the original input bytes are valid UTF-8, // and we have ownership of those bytes, we re-use them and diff --git a/url/src/host.rs b/url/src/host.rs index 7443412ea..bfe1e2c9e 100644 --- a/url/src/host.rs +++ b/url/src/host.rs @@ -30,12 +30,12 @@ pub(crate) enum HostInternal { } impl From>> for HostInternal { - fn from(host: Host>) -> HostInternal { + fn from(host: Host>) -> Self { match host { - Host::Domain(ref s) if s.is_empty() => HostInternal::None, - Host::Domain(_) => HostInternal::Domain, - Host::Ipv4(address) => HostInternal::Ipv4(address), - Host::Ipv6(address) => HostInternal::Ipv6(address), + Host::Domain(ref s) if s.is_empty() => Self::None, + Host::Domain(_) => Self::Domain, + Host::Ipv4(address) => Self::Ipv4(address), + Host::Ipv6(address) => Self::Ipv6(address), } } } @@ -175,9 +175,9 @@ impl<'a> Host> { impl> fmt::Display for Host { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match *self { - Host::Domain(ref domain) => domain.as_ref().fmt(f), - Host::Ipv4(ref addr) => addr.fmt(f), - Host::Ipv6(ref addr) => { + Self::Domain(ref domain) => domain.as_ref().fmt(f), + Self::Ipv4(ref addr) => addr.fmt(f), + Self::Ipv6(ref addr) => { f.write_str("[")?; write_ipv6(addr, f)?; f.write_str("]") @@ -192,9 +192,9 @@ where { fn eq(&self, other: &Host) -> bool { match (self, other) { - (Host::Domain(a), Host::Domain(b)) => a == b, - (Host::Ipv4(a), Host::Ipv4(b)) => a == b, - (Host::Ipv6(a), Host::Ipv6(b)) => a == b, + (Self::Domain(a), Host::Domain(b)) => a == b, + (Self::Ipv4(a), Host::Ipv4(b)) => a == b, + (Self::Ipv6(a), Host::Ipv6(b)) => a == b, (_, _) => false, } } diff --git a/url/src/lib.rs b/url/src/lib.rs index 98489941d..3a3c9c14b 100644 --- a/url/src/lib.rs +++ b/url/src/lib.rs @@ -338,8 +338,8 @@ impl Url { /// /// [`ParseError`]: enum.ParseError.html #[inline] - pub fn parse(input: &str) -> Result { - Url::options().parse(input) + pub fn parse(input: &str) -> Result { + Self::options().parse(input) } /// Parse an absolute URL from a string and add params to its query string. @@ -368,14 +368,14 @@ impl Url { /// /// [`ParseError`]: enum.ParseError.html #[inline] - pub fn parse_with_params(input: &str, iter: I) -> Result + pub fn parse_with_params(input: &str, iter: I) -> Result where I: IntoIterator, I::Item: Borrow<(K, V)>, K: AsRef, V: AsRef, { - let mut url = Url::options().parse(input); + let mut url = Self::options().parse(input); if let Ok(ref mut url) = url { url.query_pairs_mut().extend_pairs(iter); @@ -468,8 +468,8 @@ impl Url { /// [`ParseError`]: enum.ParseError.html /// [`make_relative`]: #method.make_relative #[inline] - pub fn join(&self, input: &str) -> Result { - Url::options().base_url(Some(self)).parse(input) + pub fn join(&self, input: &str) -> Result { + Self::options().base_url(Some(self)).parse(input) } /// Creates a relative URL if possible, with this URL as the base URL. @@ -513,7 +513,7 @@ impl Url { /// This is for example the case if the scheme, host or port are not the same. /// /// [`join`]: #method.join - pub fn make_relative(&self, url: &Url) -> Option { + pub fn make_relative(&self, url: &Self) -> Option { if self.cannot_be_a_base() { return None; } @@ -789,7 +789,7 @@ impl Url { assert!(fragment_start > query_start); } - let other = Url::parse(self.as_str()).expect("Failed to parse myself?"); + let other = Self::parse(self.as_str()).expect("Failed to parse myself?"); assert_eq!(&self.serialization, &other.serialization); assert_eq!(self.scheme_end, other.scheme_end); assert_eq!(self.username_end, other.username_end); @@ -2543,11 +2543,11 @@ impl Url { ) ))] #[allow(clippy::result_unit_err)] - pub fn from_file_path>(path: P) -> Result { + pub fn from_file_path>(path: P) -> Result { let mut serialization = "file://".to_owned(); let host_start = serialization.len() as u32; let (host_end, host) = path_to_file_url_segments(path.as_ref(), &mut serialization)?; - Ok(Url { + Ok(Self { serialization, scheme_end: "file".len() as u32, username_end: host_start, @@ -2591,8 +2591,8 @@ impl Url { ) ))] #[allow(clippy::result_unit_err)] - pub fn from_directory_path>(path: P) -> Result { - let mut url = Url::from_file_path(path)?; + pub fn from_directory_path>(path: P) -> Result { + let mut url = Self::from_file_path(path)?; if !url.serialization.ends_with('/') { url.serialization.push('/') } @@ -2771,8 +2771,8 @@ impl str::FromStr for Url { type Err = ParseError; #[inline] - fn from_str(input: &str) -> Result { - Url::parse(input) + fn from_str(input: &str) -> Result { + Self::parse(input) } } @@ -2780,7 +2780,7 @@ impl<'a> TryFrom<&'a str> for Url { type Error = ParseError; fn try_from(s: &'a str) -> Result { - Url::parse(s) + Self::parse(s) } } @@ -2794,7 +2794,7 @@ impl fmt::Display for Url { /// String conversion. impl From for String { - fn from(value: Url) -> String { + fn from(value: Url) -> Self { value.serialization } } diff --git a/url/src/origin.rs b/url/src/origin.rs index a039f4529..5b5cf4377 100644 --- a/url/src/origin.rs +++ b/url/src/origin.rs @@ -63,22 +63,22 @@ pub enum Origin { impl Origin { /// Creates a new opaque origin that is only equal to itself. - pub fn new_opaque() -> Origin { + pub fn new_opaque() -> Self { static COUNTER: AtomicUsize = AtomicUsize::new(0); - Origin::Opaque(OpaqueOrigin(COUNTER.fetch_add(1, Ordering::SeqCst))) + Self::Opaque(OpaqueOrigin(COUNTER.fetch_add(1, Ordering::SeqCst))) } /// Return whether this origin is a (scheme, host, port) tuple /// (as opposed to an opaque origin). pub fn is_tuple(&self) -> bool { - matches!(*self, Origin::Tuple(..)) + matches!(*self, Self::Tuple(..)) } /// pub fn ascii_serialization(&self) -> String { match *self { - Origin::Opaque(_) => "null".to_owned(), - Origin::Tuple(ref scheme, ref host, port) => { + Self::Opaque(_) => "null".to_owned(), + Self::Tuple(ref scheme, ref host, port) => { if default_port(scheme) == Some(port) { format!("{}://{}", scheme, host) } else { @@ -91,8 +91,8 @@ impl Origin { /// pub fn unicode_serialization(&self) -> String { match *self { - Origin::Opaque(_) => "null".to_owned(), - Origin::Tuple(ref scheme, ref host, port) => { + Self::Opaque(_) => "null".to_owned(), + Self::Tuple(ref scheme, ref host, port) => { let host = match *host { Host::Domain(ref domain) => { let (domain, _errors) = idna::domain_to_unicode(domain); diff --git a/url/src/parser.rs b/url/src/parser.rs index d4e3fdb88..6d44aa60b 100644 --- a/url/src/parser.rs +++ b/url/src/parser.rs @@ -99,8 +99,8 @@ simple_enum_error! { } impl From<::idna::Errors> for ParseError { - fn from(_: ::idna::Errors) -> ParseError { - ParseError::IdnaError + fn from(_: ::idna::Errors) -> Self { + Self::IdnaError } } @@ -165,20 +165,20 @@ pub enum SchemeType { impl SchemeType { pub fn is_special(&self) -> bool { - !matches!(*self, SchemeType::NotSpecial) + !matches!(*self, Self::NotSpecial) } pub fn is_file(&self) -> bool { - matches!(*self, SchemeType::File) + matches!(*self, Self::File) } } impl> From for SchemeType { fn from(s: T) -> Self { match s.as_ref() { - "http" | "https" | "ws" | "wss" | "ftp" => SchemeType::SpecialNotFile, - "file" => SchemeType::File, - _ => SchemeType::NotSpecial, + "http" | "https" | "ws" | "wss" | "ftp" => Self::SpecialNotFile, + "file" => Self::File, + _ => Self::NotSpecial, } } } @@ -350,7 +350,7 @@ pub enum Context { PathSegmentSetter, } -impl<'a> Parser<'a> { +impl Parser<'_> { fn log_violation(&self, v: SyntaxViolation) { if let Some(f) = self.violation_fn { f(v) @@ -365,7 +365,7 @@ impl<'a> Parser<'a> { } } - pub fn for_setter(serialization: String) -> Parser<'a> { + pub fn for_setter(serialization: String) -> Self { Parser { serialization, base_url: None,