Răsfoiți Sursa

MSRV 1.36 + fmt

Luca Casonato 4 ani în urmă
părinte
comite
6b029c6eee
2 a modificat fișierele cu 13 adăugiri și 10 ștergeri
  1. 9 8
      url/src/lib.rs
  2. 4 2
      url/src/quirks.rs

+ 9 - 8
url/src/lib.rs

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

+ 4 - 2
url/src/quirks.rs

@@ -139,8 +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
     // Make sure we won't set an empty host to a url with a username or a port
-    if host == Host::Domain("".to_string())  && (!username(url).is_empty() || matches!(opt_port, Some(Some(_))) || 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);
     url.set_host_internal(host, opt_port);
     Ok(())
     Ok(())