Skip to content

Commit 3ec8a66

Browse files
committed
Pleasing the 1.33.0 borrow checker.
1 parent 4e037c2 commit 3ec8a66

File tree

3 files changed

+18
-53
lines changed

3 files changed

+18
-53
lines changed

src/host.rs

-39
Original file line numberDiff line numberDiff line change
@@ -24,45 +24,6 @@ pub(crate) enum HostInternal {
2424
Ipv6(Ipv6Addr),
2525
}
2626

27-
#[cfg(feature = "serde")]
28-
impl ::serde::Serialize for HostInternal {
29-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
30-
where
31-
S: ::serde::Serializer,
32-
{
33-
// This doesn’t use `derive` because that involves
34-
// large dependencies (that take a long time to build), and
35-
// either Macros 1.1 which are not stable yet or a cumbersome build script.
36-
//
37-
// Implementing `Serializer` correctly for an enum is tricky,
38-
// so let’s use existing enums that already do.
39-
use std::net::IpAddr;
40-
match *self {
41-
HostInternal::None => None,
42-
HostInternal::Domain => Some(None),
43-
HostInternal::Ipv4(addr) => Some(Some(IpAddr::V4(addr))),
44-
HostInternal::Ipv6(addr) => Some(Some(IpAddr::V6(addr))),
45-
}
46-
.serialize(serializer)
47-
}
48-
}
49-
50-
#[cfg(feature = "serde")]
51-
impl<'de> ::serde::Deserialize<'de> for HostInternal {
52-
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
53-
where
54-
D: ::serde::Deserializer<'de>,
55-
{
56-
use std::net::IpAddr;
57-
Ok(match ::serde::Deserialize::deserialize(deserializer)? {
58-
None => HostInternal::None,
59-
Some(None) => HostInternal::Domain,
60-
Some(Some(IpAddr::V4(addr))) => HostInternal::Ipv4(addr),
61-
Some(Some(IpAddr::V6(addr))) => HostInternal::Ipv6(addr),
62-
})
63-
}
64-
}
65-
6627
impl<S> From<Host<S>> for HostInternal
6728
where
6829
S: ToString,

src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2097,7 +2097,8 @@ impl Url {
20972097
// If it is the scheme's default
20982098
// We don't mind it silently failing
20992099
// If there was no port in the first place
2100-
let _ = self.set_port(self.port());
2100+
let previous_port = self.port();
2101+
let _ = self.set_port(previous_port);
21012102

21022103
Ok(())
21032104
}

src/parser.rs

+16-13
Original file line numberDiff line numberDiff line change
@@ -1236,12 +1236,13 @@ impl<'a> Parser<'a> {
12361236
}
12371237
}
12381238
}
1239-
1240-
let segment_before_slash = if ends_with_slash {
1241-
&self.serialization[segment_start..self.serialization.len() - 1]
1239+
// Going from &str to String to &str to please the 1.33.0 borrow checker
1240+
let before_slash_string = if ends_with_slash {
1241+
self.serialization[segment_start..self.serialization.len() - 1].to_owned()
12421242
} else {
1243-
&self.serialization[segment_start..self.serialization.len()]
1243+
self.serialization[segment_start..self.serialization.len()].to_owned()
12441244
};
1245+
let segment_before_slash: &str = &before_slash_string;
12451246
match segment_before_slash {
12461247
// If buffer is a double-dot path segment, shorten url’s path,
12471248
".." | "%2e%2e" | "%2e%2E" | "%2E%2e" | "%2E%2E" | "%2e." | "%2E." | ".%2e"
@@ -1316,16 +1317,18 @@ impl<'a> Parser<'a> {
13161317
if self.serialization.len() <= path_start {
13171318
return;
13181319
}
1319-
// If url’s scheme is "file", path’s size is 1, and path[0] is a normalized Windows drive letter, then return.
1320-
let segments: Vec<&str> = self.serialization[path_start..]
1321-
.split('/')
1322-
.filter(|s| !s.is_empty())
1323-
.collect();
1324-
if scheme_type.is_file()
1325-
&& segments.len() == 1
1326-
&& is_normalized_windows_drive_letter(segments[0])
13271320
{
1328-
return;
1321+
// If url’s scheme is "file", path’s size is 1, and path[0] is a normalized Windows drive letter, then return.
1322+
let segments: Vec<&str> = self.serialization[path_start..]
1323+
.split('/')
1324+
.filter(|s| !s.is_empty())
1325+
.collect();
1326+
if scheme_type.is_file()
1327+
&& segments.len() == 1
1328+
&& is_normalized_windows_drive_letter(segments[0])
1329+
{
1330+
return;
1331+
}
13291332
}
13301333
// Remove path’s last item.
13311334
self.pop_path(scheme_type, path_start);

0 commit comments

Comments
 (0)