-
Notifications
You must be signed in to change notification settings - Fork 346
Fix up some issues flagged by clippy #294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
01ec217
844e2d5
3c21bd9
6db4c40
249369a
f34fa8f
78b4f57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -209,7 +209,7 @@ impl<F: FnMut(char) -> bool> Pattern for F { | |
impl<'i> Iterator for Input<'i> { | ||
type Item = char; | ||
fn next(&mut self) -> Option<char> { | ||
self.chars.by_ref().filter(|&c| !matches!(c, '\t' | '\n' | '\r')).next() | ||
self.chars.by_ref().find(|&c| !matches!(c, '\t' | '\n' | '\r')) | ||
} | ||
} | ||
|
||
|
@@ -736,8 +736,8 @@ impl<'a> Parser<'a> { | |
Ok((host_end, host.into(), port, remaining)) | ||
} | ||
|
||
pub fn parse_host<'i>(mut input: Input<'i>, scheme_type: SchemeType) | ||
-> ParseResult<(Host<String>, Input<'i>)> { | ||
pub fn parse_host(mut input: Input, scheme_type: SchemeType) | ||
-> ParseResult<(Host<String>, Input)> { | ||
// Undo the Input abstraction here to avoid allocating in the common case | ||
// where the host part of the input does not contain any tab or newline | ||
let input_str = input.chars.as_str(); | ||
|
@@ -830,9 +830,9 @@ impl<'a> Parser<'a> { | |
Ok((true, host, remaining)) | ||
} | ||
|
||
pub fn parse_port<'i, P>(mut input: Input<'i>, default_port: P, | ||
pub fn parse_port<P>(mut input: Input, default_port: P, | ||
context: Context) | ||
-> ParseResult<(Option<u16>, Input<'i>)> | ||
-> ParseResult<(Option<u16>, Input)> | ||
where P: Fn() -> Option<u16> { | ||
let mut port: u32 = 0; | ||
let mut has_any_digit = false; | ||
|
@@ -854,7 +854,7 @@ impl<'a> Parser<'a> { | |
if !has_any_digit || opt_port == default_port() { | ||
opt_port = None; | ||
} | ||
return Ok((opt_port, input)) | ||
Ok((opt_port, input)) | ||
} | ||
|
||
pub fn parse_path_start<'i>(&mut self, scheme_type: SchemeType, has_host: &mut bool, | ||
|
@@ -878,7 +878,7 @@ impl<'a> Parser<'a> { | |
path_start: usize, mut input: Input<'i>) | ||
-> Input<'i> { | ||
// Relative path state | ||
debug_assert!(self.serialization.ends_with("/")); | ||
debug_assert!(self.serialization.ends_with('/')); | ||
loop { | ||
let segment_start = self.serialization.len(); | ||
let mut ends_with_slash = false; | ||
|
@@ -926,7 +926,7 @@ impl<'a> Parser<'a> { | |
debug_assert!(self.serialization.as_bytes()[segment_start - 1] == b'/'); | ||
self.serialization.truncate(segment_start - 1); // Truncate "/.." | ||
self.pop_path(scheme_type, path_start); | ||
if !self.serialization[path_start..].ends_with("/") { | ||
if !self.serialization[path_start..].ends_with('/') { | ||
self.serialization.push('/') | ||
} | ||
}, | ||
|
@@ -1030,7 +1030,7 @@ impl<'a> Parser<'a> { | |
} | ||
} | ||
None => return Ok((None, None)), | ||
_ => panic!("Programming error. parse_query_and_fragment() called without ? or # {:?}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is strange. Why was the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought this would give a compiler error. Weird. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed. Me too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This compiles because the https://github.com/rust-lang/rust/blob/a0da1e0653/src/libstd/macros.rs#L43-L49 |
||
_ => panic!("Programming error. parse_query_and_fragment() called without ? or #") | ||
} | ||
|
||
let fragment_start = to_u32(self.serialization.len())?; | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly out of scope of this PR, but I think both parameters would benefit from some bound checking to ensure no index underflow/overflow will induce a panic here at runtime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you make a separate issue for this? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to #334.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately this still appears as part of the clippy related changes.
Can you move this into a new branch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a clippy related change. Bounds checking is a separate issue being tracked in #334.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! Then this PR looks OK to merge to me 👍