Skip to content

Commit badb448

Browse files
authored
Fix some Clippy warnings (#356)
* fix collapsible if warning * remove needlees return * substitute write! to writeln! * remove redundant field names in struct initialization * add non exhaustive attribute in all enums in handler.rs * fix inconsistent digit grouping * simplify return of extra_description method * fix zero pointer
1 parent 87b2cbf commit badb448

File tree

6 files changed

+56
-99
lines changed

6 files changed

+56
-99
lines changed

curl-sys/build.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,19 @@ fn main() {
2323
if !cfg!(feature = "static-curl") {
2424
// OSX and Haiku ships libcurl by default, so we just use that version
2525
// so long as it has the right features enabled.
26-
if target.contains("apple") || target.contains("haiku") {
27-
if !cfg!(feature = "http2") || curl_config_reports_http2() {
28-
return println!("cargo:rustc-flags=-l curl");
29-
}
26+
if (target.contains("apple") || target.contains("haiku"))
27+
&& (!cfg!(feature = "http2") || curl_config_reports_http2())
28+
{
29+
return println!("cargo:rustc-flags=-l curl");
3030
}
3131

3232
// Next, fall back and try to use pkg-config if its available.
3333
if windows {
3434
if try_vcpkg() {
3535
return;
3636
}
37-
} else {
38-
if try_pkg_config() {
39-
return;
40-
}
37+
} else if try_pkg_config() {
38+
return;
4139
}
4240
}
4341

@@ -468,7 +466,7 @@ fn try_pkg_config() -> bool {
468466
for path in lib.include_paths.iter() {
469467
println!("cargo:include={}", path.display());
470468
}
471-
return true;
469+
true
472470
}
473471

474472
fn xcode_major_version() -> Option<u8> {
@@ -508,7 +506,7 @@ fn curl_config_reports_http2() -> bool {
508506
return false;
509507
}
510508

511-
return true;
509+
true
512510
}
513511

514512
fn macos_link_search_path() -> Option<String> {

src/easy/form.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::ffi::CString;
22
use std::fmt;
33
use std::path::Path;
4+
use std::ptr;
45

56
use curl_sys;
67
use easy::{list, List};
@@ -34,8 +35,8 @@ impl Form {
3435
/// Creates a new blank form ready for the addition of new data.
3536
pub fn new() -> Form {
3637
Form {
37-
head: 0 as *mut _,
38-
tail: 0 as *mut _,
38+
head: ptr::null_mut(),
39+
tail: ptr::null_mut(),
3940
headers: Vec::new(),
4041
buffers: Vec::new(),
4142
strings: Vec::new(),
@@ -50,10 +51,10 @@ impl Form {
5051
Part {
5152
error: None,
5253
form: self,
53-
name: name,
54+
name,
5455
array: vec![curl_sys::curl_forms {
5556
option: curl_sys::CURLFORM_END,
56-
value: 0 as *mut _,
57+
value: ptr::null_mut(),
5758
}],
5859
}
5960
}

src/easy/handler.rs

Lines changed: 21 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::ffi::{CStr, CString};
33
use std::fmt;
44
use std::io::{self, SeekFrom, Write};
55
use std::path::Path;
6+
use std::ptr;
67
use std::slice;
78
use std::str;
89
use std::time::Duration;
@@ -306,13 +307,12 @@ pub fn debug(kind: InfoType, data: &[u8]) {
306307
InfoType::HeaderOut => ">",
307308
InfoType::DataIn | InfoType::SslDataIn => "{",
308309
InfoType::DataOut | InfoType::SslDataOut => "}",
309-
InfoType::__Nonexhaustive => " ",
310310
};
311311
let mut out = out.lock();
312312
drop(write!(out, "{} ", prefix));
313313
match str::from_utf8(data) {
314314
Ok(s) => drop(out.write_all(s.as_bytes())),
315-
Err(_) => drop(write!(out, "({} bytes of data)\n", data.len())),
315+
Err(_) => drop(writeln!(out, "({} bytes of data)", data.len())),
316316
}
317317
}
318318

@@ -392,6 +392,7 @@ struct Inner<H> {
392392
unsafe impl<H: Send> Send for Inner<H> {}
393393

394394
/// Possible proxy types that libcurl currently understands.
395+
#[non_exhaustive]
395396
#[allow(missing_docs)]
396397
#[derive(Debug, Clone, Copy)]
397398
pub enum ProxyType {
@@ -401,43 +402,31 @@ pub enum ProxyType {
401402
Socks5 = curl_sys::CURLPROXY_SOCKS5 as isize,
402403
Socks4a = curl_sys::CURLPROXY_SOCKS4A as isize,
403404
Socks5Hostname = curl_sys::CURLPROXY_SOCKS5_HOSTNAME as isize,
404-
405-
/// Hidden variant to indicate that this enum should not be matched on, it
406-
/// may grow over time.
407-
#[doc(hidden)]
408-
__Nonexhaustive,
409405
}
410406

411407
/// Possible conditions for the `time_condition` method.
408+
#[non_exhaustive]
412409
#[allow(missing_docs)]
413410
#[derive(Debug, Clone, Copy)]
414411
pub enum TimeCondition {
415412
None = curl_sys::CURL_TIMECOND_NONE as isize,
416413
IfModifiedSince = curl_sys::CURL_TIMECOND_IFMODSINCE as isize,
417414
IfUnmodifiedSince = curl_sys::CURL_TIMECOND_IFUNMODSINCE as isize,
418415
LastModified = curl_sys::CURL_TIMECOND_LASTMOD as isize,
419-
420-
/// Hidden variant to indicate that this enum should not be matched on, it
421-
/// may grow over time.
422-
#[doc(hidden)]
423-
__Nonexhaustive,
424416
}
425417

426418
/// Possible values to pass to the `ip_resolve` method.
419+
#[non_exhaustive]
427420
#[allow(missing_docs)]
428421
#[derive(Debug, Clone, Copy)]
429422
pub enum IpResolve {
430423
V4 = curl_sys::CURL_IPRESOLVE_V4 as isize,
431424
V6 = curl_sys::CURL_IPRESOLVE_V6 as isize,
432425
Any = curl_sys::CURL_IPRESOLVE_WHATEVER as isize,
433-
434-
/// Hidden variant to indicate that this enum should not be matched on, it
435-
/// may grow over time.
436-
#[doc(hidden)]
437-
__Nonexhaustive = 500,
438426
}
439427

440428
/// Possible values to pass to the `http_version` method.
429+
#[non_exhaustive]
441430
#[derive(Debug, Clone, Copy)]
442431
pub enum HttpVersion {
443432
/// We don't care what http version to use, and we'd like the library to
@@ -472,14 +461,10 @@ pub enum HttpVersion {
472461
///
473462
/// (Added in CURL 7.66.0)
474463
V3 = curl_sys::CURL_HTTP_VERSION_3 as isize,
475-
476-
/// Hidden variant to indicate that this enum should not be matched on, it
477-
/// may grow over time.
478-
#[doc(hidden)]
479-
__Nonexhaustive = 500,
480464
}
481465

482466
/// Possible values to pass to the `ssl_version` and `ssl_min_max_version` method.
467+
#[non_exhaustive]
483468
#[allow(missing_docs)]
484469
#[derive(Debug, Clone, Copy)]
485470
pub enum SslVersion {
@@ -491,14 +476,10 @@ pub enum SslVersion {
491476
Tlsv11 = curl_sys::CURL_SSLVERSION_TLSv1_1 as isize,
492477
Tlsv12 = curl_sys::CURL_SSLVERSION_TLSv1_2 as isize,
493478
Tlsv13 = curl_sys::CURL_SSLVERSION_TLSv1_3 as isize,
494-
495-
/// Hidden variant to indicate that this enum should not be matched on, it
496-
/// may grow over time.
497-
#[doc(hidden)]
498-
__Nonexhaustive = 500,
499479
}
500480

501481
/// Possible return values from the `seek_function` callback.
482+
#[non_exhaustive]
502483
#[derive(Debug, Clone, Copy)]
503484
pub enum SeekResult {
504485
/// Indicates that the seek operation was a success
@@ -511,15 +492,11 @@ pub enum SeekResult {
511492
/// Indicates that although the seek failed libcurl should attempt to keep
512493
/// working if possible (for example "seek" through reading).
513494
CantSeek = curl_sys::CURL_SEEKFUNC_CANTSEEK as isize,
514-
515-
/// Hidden variant to indicate that this enum should not be matched on, it
516-
/// may grow over time.
517-
#[doc(hidden)]
518-
__Nonexhaustive = 500,
519495
}
520496

521497
/// Possible data chunks that can be witnessed as part of the `debug_function`
522498
/// callback.
499+
#[non_exhaustive]
523500
#[derive(Debug, Clone, Copy)]
524501
pub enum InfoType {
525502
/// The data is informational text.
@@ -542,38 +519,25 @@ pub enum InfoType {
542519

543520
/// The data is SSL/TLS (binary) data sent to the peer.
544521
SslDataOut,
545-
546-
/// Hidden variant to indicate that this enum should not be matched on, it
547-
/// may grow over time.
548-
#[doc(hidden)]
549-
__Nonexhaustive,
550522
}
551523

552524
/// Possible error codes that can be returned from the `read_function` callback.
525+
#[non_exhaustive]
553526
#[derive(Debug)]
554527
pub enum ReadError {
555528
/// Indicates that the connection should be aborted immediately
556529
Abort,
557530

558531
/// Indicates that reading should be paused until `unpause` is called.
559532
Pause,
560-
561-
/// Hidden variant to indicate that this enum should not be matched on, it
562-
/// may grow over time.
563-
#[doc(hidden)]
564-
__Nonexhaustive,
565533
}
566534

567535
/// Possible error codes that can be returned from the `write_function` callback.
536+
#[non_exhaustive]
568537
#[derive(Debug)]
569538
pub enum WriteError {
570539
/// Indicates that reading should be paused until `unpause` is called.
571540
Pause,
572-
573-
/// Hidden variant to indicate that this enum should not be matched on, it
574-
/// may grow over time.
575-
#[doc(hidden)]
576-
__Nonexhaustive,
577541
}
578542

579543
/// Options for `.netrc` parsing.
@@ -623,17 +587,17 @@ impl<H: Handler> Easy2<H> {
623587
assert!(!handle.is_null());
624588
let mut ret = Easy2 {
625589
inner: Box::new(Inner {
626-
handle: handle,
590+
handle,
627591
header_list: None,
628592
resolve_list: None,
629593
connect_to_list: None,
630594
form: None,
631595
error_buf: RefCell::new(vec![0; curl_sys::CURL_ERROR_SIZE]),
632-
handler: handler,
596+
handler,
633597
}),
634598
};
635599
ret.default_configure();
636-
return ret;
600+
ret
637601
}
638602
}
639603

@@ -2658,7 +2622,7 @@ impl<H> Easy2<H> {
26582622
/// if the option isn't supported.
26592623
pub fn cookies(&mut self) -> Result<List, Error> {
26602624
unsafe {
2661-
let mut list = 0 as *mut _;
2625+
let mut list = ptr::null_mut();
26622626
let rc = curl_sys::curl_easy_getinfo(
26632627
self.inner.handle,
26642628
curl_sys::CURLINFO_COOKIELIST,
@@ -2721,7 +2685,7 @@ impl<H> Easy2<H> {
27212685
pub fn perform(&self) -> Result<(), Error> {
27222686
let ret = unsafe { self.cvt(curl_sys::curl_easy_perform(self.inner.handle)) };
27232687
panic::propagate();
2724-
return ret;
2688+
ret
27252689
}
27262690

27272691
/// Unpause reading on a connection.
@@ -2781,7 +2745,7 @@ impl<H> Easy2<H> {
27812745
let ret = str::from_utf8(CStr::from_ptr(p).to_bytes()).unwrap();
27822746
let ret = String::from(ret);
27832747
curl_sys::curl_free(p as *mut _);
2784-
return ret;
2748+
ret
27852749
}
27862750
}
27872751

@@ -2815,7 +2779,7 @@ impl<H> Easy2<H> {
28152779
let slice = slice::from_raw_parts(p as *const u8, len as usize);
28162780
let ret = slice.to_vec();
28172781
curl_sys::curl_free(p as *mut _);
2818-
return ret;
2782+
ret
28192783
}
28202784
}
28212785

@@ -3060,9 +3024,7 @@ extern "C" fn write_cb<H: Handler>(
30603024
let input = slice::from_raw_parts(ptr as *const u8, size * nmemb);
30613025
match (*(data as *mut Inner<H>)).handler.write(input) {
30623026
Ok(s) => s,
3063-
Err(WriteError::Pause) | Err(WriteError::__Nonexhaustive) => {
3064-
curl_sys::CURL_WRITEFUNC_PAUSE
3065-
}
3027+
Err(WriteError::Pause) => curl_sys::CURL_WRITEFUNC_PAUSE,
30663028
}
30673029
})
30683030
.unwrap_or(!0)
@@ -3079,9 +3041,7 @@ extern "C" fn read_cb<H: Handler>(
30793041
match (*(data as *mut Inner<H>)).handler.read(input) {
30803042
Ok(s) => s,
30813043
Err(ReadError::Pause) => curl_sys::CURL_READFUNC_PAUSE,
3082-
Err(ReadError::__Nonexhaustive) | Err(ReadError::Abort) => {
3083-
curl_sys::CURL_READFUNC_ABORT
3084-
}
3044+
Err(ReadError::Abort) => curl_sys::CURL_READFUNC_ABORT,
30853045
}
30863046
})
30873047
.unwrap_or(!0)
@@ -3145,7 +3105,7 @@ extern "C" fn debug_cb<H: Handler>(
31453105
};
31463106
(*(userptr as *mut Inner<H>)).handler.debug(kind, data)
31473107
});
3148-
return 0;
3108+
0
31493109
}
31503110

31513111
extern "C" fn ssl_ctx_cb<H: Handler>(

src/easy/list.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::ffi::{CStr, CString};
22
use std::fmt;
3+
use std::ptr;
34

45
use curl_sys;
56
use Error;
@@ -21,15 +22,17 @@ pub fn raw(list: &List) -> *mut curl_sys::curl_slist {
2122
}
2223

2324
pub unsafe fn from_raw(raw: *mut curl_sys::curl_slist) -> List {
24-
List { raw: raw }
25+
List { raw }
2526
}
2627

2728
unsafe impl Send for List {}
2829

2930
impl List {
3031
/// Creates a new empty list of strings.
3132
pub fn new() -> List {
32-
List { raw: 0 as *mut _ }
33+
List {
34+
raw: ptr::null_mut(),
35+
}
3336
}
3437

3538
/// Appends some data into this list.
@@ -86,7 +89,7 @@ impl<'a> Iterator for Iter<'a> {
8689
unsafe {
8790
let ret = Some(CStr::from_ptr((*self.cur).data).to_bytes());
8891
self.cur = (*self.cur).next;
89-
return ret;
92+
ret
9093
}
9194
}
9295
}

0 commit comments

Comments
 (0)