Skip to content

Commit

Permalink
Fix Clippy lints (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
winterqt authored Oct 19, 2021
1 parent 5df9997 commit df64ee4
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 40 deletions.
6 changes: 3 additions & 3 deletions examples/ssl_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ fn main() -> Result<()> {

handle.proxy(proxy_url)?;
handle.proxy_port(proxy_port)?;
handle.proxy_cainfo(&cainfo)?;
handle.proxy_sslcert(&sslcert)?;
handle.proxy_sslkey(&sslkey)?;
handle.proxy_cainfo(cainfo)?;
handle.proxy_sslcert(sslcert)?;
handle.proxy_sslkey(sslkey)?;
println!("ssl proxy setup done");

handle.perform()?;
Expand Down
25 changes: 9 additions & 16 deletions src/easy/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,7 @@ impl<H> Easy2<H> {
/// `CURLOPT_POSTFIELDSIZE_LARGE`.
pub fn post_field_size(&mut self, size: u64) -> Result<(), Error> {
// Clear anything previous to ensure we don't read past a buffer
self.setopt_ptr(curl_sys::CURLOPT_POSTFIELDS, 0 as *const _)?;
self.setopt_ptr(curl_sys::CURLOPT_POSTFIELDS, ptr::null())?;
self.setopt_off_t(
curl_sys::CURLOPT_POSTFIELDSIZE_LARGE,
size as curl_sys::curl_off_t,
Expand Down Expand Up @@ -1738,7 +1738,7 @@ impl<H> Easy2<H> {
pub fn timeout(&mut self, timeout: Duration) -> Result<(), Error> {
// TODO: checked arithmetic and casts
// TODO: use CURLOPT_TIMEOUT if the timeout is too great
let ms = timeout.as_secs() * 1000 + (timeout.subsec_nanos() / 1_000_000) as u64;
let ms = timeout.as_secs() * 1000 + timeout.subsec_millis() as u64;
self.setopt_long(curl_sys::CURLOPT_TIMEOUT_MS, ms as c_long)
}

Expand Down Expand Up @@ -1860,7 +1860,7 @@ impl<H> Easy2<H> {
/// By default this value is 300 seconds and corresponds to
/// `CURLOPT_CONNECTTIMEOUT_MS`.
pub fn connect_timeout(&mut self, timeout: Duration) -> Result<(), Error> {
let ms = timeout.as_secs() * 1000 + (timeout.subsec_nanos() / 1_000_000) as u64;
let ms = timeout.as_secs() * 1000 + timeout.subsec_millis() as u64;
self.setopt_long(curl_sys::CURLOPT_CONNECTTIMEOUT_MS, ms as c_long)
}

Expand Down Expand Up @@ -2411,7 +2411,7 @@ impl<H> Easy2<H> {
/// By default this option is not set and corresponds to
/// `CURLOPT_EXPECT_100_TIMEOUT_MS`.
pub fn expect_100_timeout(&mut self, timeout: Duration) -> Result<(), Error> {
let ms = timeout.as_secs() * 1000 + (timeout.subsec_nanos() / 1_000_000) as u64;
let ms = timeout.as_secs() * 1000 + timeout.subsec_millis() as u64;
self.setopt_long(curl_sys::CURLOPT_EXPECT_100_TIMEOUT_MS, ms as c_long)
}

Expand All @@ -2422,15 +2422,8 @@ impl<H> Easy2<H> {
//// This corresponds to `CURLINFO_CONDITION_UNMET` and may return an error if the
/// option is not supported
pub fn time_condition_unmet(&mut self) -> Result<bool, Error> {
self.getopt_long(curl_sys::CURLINFO_CONDITION_UNMET).map(
|r| {
if r == 0 {
false
} else {
true
}
},
)
self.getopt_long(curl_sys::CURLINFO_CONDITION_UNMET)
.map(|r| r != 0)
}

/// Get the last used URL
Expand Down Expand Up @@ -2894,7 +2887,7 @@ impl<H> Easy2<H> {

/// URL encodes a string `s`
pub fn url_encode(&mut self, s: &[u8]) -> String {
if s.len() == 0 {
if s.is_empty() {
return String::new();
}
unsafe {
Expand All @@ -2913,7 +2906,7 @@ impl<H> Easy2<H> {

/// URL decodes a string `s`, returning `None` if it fails
pub fn url_decode(&mut self, s: &str) -> Vec<u8> {
if s.len() == 0 {
if s.is_empty() {
return Vec::new();
}

Expand Down Expand Up @@ -3078,7 +3071,7 @@ impl<H> Easy2<H> {

fn getopt_ptr(&mut self, opt: curl_sys::CURLINFO) -> Result<*const c_char, Error> {
unsafe {
let mut p = 0 as *const c_char;
let mut p = ptr::null();
let rc = curl_sys::curl_easy_getinfo(self.inner.handle, opt, &mut p);
self.cvt(rc)?;
Ok(p)
Expand Down
2 changes: 0 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use std::fmt;
use std::io;
use std::str;

use curl_sys;

/// An error returned from various "easy" operations.
///
/// This structure wraps a `CURLcode`.
Expand Down
1 change: 0 additions & 1 deletion src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::ffi::CStr;
use std::fmt;
use std::str;

use curl_sys;
use libc::{c_char, c_int};

/// Version information about libcurl and the capabilities that it supports.
Expand Down
5 changes: 2 additions & 3 deletions systest/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ fn main() {
let version = str::from_utf8(&version).unwrap();
let version = version
.lines()
.filter(|l| !l.is_empty() && !l.starts_with("#"))
.next()
.find(|l| !l.is_empty() && !l.starts_with('#'))
.and_then(|s| s.parse::<u32>().ok())
.unwrap_or(10000);
println!("got version: {}", version);
Expand All @@ -39,7 +38,7 @@ fn main() {
"CURL" | "CURLM" | "CURLSH" | "curl_version_info_data" => s.to_string(),
"curl_khtype" | "curl_khstat" | "curl_khmatch" => format!("enum {}", s),
s if is_struct => format!("struct {}", s),
"sockaddr" => format!("struct sockaddr"),
"sockaddr" => "struct sockaddr".to_string(),
s => s.to_string(),
});
// cfg.fn_cname(|s, l| l.unwrap_or(s).to_string());
Expand Down
2 changes: 1 addition & 1 deletion tests/easy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mod server;
fn handle() -> Easy {
let mut e = Easy::new();
t!(e.timeout(Duration::new(20, 0)));
return e;
e
}

fn sink(data: &[u8]) -> Result<usize, WriteError> {
Expand Down
10 changes: 4 additions & 6 deletions tests/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,8 @@ fn upload_lots() {
while running {
let n = t!(poll.poll(&mut events, cur_timeout));

if n == 0 {
if t!(m.timeout()) == 0 {
running = false;
}
if n == 0 && t!(m.timeout()) == 0 {
running = false;
}

for event in events.iter() {
Expand All @@ -167,10 +165,10 @@ fn upload_lots() {
} else {
let mut e = mio::Ready::empty();
if events.input() {
e = e | mio::Ready::readable();
e |= mio::Ready::readable();
}
if events.output() {
e = e | mio::Ready::writable();
e |= mio::Ready::writable();
}
if token == 0 {
let token = next_token;
Expand Down
2 changes: 1 addition & 1 deletion tests/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn handle() -> Easy {
let mut list = List::new();
t!(list.append("Expect:"));
t!(e.http_headers(list));
return e;
e
}

#[test]
Expand Down
14 changes: 7 additions & 7 deletions tests/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn run(stream: impl Read + Write, rx: &Receiver<Message>) {
Message::Read(ref expected) => {
let mut expected = &expected[..];
let mut expected_headers = HashSet::new();
while let Some(i) = expected.find("\n") {
while let Some(i) = expected.find('\n') {
let line = &expected[..i + 1];
expected = &expected[i + 1..];
expected_headers.insert(line);
Expand All @@ -41,11 +41,11 @@ fn run(stream: impl Read + Write, rx: &Receiver<Message>) {
}

let mut expected_len = None;
while expected_headers.len() > 0 {
while !expected_headers.is_empty() {
let mut actual = String::new();
t!(socket.read_line(&mut actual));
if actual.starts_with("Content-Length") {
let len = actual.split(": ").skip(1).next().unwrap();
let len = actual.split(": ").nth(1).unwrap();
expected_len = len.trim().parse().ok();
}
// various versions of libcurl do different things here
Expand Down Expand Up @@ -84,13 +84,13 @@ fn run(stream: impl Read + Write, rx: &Receiver<Message>) {
while socket.limit() > 0 {
line.truncate(0);
t!(socket.read_line(&mut line));
if line.len() == 0 {
if line.is_empty() {
break;
}
if expected.len() == 0 {
if expected.is_empty() {
panic!("unexpected line: {:?}", line);
}
let i = expected.find("\n").unwrap_or(expected.len() - 1);
let i = expected.find('\n').unwrap_or(expected.len() - 1);
let expected_line = &expected[..i + 1];
expected = &expected[i + 1..];
if lines_match(expected_line, &line) {
Expand All @@ -103,7 +103,7 @@ fn run(stream: impl Read + Write, rx: &Receiver<Message>) {
expected_line, line
)
}
if expected.len() != 0 {
if !expected.is_empty() {
println!("didn't get expected data: {:?}", expected);
}
}
Expand Down

0 comments on commit df64ee4

Please sign in to comment.