Fix clippy warnings

This commit is contained in:
Martin Algesten
2021-03-24 20:05:51 +01:00
parent ea53c7cedd
commit b42e9afd71
6 changed files with 26 additions and 27 deletions

View File

@@ -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)
}

View File

@@ -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.

View File

@@ -46,7 +46,9 @@ impl Proxy {
match host {
Some(host) => {
let mut parts = host.as_ref().split(':').collect::<Vec<&str>>().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(()),

View File

@@ -25,6 +25,7 @@ pub(crate) struct Stream {
inner: BufReader<Inner>,
}
#[allow(clippy::large_enum_variant)]
enum Inner {
Http(TcpStream),
#[cfg(feature = "tls")]

View File

@@ -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);
}
}
}

View File

@@ -36,7 +36,7 @@ impl Unit {
agent: &Agent,
method: &str,
url: &Url,
headers: &Vec<Header>,
headers: &[Header],
body: &SizedReader,
deadline: Option<time::Instant>,
) -> 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