Skip to content

Commit df64ee4

Browse files
authored
Fix Clippy lints (#416)
1 parent 5df9997 commit df64ee4

File tree

9 files changed

+27
-40
lines changed

9 files changed

+27
-40
lines changed

examples/ssl_proxy.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ fn main() -> Result<()> {
1616

1717
handle.proxy(proxy_url)?;
1818
handle.proxy_port(proxy_port)?;
19-
handle.proxy_cainfo(&cainfo)?;
20-
handle.proxy_sslcert(&sslcert)?;
21-
handle.proxy_sslkey(&sslkey)?;
19+
handle.proxy_cainfo(cainfo)?;
20+
handle.proxy_sslcert(sslcert)?;
21+
handle.proxy_sslkey(sslkey)?;
2222
println!("ssl proxy setup done");
2323

2424
handle.perform()?;

src/easy/handler.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,7 @@ impl<H> Easy2<H> {
13431343
/// `CURLOPT_POSTFIELDSIZE_LARGE`.
13441344
pub fn post_field_size(&mut self, size: u64) -> Result<(), Error> {
13451345
// Clear anything previous to ensure we don't read past a buffer
1346-
self.setopt_ptr(curl_sys::CURLOPT_POSTFIELDS, 0 as *const _)?;
1346+
self.setopt_ptr(curl_sys::CURLOPT_POSTFIELDS, ptr::null())?;
13471347
self.setopt_off_t(
13481348
curl_sys::CURLOPT_POSTFIELDSIZE_LARGE,
13491349
size as curl_sys::curl_off_t,
@@ -1738,7 +1738,7 @@ impl<H> Easy2<H> {
17381738
pub fn timeout(&mut self, timeout: Duration) -> Result<(), Error> {
17391739
// TODO: checked arithmetic and casts
17401740
// TODO: use CURLOPT_TIMEOUT if the timeout is too great
1741-
let ms = timeout.as_secs() * 1000 + (timeout.subsec_nanos() / 1_000_000) as u64;
1741+
let ms = timeout.as_secs() * 1000 + timeout.subsec_millis() as u64;
17421742
self.setopt_long(curl_sys::CURLOPT_TIMEOUT_MS, ms as c_long)
17431743
}
17441744

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

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

@@ -2422,15 +2422,8 @@ impl<H> Easy2<H> {
24222422
//// This corresponds to `CURLINFO_CONDITION_UNMET` and may return an error if the
24232423
/// option is not supported
24242424
pub fn time_condition_unmet(&mut self) -> Result<bool, Error> {
2425-
self.getopt_long(curl_sys::CURLINFO_CONDITION_UNMET).map(
2426-
|r| {
2427-
if r == 0 {
2428-
false
2429-
} else {
2430-
true
2431-
}
2432-
},
2433-
)
2425+
self.getopt_long(curl_sys::CURLINFO_CONDITION_UNMET)
2426+
.map(|r| r != 0)
24342427
}
24352428

24362429
/// Get the last used URL
@@ -2894,7 +2887,7 @@ impl<H> Easy2<H> {
28942887

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

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

@@ -3078,7 +3071,7 @@ impl<H> Easy2<H> {
30783071

30793072
fn getopt_ptr(&mut self, opt: curl_sys::CURLINFO) -> Result<*const c_char, Error> {
30803073
unsafe {
3081-
let mut p = 0 as *const c_char;
3074+
let mut p = ptr::null();
30823075
let rc = curl_sys::curl_easy_getinfo(self.inner.handle, opt, &mut p);
30833076
self.cvt(rc)?;
30843077
Ok(p)

src/error.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ use std::fmt;
44
use std::io;
55
use std::str;
66

7-
use curl_sys;
8-
97
/// An error returned from various "easy" operations.
108
///
119
/// This structure wraps a `CURLcode`.

src/version.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::ffi::CStr;
22
use std::fmt;
33
use std::str;
44

5-
use curl_sys;
65
use libc::{c_char, c_int};
76

87
/// Version information about libcurl and the capabilities that it supports.

systest/build.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ fn main() {
1414
let version = str::from_utf8(&version).unwrap();
1515
let version = version
1616
.lines()
17-
.filter(|l| !l.is_empty() && !l.starts_with("#"))
18-
.next()
17+
.find(|l| !l.is_empty() && !l.starts_with('#'))
1918
.and_then(|s| s.parse::<u32>().ok())
2019
.unwrap_or(10000);
2120
println!("got version: {}", version);
@@ -39,7 +38,7 @@ fn main() {
3938
"CURL" | "CURLM" | "CURLSH" | "curl_version_info_data" => s.to_string(),
4039
"curl_khtype" | "curl_khstat" | "curl_khmatch" => format!("enum {}", s),
4140
s if is_struct => format!("struct {}", s),
42-
"sockaddr" => format!("struct sockaddr"),
41+
"sockaddr" => "struct sockaddr".to_string(),
4342
s => s.to_string(),
4443
});
4544
// cfg.fn_cname(|s, l| l.unwrap_or(s).to_string());

tests/easy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ mod server;
2222
fn handle() -> Easy {
2323
let mut e = Easy::new();
2424
t!(e.timeout(Duration::new(20, 0)));
25-
return e;
25+
e
2626
}
2727

2828
fn sink(data: &[u8]) -> Result<usize, WriteError> {

tests/multi.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,8 @@ fn upload_lots() {
150150
while running {
151151
let n = t!(poll.poll(&mut events, cur_timeout));
152152

153-
if n == 0 {
154-
if t!(m.timeout()) == 0 {
155-
running = false;
156-
}
153+
if n == 0 && t!(m.timeout()) == 0 {
154+
running = false;
157155
}
158156

159157
for event in events.iter() {
@@ -167,10 +165,10 @@ fn upload_lots() {
167165
} else {
168166
let mut e = mio::Ready::empty();
169167
if events.input() {
170-
e = e | mio::Ready::readable();
168+
e |= mio::Ready::readable();
171169
}
172170
if events.output() {
173-
e = e | mio::Ready::writable();
171+
e |= mio::Ready::writable();
174172
}
175173
if token == 0 {
176174
let token = next_token;

tests/post.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn handle() -> Easy {
2020
let mut list = List::new();
2121
t!(list.append("Expect:"));
2222
t!(e.http_headers(list));
23-
return e;
23+
e
2424
}
2525

2626
#[test]

tests/server/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn run(stream: impl Read + Write, rx: &Receiver<Message>) {
3131
Message::Read(ref expected) => {
3232
let mut expected = &expected[..];
3333
let mut expected_headers = HashSet::new();
34-
while let Some(i) = expected.find("\n") {
34+
while let Some(i) = expected.find('\n') {
3535
let line = &expected[..i + 1];
3636
expected = &expected[i + 1..];
3737
expected_headers.insert(line);
@@ -41,11 +41,11 @@ fn run(stream: impl Read + Write, rx: &Receiver<Message>) {
4141
}
4242

4343
let mut expected_len = None;
44-
while expected_headers.len() > 0 {
44+
while !expected_headers.is_empty() {
4545
let mut actual = String::new();
4646
t!(socket.read_line(&mut actual));
4747
if actual.starts_with("Content-Length") {
48-
let len = actual.split(": ").skip(1).next().unwrap();
48+
let len = actual.split(": ").nth(1).unwrap();
4949
expected_len = len.trim().parse().ok();
5050
}
5151
// various versions of libcurl do different things here
@@ -84,13 +84,13 @@ fn run(stream: impl Read + Write, rx: &Receiver<Message>) {
8484
while socket.limit() > 0 {
8585
line.truncate(0);
8686
t!(socket.read_line(&mut line));
87-
if line.len() == 0 {
87+
if line.is_empty() {
8888
break;
8989
}
90-
if expected.len() == 0 {
90+
if expected.is_empty() {
9191
panic!("unexpected line: {:?}", line);
9292
}
93-
let i = expected.find("\n").unwrap_or(expected.len() - 1);
93+
let i = expected.find('\n').unwrap_or(expected.len() - 1);
9494
let expected_line = &expected[..i + 1];
9595
expected = &expected[i + 1..];
9696
if lines_match(expected_line, &line) {
@@ -103,7 +103,7 @@ fn run(stream: impl Read + Write, rx: &Receiver<Message>) {
103103
expected_line, line
104104
)
105105
}
106-
if expected.len() != 0 {
106+
if !expected.is_empty() {
107107
println!("didn't get expected data: {:?}", expected);
108108
}
109109
}

0 commit comments

Comments
 (0)