Skip to content

Commit bd150e3

Browse files
authored
Merge pull request #744 from lucacasonato/fix_clippy
Appease clippy
2 parents 9f438e8 + 6b029c6 commit bd150e3

File tree

7 files changed

+21
-24
lines changed

7 files changed

+21
-24
lines changed

idna/src/uts46.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ fn passes_bidi(label: &str, is_bidi_domain: bool) -> bool {
156156
// LTR label
157157
BidiClass::L => {
158158
// Rule 5
159-
while let Some(c) = chars.next() {
159+
for c in chars.by_ref() {
160160
if !matches!(
161161
bidi_class(c),
162162
BidiClass::L
@@ -396,7 +396,7 @@ fn processing(
396396
}
397397

398398
if !errors.is_err() {
399-
if !is_nfc(&decoded_label) {
399+
if !is_nfc(decoded_label) {
400400
errors.nfc = true;
401401
} else {
402402
check_validity(decoded_label, non_transitional, &mut errors);

idna/tests/uts46.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ pub fn collect_tests<F: FnMut(String, TestFn)>(add_test: &mut F) {
2525
};
2626

2727
let mut pieces = line.split(';').map(|x| x.trim()).collect::<Vec<&str>>();
28-
let source = unescape(&pieces.remove(0));
28+
let source = unescape(pieces.remove(0));
2929

3030
// ToUnicode
31-
let mut to_unicode = unescape(&pieces.remove(0));
31+
let mut to_unicode = unescape(pieces.remove(0));
3232
if to_unicode.is_empty() {
3333
to_unicode = source.clone();
3434
}

url/src/host.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl Host<String> {
162162
/// convert domain with idna
163163
#[cfg(feature = "idna")]
164164
fn domain_to_ascii(domain: &str) -> Result<String, ParseError> {
165-
idna::domain_to_ascii(&domain).map_err(Into::into)
165+
idna::domain_to_ascii(domain).map_err(Into::into)
166166
}
167167

168168
/// checks domain is ascii

url/src/lib.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,7 @@ impl Url {
13611361
}
13621362

13631363
fn mutate<F: FnOnce(&mut Parser<'_>) -> R, R>(&mut self, f: F) -> R {
1364+
#[allow(clippy::mem_replace_with_default)] // introduced in 1.40, MSRV is 1.36
13641365
let mut parser = Parser::for_setter(mem::replace(&mut self.serialization, String::new()));
13651366
let result = f(&mut parser);
13661367
self.serialization = parser.serialization;
@@ -1551,19 +1552,19 @@ impl Url {
15511552
/// url.set_path("data/report.csv");
15521553
/// assert_eq!(url.as_str(), "https://example.com/data/report.csv");
15531554
/// assert_eq!(url.path(), "/data/report.csv");
1554-
///
1555+
///
15551556
/// // `set_path` percent-encodes the given string if it's not already percent-encoded.
15561557
/// let mut url = Url::parse("https://example.com")?;
15571558
/// url.set_path("api/some comments");
15581559
/// assert_eq!(url.as_str(), "https://example.com/api/some%20comments");
15591560
/// assert_eq!(url.path(), "/api/some%20comments");
1560-
///
1561+
///
15611562
/// // `set_path` will not double percent-encode the string if it's already percent-encoded.
15621563
/// let mut url = Url::parse("https://example.com")?;
15631564
/// url.set_path("api/some%20comments");
15641565
/// assert_eq!(url.as_str(), "https://example.com/api/some%20comments");
15651566
/// assert_eq!(url.path(), "/api/some%20comments");
1566-
///
1567+
///
15671568
/// # Ok(())
15681569
/// # }
15691570
/// # run().unwrap();
@@ -2684,9 +2685,9 @@ fn path_to_file_url_segments(
26842685
path: &Path,
26852686
serialization: &mut String,
26862687
) -> Result<(u32, HostInternal), ()> {
2687-
#[cfg(any(unix, target_os = "redox"))]
2688+
#[cfg(any(unix, target_os = "redox"))]
26882689
use std::os::unix::prelude::OsStrExt;
2689-
#[cfg(target_os = "wasi")]
2690+
#[cfg(target_os = "wasi")]
26902691
use std::os::wasi::prelude::OsStrExt;
26912692
if !path.is_absolute() {
26922693
return Err(());
@@ -2783,9 +2784,9 @@ fn file_url_segments_to_pathbuf(
27832784
segments: str::Split<'_, char>,
27842785
) -> Result<PathBuf, ()> {
27852786
use std::ffi::OsStr;
2786-
#[cfg(any(unix, target_os = "redox"))]
2787+
#[cfg(any(unix, target_os = "redox"))]
27872788
use std::os::unix::prelude::OsStrExt;
2788-
#[cfg(target_os = "wasi")]
2789+
#[cfg(target_os = "wasi")]
27892790
use std::os::wasi::prelude::OsStrExt;
27902791

27912792
if host.is_some() {

url/src/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,7 @@ impl<'a> Parser<'a> {
12931293
//FIXME: log violation
12941294
let path = self.serialization.split_off(path_start);
12951295
self.serialization.push('/');
1296-
self.serialization.push_str(&path.trim_start_matches('/'));
1296+
self.serialization.push_str(path.trim_start_matches('/'));
12971297
}
12981298

12991299
input

url/src/quirks.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,10 @@ pub fn set_host(url: &mut Url, new_host: &str) -> Result<(), ()> {
139139
}
140140
}
141141
// Make sure we won't set an empty host to a url with a username or a port
142-
if host == Host::Domain("".to_string()) {
143-
if !username(&url).is_empty() {
144-
return Err(());
145-
} else if let Some(Some(_)) = opt_port {
146-
return Err(());
147-
} else if url.port().is_some() {
148-
return Err(());
149-
}
142+
if host == Host::Domain("".to_string())
143+
&& (!username(url).is_empty() || matches!(opt_port, Some(Some(_))) || url.port().is_some())
144+
{
145+
return Err(());
150146
}
151147
url.set_host_internal(host, opt_port);
152148
Ok(())
@@ -178,10 +174,10 @@ pub fn set_hostname(url: &mut Url, new_hostname: &str) -> Result<(), ()> {
178174
// Empty host on special not file url
179175
if SchemeType::from(url.scheme()) == SchemeType::SpecialNotFile
180176
// Port with an empty host
181-
||!port(&url).is_empty()
177+
||!port(url).is_empty()
182178
// Empty host that includes credentials
183179
|| !url.username().is_empty()
184-
|| !url.password().unwrap_or(&"").is_empty()
180+
|| !url.password().unwrap_or("").is_empty()
185181
{
186182
return Err(());
187183
}

url/tests/unit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ fn test_make_relative() {
10961096
base, uri, relative
10971097
);
10981098
assert_eq!(
1099-
base_uri.join(&relative).unwrap().as_str(),
1099+
base_uri.join(relative).unwrap().as_str(),
11001100
*uri,
11011101
"base: {}, uri: {}, relative: {}",
11021102
base,

0 commit comments

Comments
 (0)