Procházet zdrojové kódy

Merge pull request #744 from lucacasonato/fix_clippy

Appease clippy
Valentin Gosu před 4 roky
rodič
revize
bd150e3e0c
7 změnil soubory, kde provedl 21 přidání a 24 odebrání
  1. 2 2
      idna/src/uts46.rs
  2. 2 2
      idna/tests/uts46.rs
  3. 1 1
      url/src/host.rs
  4. 8 7
      url/src/lib.rs
  5. 1 1
      url/src/parser.rs
  6. 6 10
      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

+ 8 - 7
url/src/lib.rs

@@ -1361,6 +1361,7 @@ impl Url {
     }
 
     fn mutate<F: FnOnce(&mut Parser<'_>) -> R, R>(&mut self, f: F) -> R {
+        #[allow(clippy::mem_replace_with_default)] // introduced in 1.40, MSRV is 1.36
         let mut parser = Parser::for_setter(mem::replace(&mut self.serialization, String::new()));
         let result = f(&mut parser);
         self.serialization = parser.serialization;
@@ -1551,19 +1552,19 @@ impl Url {
     /// url.set_path("data/report.csv");
     /// assert_eq!(url.as_str(), "https://example.com/data/report.csv");
     /// assert_eq!(url.path(), "/data/report.csv");
-    /// 
+    ///
     /// // `set_path` percent-encodes the given string if it's not already percent-encoded.
     /// let mut url = Url::parse("https://example.com")?;
     /// url.set_path("api/some comments");
     /// assert_eq!(url.as_str(), "https://example.com/api/some%20comments");
     /// assert_eq!(url.path(), "/api/some%20comments");
-    /// 
+    ///
     /// // `set_path` will not double percent-encode the string if it's already percent-encoded.
     /// let mut url = Url::parse("https://example.com")?;
     /// url.set_path("api/some%20comments");
     /// assert_eq!(url.as_str(), "https://example.com/api/some%20comments");
     /// assert_eq!(url.path(), "/api/some%20comments");
-    /// 
+    ///
     /// # Ok(())
     /// # }
     /// # run().unwrap();
@@ -2684,9 +2685,9 @@ fn path_to_file_url_segments(
     path: &Path,
     serialization: &mut String,
 ) -> Result<(u32, HostInternal), ()> {
-    #[cfg(any(unix, target_os = "redox"))]    
+    #[cfg(any(unix, target_os = "redox"))]
     use std::os::unix::prelude::OsStrExt;
-    #[cfg(target_os = "wasi")]    
+    #[cfg(target_os = "wasi")]
     use std::os::wasi::prelude::OsStrExt;
     if !path.is_absolute() {
         return Err(());
@@ -2783,9 +2784,9 @@ fn file_url_segments_to_pathbuf(
     segments: str::Split<'_, char>,
 ) -> Result<PathBuf, ()> {
     use std::ffi::OsStr;
-    #[cfg(any(unix, target_os = "redox"))]    
+    #[cfg(any(unix, target_os = "redox"))]
     use std::os::unix::prelude::OsStrExt;
-    #[cfg(target_os = "wasi")]    
+    #[cfg(target_os = "wasi")]
     use std::os::wasi::prelude::OsStrExt;
 
     if host.is_some() {

+ 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

+ 6 - 10
url/src/quirks.rs

@@ -139,14 +139,10 @@ 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() {
-            return Err(());
-        } else if let Some(Some(_)) = opt_port {
-            return Err(());
-        } else if url.port().is_some() {
-            return Err(());
-        }
+    if host == Host::Domain("".to_string())
+        && (!username(url).is_empty() || matches!(opt_port, Some(Some(_))) || url.port().is_some())
+    {
+        return Err(());
     }
     url.set_host_internal(host, opt_port);
     Ok(())
@@ -178,10 +174,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,