From 3ec8a6656c377ed06e5b7d0de03587a4edb73191 Mon Sep 17 00:00:00 2001 From: o0Ignition0o Date: Sun, 4 Aug 2019 01:02:45 +0200 Subject: [PATCH] Pleasing the 1.33.0 borrow checker. --- src/host.rs | 39 --------------------------------------- src/lib.rs | 3 ++- src/parser.rs | 29 ++++++++++++++++------------- 3 files changed, 18 insertions(+), 53 deletions(-) diff --git a/src/host.rs b/src/host.rs index 60595da79..238d523ed 100644 --- a/src/host.rs +++ b/src/host.rs @@ -24,45 +24,6 @@ pub(crate) enum HostInternal { Ipv6(Ipv6Addr), } -#[cfg(feature = "serde")] -impl ::serde::Serialize for HostInternal { - fn serialize(&self, serializer: S) -> Result - where - S: ::serde::Serializer, - { - // This doesn’t use `derive` because that involves - // large dependencies (that take a long time to build), and - // either Macros 1.1 which are not stable yet or a cumbersome build script. - // - // Implementing `Serializer` correctly for an enum is tricky, - // so let’s use existing enums that already do. - use std::net::IpAddr; - match *self { - HostInternal::None => None, - HostInternal::Domain => Some(None), - HostInternal::Ipv4(addr) => Some(Some(IpAddr::V4(addr))), - HostInternal::Ipv6(addr) => Some(Some(IpAddr::V6(addr))), - } - .serialize(serializer) - } -} - -#[cfg(feature = "serde")] -impl<'de> ::serde::Deserialize<'de> for HostInternal { - fn deserialize(deserializer: D) -> Result - where - D: ::serde::Deserializer<'de>, - { - use std::net::IpAddr; - Ok(match ::serde::Deserialize::deserialize(deserializer)? { - None => HostInternal::None, - Some(None) => HostInternal::Domain, - Some(Some(IpAddr::V4(addr))) => HostInternal::Ipv4(addr), - Some(Some(IpAddr::V6(addr))) => HostInternal::Ipv6(addr), - }) - } -} - impl From> for HostInternal where S: ToString, diff --git a/src/lib.rs b/src/lib.rs index 9b788db5a..163de5d30 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2097,7 +2097,8 @@ impl Url { // If it is the scheme's default // We don't mind it silently failing // If there was no port in the first place - let _ = self.set_port(self.port()); + let previous_port = self.port(); + let _ = self.set_port(previous_port); Ok(()) } diff --git a/src/parser.rs b/src/parser.rs index a247e87a2..48d02088a 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1236,12 +1236,13 @@ impl<'a> Parser<'a> { } } } - - let segment_before_slash = if ends_with_slash { - &self.serialization[segment_start..self.serialization.len() - 1] + // Going from &str to String to &str to please the 1.33.0 borrow checker + let before_slash_string = if ends_with_slash { + self.serialization[segment_start..self.serialization.len() - 1].to_owned() } else { - &self.serialization[segment_start..self.serialization.len()] + self.serialization[segment_start..self.serialization.len()].to_owned() }; + let segment_before_slash: &str = &before_slash_string; match segment_before_slash { // If buffer is a double-dot path segment, shorten url’s path, ".." | "%2e%2e" | "%2e%2E" | "%2E%2e" | "%2E%2E" | "%2e." | "%2E." | ".%2e" @@ -1316,16 +1317,18 @@ impl<'a> Parser<'a> { if self.serialization.len() <= path_start { return; } - // If url’s scheme is "file", path’s size is 1, and path[0] is a normalized Windows drive letter, then return. - let segments: Vec<&str> = self.serialization[path_start..] - .split('/') - .filter(|s| !s.is_empty()) - .collect(); - if scheme_type.is_file() - && segments.len() == 1 - && is_normalized_windows_drive_letter(segments[0]) { - return; + // If url’s scheme is "file", path’s size is 1, and path[0] is a normalized Windows drive letter, then return. + let segments: Vec<&str> = self.serialization[path_start..] + .split('/') + .filter(|s| !s.is_empty()) + .collect(); + if scheme_type.is_file() + && segments.len() == 1 + && is_normalized_windows_drive_letter(segments[0]) + { + return; + } } // Remove path’s last item. self.pop_path(scheme_type, path_start);