Procházet zdrojové kódy

ran `cargo clippy --fix -- -Wclippy::use_self` (#1048)

Co-authored-by: adamnemecek <adamnemecek@gmail.com>
Martin Robinson před 1 rokem
rodič
revize
dbd526178e

+ 1 - 1
data-url/src/forgiving_base64.rs

@@ -52,7 +52,7 @@ impl<E: std::error::Error> std::error::Error for DecodeError<E> {}
 
 impl<E> From<InvalidBase64Details> for DecodeError<E> {
     fn from(e: InvalidBase64Details) -> Self {
-        DecodeError::InvalidBase64(InvalidBase64(e))
+        Self::InvalidBase64(InvalidBase64(e))
     }
 }
 

+ 1 - 1
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

+ 1 - 1
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,

+ 1 - 1
idna/src/lib.rs

@@ -66,7 +66,7 @@ pub use crate::deprecated::{Config, Idna};
 pub struct Errors {}
 
 impl From<Errors> for Result<(), Errors> {
-    fn from(e: Errors) -> Result<(), Errors> {
+    fn from(e: Errors) -> Self {
         Err(e)
     }
 }

+ 1 - 1
idna/src/punycode.rs

@@ -350,7 +350,7 @@ pub(crate) enum PunycodeEncodeError {
 
 impl From<core::fmt::Error> for PunycodeEncodeError {
     fn from(_: core::fmt::Error) -> Self {
-        PunycodeEncodeError::Sink
+        Self::Sink
     }
 }
 

+ 5 - 5
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<core::fmt::Error> for ProcessingError {
     fn from(_: core::fmt::Error) -> Self {
-        ProcessingError::SinkError
+        Self::SinkError
     }
 }
 

+ 5 - 5
percent_encoding/src/ascii_set.rs

@@ -37,7 +37,7 @@ const BITS_PER_CHUNK: usize = 8 * mem::size_of::<Chunk>();
 
 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 }
     }
 }
 

+ 1 - 1
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

+ 11 - 11
url/src/host.rs

@@ -30,12 +30,12 @@ pub(crate) enum HostInternal {
 }
 
 impl From<Host<Cow<'_, str>>> for HostInternal {
-    fn from(host: Host<Cow<'_, str>>) -> HostInternal {
+    fn from(host: Host<Cow<'_, str>>) -> 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<Cow<'a, str>> {
 impl<S: AsRef<str>> fmt::Display for Host<S> {
     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<T>) -> 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,
         }
     }

+ 16 - 16
url/src/lib.rs

@@ -338,8 +338,8 @@ impl Url {
     ///
     /// [`ParseError`]: enum.ParseError.html
     #[inline]
-    pub fn parse(input: &str) -> Result<Url, crate::ParseError> {
-        Url::options().parse(input)
+    pub fn parse(input: &str) -> Result<Self, crate::ParseError> {
+        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<I, K, V>(input: &str, iter: I) -> Result<Url, crate::ParseError>
+    pub fn parse_with_params<I, K, V>(input: &str, iter: I) -> Result<Self, crate::ParseError>
     where
         I: IntoIterator,
         I::Item: Borrow<(K, V)>,
         K: AsRef<str>,
         V: AsRef<str>,
     {
-        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, crate::ParseError> {
-        Url::options().base_url(Some(self)).parse(input)
+    pub fn join(&self, input: &str) -> Result<Self, crate::ParseError> {
+        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<String> {
+    pub fn make_relative(&self, url: &Self) -> Option<String> {
         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<P: AsRef<std::path::Path>>(path: P) -> Result<Url, ()> {
+    pub fn from_file_path<P: AsRef<std::path::Path>>(path: P) -> Result<Self, ()> {
         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<P: AsRef<std::path::Path>>(path: P) -> Result<Url, ()> {
-        let mut url = Url::from_file_path(path)?;
+    pub fn from_directory_path<P: AsRef<std::path::Path>>(path: P) -> Result<Self, ()> {
+        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, crate::ParseError> {
-        Url::parse(input)
+    fn from_str(input: &str) -> Result<Self, crate::ParseError> {
+        Self::parse(input)
     }
 }
 
@@ -2780,7 +2780,7 @@ impl<'a> TryFrom<&'a str> for Url {
     type Error = ParseError;
 
     fn try_from(s: &'a str) -> Result<Self, Self::Error> {
-        Url::parse(s)
+        Self::parse(s)
     }
 }
 
@@ -2794,7 +2794,7 @@ impl fmt::Display for Url {
 
 /// String conversion.
 impl From<Url> for String {
-    fn from(value: Url) -> String {
+    fn from(value: Url) -> Self {
         value.serialization
     }
 }

+ 7 - 7
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(..))
     }
 
     /// <https://html.spec.whatwg.org/multipage/#ascii-serialisation-of-an-origin>
     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 {
     /// <https://html.spec.whatwg.org/multipage/#unicode-serialisation-of-an-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);

+ 9 - 9
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<T: AsRef<str>> From<T> 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,