Skip to content

Commit e1344ad

Browse files
authored
Merge pull request #669 from sdroege/clippy
Fix various clippy warnings
2 parents 21aed6e + eb7330b commit e1344ad

File tree

6 files changed

+30
-15
lines changed

6 files changed

+30
-15
lines changed

data-url/tests/wpt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn run_data_url(
1717
if let Some(expected_mime) = expected_mime {
1818
let url = url.unwrap();
1919
let (body, _) = url.decode_to_vec().unwrap();
20-
if expected_mime == "" {
20+
if expected_mime.is_empty() {
2121
assert_eq!(url.mime_type().to_string(), "text/plain;charset=US-ASCII")
2222
} else {
2323
assert_eq!(url.mime_type().to_string(), expected_mime)
@@ -41,7 +41,7 @@ where
4141
enum TestCase {
4242
Two(String, Option<String>),
4343
Three(String, Option<String>, Vec<u8>),
44-
};
44+
}
4545

4646
let v: Vec<TestCase> = serde_json::from_str(include_str!("data-urls.json")).unwrap();
4747
for test in v {

idna/tests/uts46.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use idna::Errors;
1414
pub fn collect_tests<F: FnMut(String, TestFn)>(add_test: &mut F) {
1515
// https://www.unicode.org/Public/idna/13.0.0/IdnaTestV2.txt
1616
for (i, line) in include_str!("IdnaTestV2.txt").lines().enumerate() {
17-
if line == "" || line.starts_with('#') {
17+
if line.is_empty() || line.starts_with('#') {
1818
continue;
1919
}
2020

url/src/host.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,11 @@ fn parse_ipv4number(mut input: &str) -> Result<Option<u32>, ()> {
263263
// So instead we check if the input looks like a real number and only return
264264
// an error when it's an overflow.
265265
let valid_number = match r {
266-
8 => input.chars().all(|c| c >= '0' && c <= '7'),
267-
10 => input.chars().all(|c| c >= '0' && c <= '9'),
268-
16 => input
269-
.chars()
270-
.all(|c| (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')),
266+
8 => input.chars().all(|c| ('0'..='7').contains(&c)),
267+
10 => input.chars().all(|c| ('0'..='9').contains(&c)),
268+
16 => input.chars().all(|c| {
269+
('0'..='9').contains(&c) || ('a'..='f').contains(&c) || ('A'..='F').contains(&c)
270+
}),
271271
_ => false,
272272
};
273273

@@ -302,7 +302,7 @@ fn parse_ipv4addr(input: &str) -> ParseResult<Option<Ipv4Addr>> {
302302
let mut numbers: Vec<u32> = Vec::new();
303303
let mut overflow = false;
304304
for part in parts {
305-
if part == "" {
305+
if part.is_empty() {
306306
return Ok(None);
307307
}
308308
match parse_ipv4number(part) {

url/src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,7 @@ impl Url {
14331433
/// Return an object with methods to manipulate this URL’s path segments.
14341434
///
14351435
/// Return `Err(())` if this URL is cannot-be-a-base.
1436+
#[allow(clippy::clippy::result_unit_err)]
14361437
pub fn path_segments_mut(&mut self) -> Result<PathSegmentsMut<'_>, ()> {
14371438
if self.cannot_be_a_base() {
14381439
Err(())
@@ -1516,6 +1517,7 @@ impl Url {
15161517
/// # }
15171518
/// # run().unwrap();
15181519
/// ```
1520+
#[allow(clippy::clippy::result_unit_err)]
15191521
pub fn set_port(&mut self, mut port: Option<u16>) -> Result<(), ()> {
15201522
// has_host implies !cannot_be_a_base
15211523
if !self.has_host() || self.host() == Some(Host::Domain("")) || self.scheme() == "file" {
@@ -1655,7 +1657,7 @@ impl Url {
16551657
}
16561658

16571659
if let Some(host) = host {
1658-
if host == "" && SchemeType::from(self.scheme()).is_special() {
1660+
if host.is_empty() && SchemeType::from(self.scheme()).is_special() {
16591661
return Err(ParseError::EmptyHost);
16601662
}
16611663
let mut host_substr = host;
@@ -1786,6 +1788,7 @@ impl Url {
17861788
/// # run().unwrap();
17871789
/// ```
17881790
///
1791+
#[allow(clippy::clippy::result_unit_err)]
17891792
pub fn set_ip_host(&mut self, address: IpAddr) -> Result<(), ()> {
17901793
if self.cannot_be_a_base() {
17911794
return Err(());
@@ -1825,6 +1828,7 @@ impl Url {
18251828
/// # }
18261829
/// # run().unwrap();
18271830
/// ```
1831+
#[allow(clippy::clippy::result_unit_err)]
18281832
pub fn set_password(&mut self, password: Option<&str>) -> Result<(), ()> {
18291833
// has_host implies !cannot_be_a_base
18301834
if !self.has_host() || self.host() == Some(Host::Domain("")) || self.scheme() == "file" {
@@ -1917,6 +1921,7 @@ impl Url {
19171921
/// # }
19181922
/// # run().unwrap();
19191923
/// ```
1924+
#[allow(clippy::clippy::result_unit_err)]
19201925
pub fn set_username(&mut self, username: &str) -> Result<(), ()> {
19211926
// has_host implies !cannot_be_a_base
19221927
if !self.has_host() || self.host() == Some(Host::Domain("")) || self.scheme() == "file" {
@@ -2078,6 +2083,7 @@ impl Url {
20782083
/// # }
20792084
/// # run().unwrap();
20802085
/// ```
2086+
#[allow(clippy::clippy::result_unit_err)]
20812087
pub fn set_scheme(&mut self, scheme: &str) -> Result<(), ()> {
20822088
let mut parser = Parser::for_setter(String::new());
20832089
let remaining = parser.parse_scheme(parser::Input::new(scheme))?;
@@ -2157,6 +2163,7 @@ impl Url {
21572163
/// # }
21582164
/// ```
21592165
#[cfg(any(unix, windows, target_os = "redox"))]
2166+
#[allow(clippy::clippy::result_unit_err)]
21602167
pub fn from_file_path<P: AsRef<Path>>(path: P) -> Result<Url, ()> {
21612168
let mut serialization = "file://".to_owned();
21622169
let host_start = serialization.len() as u32;
@@ -2193,6 +2200,7 @@ impl Url {
21932200
/// Note that `std::path` does not consider trailing slashes significant
21942201
/// and usually does not include them (e.g. in `Path::parent()`).
21952202
#[cfg(any(unix, windows, target_os = "redox"))]
2203+
#[allow(clippy::clippy::result_unit_err)]
21962204
pub fn from_directory_path<P: AsRef<Path>>(path: P) -> Result<Url, ()> {
21972205
let mut url = Url::from_file_path(path)?;
21982206
if !url.serialization.ends_with('/') {
@@ -2309,6 +2317,7 @@ impl Url {
23092317
/// for a Windows path, is not UTF-8.)
23102318
#[inline]
23112319
#[cfg(any(unix, windows, target_os = "redox"))]
2320+
#[allow(clippy::clippy::result_unit_err)]
23122321
pub fn to_file_path(&self) -> Result<PathBuf, ()> {
23132322
if let Some(segments) = self.path_segments() {
23142323
let host = match self.host() {

url/src/parser.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,17 +295,17 @@ impl<'i> Input<'i> {
295295
}
296296

297297
pub trait Pattern {
298-
fn split_prefix<'i>(self, input: &mut Input<'i>) -> bool;
298+
fn split_prefix(self, input: &mut Input) -> bool;
299299
}
300300

301301
impl Pattern for char {
302-
fn split_prefix<'i>(self, input: &mut Input<'i>) -> bool {
302+
fn split_prefix(self, input: &mut Input) -> bool {
303303
input.next() == Some(self)
304304
}
305305
}
306306

307307
impl<'a> Pattern for &'a str {
308-
fn split_prefix<'i>(self, input: &mut Input<'i>) -> bool {
308+
fn split_prefix(self, input: &mut Input) -> bool {
309309
for c in self.chars() {
310310
if input.next() != Some(c) {
311311
return false;
@@ -316,7 +316,7 @@ impl<'a> Pattern for &'a str {
316316
}
317317

318318
impl<F: FnMut(char) -> bool> Pattern for F {
319-
fn split_prefix<'i>(self, input: &mut Input<'i>) -> bool {
319+
fn split_prefix(self, input: &mut Input) -> bool {
320320
input.next().map_or(false, self)
321321
}
322322
}
@@ -1071,7 +1071,7 @@ impl<'a> Parser<'a> {
10711071
Ok((has_host, host, remaining))
10721072
}
10731073

1074-
pub fn file_host<'i>(input: Input<'i>) -> ParseResult<(bool, String, Input<'i>)> {
1074+
pub fn file_host(input: Input) -> ParseResult<(bool, String, Input)> {
10751075
// Undo the Input abstraction here to avoid allocating in the common case
10761076
// where the host part of the input does not contain any tab or newline
10771077
let input_str = input.chars.as_str();

url/src/quirks.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub fn protocol(url: &Url) -> &str {
5656
}
5757

5858
/// Setter for https://url.spec.whatwg.org/#dom-url-protocol
59+
#[allow(clippy::clippy::result_unit_err)]
5960
pub fn set_protocol(url: &mut Url, mut new_protocol: &str) -> Result<(), ()> {
6061
// The scheme state in the spec ignores everything after the first `:`,
6162
// but `set_scheme` errors if there is more.
@@ -72,6 +73,7 @@ pub fn username(url: &Url) -> &str {
7273
}
7374

7475
/// Setter for https://url.spec.whatwg.org/#dom-url-username
76+
#[allow(clippy::clippy::result_unit_err)]
7577
pub fn set_username(url: &mut Url, new_username: &str) -> Result<(), ()> {
7678
url.set_username(new_username)
7779
}
@@ -83,6 +85,7 @@ pub fn password(url: &Url) -> &str {
8385
}
8486

8587
/// Setter for https://url.spec.whatwg.org/#dom-url-password
88+
#[allow(clippy::clippy::result_unit_err)]
8689
pub fn set_password(url: &mut Url, new_password: &str) -> Result<(), ()> {
8790
url.set_password(if new_password.is_empty() {
8891
None
@@ -98,6 +101,7 @@ pub fn host(url: &Url) -> &str {
98101
}
99102

100103
/// Setter for https://url.spec.whatwg.org/#dom-url-host
104+
#[allow(clippy::clippy::result_unit_err)]
101105
pub fn set_host(url: &mut Url, new_host: &str) -> Result<(), ()> {
102106
// If context object’s url’s cannot-be-a-base-URL flag is set, then return.
103107
if url.cannot_be_a_base() {
@@ -154,6 +158,7 @@ pub fn hostname(url: &Url) -> &str {
154158
}
155159

156160
/// Setter for https://url.spec.whatwg.org/#dom-url-hostname
161+
#[allow(clippy::clippy::result_unit_err)]
157162
pub fn set_hostname(url: &mut Url, new_hostname: &str) -> Result<(), ()> {
158163
if url.cannot_be_a_base() {
159164
return Err(());
@@ -195,6 +200,7 @@ pub fn port(url: &Url) -> &str {
195200
}
196201

197202
/// Setter for https://url.spec.whatwg.org/#dom-url-port
203+
#[allow(clippy::clippy::result_unit_err)]
198204
pub fn set_port(url: &mut Url, new_port: &str) -> Result<(), ()> {
199205
let result;
200206
{

0 commit comments

Comments
 (0)