Skip to content

Commit e461e34

Browse files
author
bors-servo
authored
Auto merge of #294 - neosilky:clippy-fixes, r=SimonSapin
Fix up some issues flagged by clippy <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-url/294) <!-- Reviewable:end -->
2 parents 03e0c0f + 78b4f57 commit e461e34

File tree

7 files changed

+25
-27
lines changed

7 files changed

+25
-27
lines changed

fuzz/fuzzers/parse.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ extern crate url;
44
use std::str;
55

66
fuzz_target!(|data: &[u8]| {
7-
if let Ok(utf8) = str::from_utf8(data) {
8-
let url = url::Url::parse(utf8);
9-
}
7+
if let Ok(utf8) = str::from_utf8(data) {
8+
let _ = url::Url::parse(utf8);
9+
}
1010
});

src/form_urlencoded.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ fn decode(input: &[u8], encoding: EncodingOverride) -> Cow<str> {
121121
}
122122

123123
/// Replace b'+' with b' '
124-
fn replace_plus<'a>(input: &'a [u8]) -> Cow<'a, [u8]> {
124+
fn replace_plus(input: &[u8]) -> Cow<[u8]> {
125125
match input.iter().position(|&b| b == b'+') {
126126
None => Cow::Borrowed(input),
127127
Some(first_position) => {

src/host.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ impl Host<String> {
139139
///
140140
/// https://url.spec.whatwg.org/#host-parsing
141141
pub fn parse(input: &str) -> Result<Self, ParseError> {
142-
if input.starts_with("[") {
143-
if !input.ends_with("]") {
142+
if input.starts_with('[') {
143+
if !input.ends_with(']') {
144144
return Err(ParseError::InvalidIpv6Address)
145145
}
146146
return parse_ipv6addr(&input[1..input.len() - 1]).map(Host::Ipv6)
@@ -304,17 +304,17 @@ fn parse_ipv4number(mut input: &str) -> Result<u32, ()> {
304304
if input.starts_with("0x") || input.starts_with("0X") {
305305
input = &input[2..];
306306
r = 16;
307-
} else if input.len() >= 2 && input.starts_with("0") {
307+
} else if input.len() >= 2 && input.starts_with('0') {
308308
input = &input[1..];
309309
r = 8;
310310
}
311311
if input.is_empty() {
312312
return Ok(0);
313313
}
314-
if input.starts_with("+") {
314+
if input.starts_with('+') {
315315
return Err(())
316316
}
317-
match u32::from_str_radix(&input, r) {
317+
match u32::from_str_radix(input, r) {
318318
Ok(number) => Ok(number),
319319
Err(_) => Err(()),
320320
}
@@ -477,9 +477,7 @@ fn parse_ipv6addr(input: &str) -> ParseResult<Ipv6Addr> {
477477
let mut swaps = piece_pointer - compress_pointer;
478478
piece_pointer = 7;
479479
while swaps > 0 {
480-
let tmp = pieces[piece_pointer];
481-
pieces[piece_pointer] = pieces[compress_pointer + swaps - 1];
482-
pieces[compress_pointer + swaps - 1] = tmp;
480+
pieces.swap(piece_pointer, compress_pointer + swaps - 1);
483481
swaps -= 1;
484482
piece_pointer -= 1;
485483
}

src/parser.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl<F: FnMut(char) -> bool> Pattern for F {
209209
impl<'i> Iterator for Input<'i> {
210210
type Item = char;
211211
fn next(&mut self) -> Option<char> {
212-
self.chars.by_ref().filter(|&c| !matches!(c, '\t' | '\n' | '\r')).next()
212+
self.chars.by_ref().find(|&c| !matches!(c, '\t' | '\n' | '\r'))
213213
}
214214
}
215215

@@ -736,8 +736,8 @@ impl<'a> Parser<'a> {
736736
Ok((host_end, host.into(), port, remaining))
737737
}
738738

739-
pub fn parse_host<'i>(mut input: Input<'i>, scheme_type: SchemeType)
740-
-> ParseResult<(Host<String>, Input<'i>)> {
739+
pub fn parse_host(mut input: Input, scheme_type: SchemeType)
740+
-> ParseResult<(Host<String>, Input)> {
741741
// Undo the Input abstraction here to avoid allocating in the common case
742742
// where the host part of the input does not contain any tab or newline
743743
let input_str = input.chars.as_str();
@@ -830,9 +830,9 @@ impl<'a> Parser<'a> {
830830
Ok((true, host, remaining))
831831
}
832832

833-
pub fn parse_port<'i, P>(mut input: Input<'i>, default_port: P,
833+
pub fn parse_port<P>(mut input: Input, default_port: P,
834834
context: Context)
835-
-> ParseResult<(Option<u16>, Input<'i>)>
835+
-> ParseResult<(Option<u16>, Input)>
836836
where P: Fn() -> Option<u16> {
837837
let mut port: u32 = 0;
838838
let mut has_any_digit = false;
@@ -854,7 +854,7 @@ impl<'a> Parser<'a> {
854854
if !has_any_digit || opt_port == default_port() {
855855
opt_port = None;
856856
}
857-
return Ok((opt_port, input))
857+
Ok((opt_port, input))
858858
}
859859

860860
pub fn parse_path_start<'i>(&mut self, scheme_type: SchemeType, has_host: &mut bool,
@@ -878,7 +878,7 @@ impl<'a> Parser<'a> {
878878
path_start: usize, mut input: Input<'i>)
879879
-> Input<'i> {
880880
// Relative path state
881-
debug_assert!(self.serialization.ends_with("/"));
881+
debug_assert!(self.serialization.ends_with('/'));
882882
loop {
883883
let segment_start = self.serialization.len();
884884
let mut ends_with_slash = false;
@@ -926,7 +926,7 @@ impl<'a> Parser<'a> {
926926
debug_assert!(self.serialization.as_bytes()[segment_start - 1] == b'/');
927927
self.serialization.truncate(segment_start - 1); // Truncate "/.."
928928
self.pop_path(scheme_type, path_start);
929-
if !self.serialization[path_start..].ends_with("/") {
929+
if !self.serialization[path_start..].ends_with('/') {
930930
self.serialization.push('/')
931931
}
932932
},
@@ -1030,7 +1030,7 @@ impl<'a> Parser<'a> {
10301030
}
10311031
}
10321032
None => return Ok((None, None)),
1033-
_ => panic!("Programming error. parse_query_and_fragment() called without ? or # {:?}")
1033+
_ => panic!("Programming error. parse_query_and_fragment() called without ? or #")
10341034
}
10351035

10361036
let fragment_start = to_u32(self.serialization.len())?;

src/percent_encoding.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ impl<'a, E: EncodeSet> From<PercentEncode<'a, E>> for Cow<'a, str> {
242242
/// (which returns `Cow::Borrowed` when `input` contains no percent-encoded sequence)
243243
/// and has `decode_utf8()` and `decode_utf8_lossy()` methods.
244244
#[inline]
245-
pub fn percent_decode<'a>(input: &'a [u8]) -> PercentDecode<'a> {
245+
pub fn percent_decode(input: &[u8]) -> PercentDecode {
246246
PercentDecode {
247247
bytes: input.iter()
248248
}
@@ -298,7 +298,7 @@ impl<'a> PercentDecode<'a> {
298298
/// If the percent-decoding is different from the input, return it as a new bytes vector.
299299
pub fn if_any(&self) -> Option<Vec<u8>> {
300300
let mut bytes_iter = self.bytes.clone();
301-
while bytes_iter.find(|&&b| b == b'%').is_some() {
301+
while bytes_iter.any(|&b| b == b'%') {
302302
if let Some(decoded_byte) = after_percent_sign(&mut bytes_iter) {
303303
let initial_bytes = self.bytes.as_slice();
304304
let unchanged_bytes_len = initial_bytes.len() - bytes_iter.len() - 3;

tests/data.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn check_invariants(url: &Url) {
2626
}
2727

2828

29-
fn run_parsing(input: String, base: String, expected: Result<ExpectedAttributes, ()>) {
29+
fn run_parsing(input: &str, base: &str, expected: Result<ExpectedAttributes, ()>) {
3030
let base = match Url::parse(&base) {
3131
Ok(base) => base,
3232
Err(message) => panic!("Error parsing base {:?}: {}", base, message)
@@ -135,7 +135,7 @@ fn collect_parsing<F: FnMut(String, test::TestFn)>(add_test: &mut F) {
135135
})
136136
};
137137
add_test(format!("{:?} @ base {:?}", input, base),
138-
test::TestFn::dyn_test_fn(move || run_parsing(input, base, expected)));
138+
test::TestFn::dyn_test_fn(move || run_parsing(&input, &base, expected)));
139139
}
140140
}
141141

tests/unit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ fn test_equality() {
164164
// Different scheme
165165
let a: Url = url("http://example.com/");
166166
let b: Url = url("https://example.com/");
167-
assert!(a != b);
167+
assert_ne!(a, b);
168168

169169
// Different host
170170
let a: Url = url("http://foo.com/");
171171
let b: Url = url("http://bar.com/");
172-
assert!(a != b);
172+
assert_ne!(a, b);
173173

174174
// Missing path, automatically substituted. Semantically the same.
175175
let a: Url = url("http://foo.com");

0 commit comments

Comments
 (0)