فهرست منبع

Appease clippy

This commit appeases clippy by fixing all of the issues it flagged.
Luca Casonato 4 سال پیش
والد
کامیت
e398b2c5f1
7فایلهای تغییر یافته به همراه11 افزوده شده و 17 حذف شده
  1. 2 2
      idna/src/uts46.rs
  2. 2 2
      idna/tests/uts46.rs
  3. 1 1
      url/src/host.rs
  4. 1 1
      url/src/lib.rs
  5. 1 1
      url/src/parser.rs
  6. 3 9
      url/src/quirks.rs
  7. 1 1
      url/tests/unit.rs

+ 2 - 2
idna/src/uts46.rs

@@ -156,7 +156,7 @@ fn passes_bidi(label: &str, is_bidi_domain: bool) -> bool {
         // LTR label
         BidiClass::L => {
             // Rule 5
-            while let Some(c) = chars.next() {
+            for c in chars.by_ref() {
                 if !matches!(
                     bidi_class(c),
                     BidiClass::L
@@ -396,7 +396,7 @@ fn processing(
                     }
 
                     if !errors.is_err() {
-                        if !is_nfc(&decoded_label) {
+                        if !is_nfc(decoded_label) {
                             errors.nfc = true;
                         } else {
                             check_validity(decoded_label, non_transitional, &mut errors);

+ 2 - 2
idna/tests/uts46.rs

@@ -25,10 +25,10 @@ pub fn collect_tests<F: FnMut(String, TestFn)>(add_test: &mut F) {
         };
 
         let mut pieces = line.split(';').map(|x| x.trim()).collect::<Vec<&str>>();
-        let source = unescape(&pieces.remove(0));
+        let source = unescape(pieces.remove(0));
 
         // ToUnicode
-        let mut to_unicode = unescape(&pieces.remove(0));
+        let mut to_unicode = unescape(pieces.remove(0));
         if to_unicode.is_empty() {
             to_unicode = source.clone();
         }

+ 1 - 1
url/src/host.rs

@@ -162,7 +162,7 @@ impl Host<String> {
     /// convert domain with idna
     #[cfg(feature = "idna")]
     fn domain_to_ascii(domain: &str) -> Result<String, ParseError> {
-        idna::domain_to_ascii(&domain).map_err(Into::into)
+        idna::domain_to_ascii(domain).map_err(Into::into)
     }
 
     /// checks domain is ascii

+ 1 - 1
url/src/lib.rs

@@ -1361,7 +1361,7 @@ impl Url {
     }
 
     fn mutate<F: FnOnce(&mut Parser<'_>) -> R, R>(&mut self, f: F) -> R {
-        let mut parser = Parser::for_setter(mem::replace(&mut self.serialization, String::new()));
+        let mut parser = Parser::for_setter(mem::take(&mut self.serialization));
         let result = f(&mut parser);
         self.serialization = parser.serialization;
         result

+ 1 - 1
url/src/parser.rs

@@ -1293,7 +1293,7 @@ impl<'a> Parser<'a> {
             //FIXME: log violation
             let path = self.serialization.split_off(path_start);
             self.serialization.push('/');
-            self.serialization.push_str(&path.trim_start_matches('/'));
+            self.serialization.push_str(path.trim_start_matches('/'));
         }
 
         input

+ 3 - 9
url/src/quirks.rs

@@ -139,14 +139,8 @@ pub fn set_host(url: &mut Url, new_host: &str) -> Result<(), ()> {
         }
     }
     // Make sure we won't set an empty host to a url with a username or a port
-    if host == Host::Domain("".to_string()) {
-        if !username(&url).is_empty() {
+    if host == Host::Domain("".to_string())  && (!username(url).is_empty() || matches!(opt_port, Some(Some(_))) || url.port().is_some()) {
             return Err(());
-        } else if let Some(Some(_)) = opt_port {
-            return Err(());
-        } else if url.port().is_some() {
-            return Err(());
-        }
     }
     url.set_host_internal(host, opt_port);
     Ok(())
@@ -178,10 +172,10 @@ pub fn set_hostname(url: &mut Url, new_hostname: &str) -> Result<(), ()> {
                 // Empty host on special not file url
                 if SchemeType::from(url.scheme()) == SchemeType::SpecialNotFile
                     // Port with an empty host
-                    ||!port(&url).is_empty()
+                    ||!port(url).is_empty()
                     // Empty host that includes credentials
                     || !url.username().is_empty()
-                    || !url.password().unwrap_or(&"").is_empty()
+                    || !url.password().unwrap_or("").is_empty()
                 {
                     return Err(());
                 }

+ 1 - 1
url/tests/unit.rs

@@ -1096,7 +1096,7 @@ fn test_make_relative() {
             base, uri, relative
         );
         assert_eq!(
-            base_uri.join(&relative).unwrap().as_str(),
+            base_uri.join(relative).unwrap().as_str(),
             *uri,
             "base: {}, uri: {}, relative: {}",
             base,