diff --git a/src/error.rs b/src/error.rs index 881a04c..0fd37b6 100644 --- a/src/error.rs +++ b/src/error.rs @@ -288,6 +288,8 @@ pub enum ErrorKind { } impl ErrorKind { + #[allow(clippy::wrong_self_convention)] + #[allow(clippy::new_ret_no_self)] pub(crate) fn new(self) -> Error { Error::new(self, None) } diff --git a/src/lib.rs b/src/lib.rs index 2ef48a1..ea2b8fa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,10 @@ #![forbid(unsafe_code)] #![warn(clippy::all)] +// new is just more readable than ..Default::default(). +#![allow(clippy::new_without_default)] +// the matches! macro is obscure and not widely known. +#![allow(clippy::match_like_matches_macro)] + //! A simple, safe HTTP client. //! //! Ureq's first priority is being easy for you to use. It's great for @@ -327,8 +332,7 @@ pub fn is_test(is: bool) -> bool { if is { IS_TEST.store(true, Ordering::SeqCst); } - let x = IS_TEST.load(Ordering::SeqCst); - x + IS_TEST.load(Ordering::SeqCst) } /// Agents are used to hold configuration and keep state between requests. diff --git a/src/proxy.rs b/src/proxy.rs index 0aed467..36a4086 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -46,7 +46,9 @@ impl Proxy { match host { Some(host) => { let mut parts = host.as_ref().split(':').collect::>().into_iter(); - let host = parts.next().ok_or(ErrorKind::InvalidProxyUrl.new())?; + let host = parts + .next() + .ok_or_else(|| ErrorKind::InvalidProxyUrl.new())?; let port = parts.next(); Ok(( String::from(host), @@ -155,11 +157,11 @@ Proxy-Connection: Keep-Alive\r\n\ let top_line = response_string .lines() .next() - .ok_or(ErrorKind::ProxyConnect.new())?; + .ok_or_else(|| ErrorKind::ProxyConnect.new())?; let status_code = top_line .split_whitespace() .nth(1) - .ok_or(ErrorKind::ProxyConnect.new())?; + .ok_or_else(|| ErrorKind::ProxyConnect.new())?; match status_code { "200" => Ok(()), diff --git a/src/stream.rs b/src/stream.rs index 84d3933..5ed48ca 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -25,6 +25,7 @@ pub(crate) struct Stream { inner: BufReader, } +#[allow(clippy::large_enum_variant)] enum Inner { Http(TcpStream), #[cfg(feature = "tls")] diff --git a/src/testserver.rs b/src/testserver.rs index 8261fd8..930a559 100644 --- a/src/testserver.rs +++ b/src/testserver.rs @@ -113,13 +113,8 @@ pub fn read_request(stream: &TcpStream) -> TestHeaders { // There's a risk stream is ended here, and fill_buf() would block. stream.set_nonblocking(true).ok(); let mut reader = BufReader::new(stream); - loop { - let amount = match reader.fill_buf() { - Ok(buf) => buf.len(), - Err(_) => { - break; - } - }; + while let Ok(buf) = reader.fill_buf() { + let amount = buf.len(); if amount == 0 { break; } @@ -148,17 +143,13 @@ impl TestServer { } }); // before returning from new(), ensure the server is ready to accept connections - loop { - if let Err(e) = TcpStream::connect(format!("127.0.0.1:{}", port)) { - match e.kind() { - io::ErrorKind::ConnectionRefused => { - std::thread::sleep(Duration::from_millis(100)); - continue; - } - _ => eprintln!("testserver: pre-connect with error {}", e), + while let Err(e) = TcpStream::connect(format!("127.0.0.1:{}", port)) { + match e.kind() { + io::ErrorKind::ConnectionRefused => { + std::thread::sleep(Duration::from_millis(100)); + continue; } - } else { - break; + _ => eprintln!("testserver: pre-connect with error {}", e), } } TestServer { @@ -172,9 +163,8 @@ impl Drop for TestServer { fn drop(&mut self) { self.done.store(true, Ordering::SeqCst); // Connect once to unblock the listen loop. - match TcpStream::connect(format!("localhost:{}", self.port)) { - Err(e) => eprintln!("error dropping testserver: {}", e), - _ => {} + if let Err(e) = TcpStream::connect(format!("localhost:{}", self.port)) { + eprintln!("error dropping testserver: {}", e); } } } diff --git a/src/unit.rs b/src/unit.rs index c9c1b18..bc673c3 100644 --- a/src/unit.rs +++ b/src/unit.rs @@ -36,7 +36,7 @@ impl Unit { agent: &Agent, method: &str, url: &Url, - headers: &Vec
, + headers: &[Header], body: &SizedReader, deadline: Option, ) -> Self { @@ -229,7 +229,7 @@ fn connect_inner( let host = unit .url .host_str() - .ok_or(ErrorKind::InvalidUrl.msg("no host in URL"))?; + .ok_or_else(|| ErrorKind::InvalidUrl.msg("no host in URL"))?; let url = &unit.url; let method = &unit.method; // open socket