diff --git a/curl-sys/build.rs b/curl-sys/build.rs index debbfae978..ae74528ec9 100644 --- a/curl-sys/build.rs +++ b/curl-sys/build.rs @@ -23,10 +23,10 @@ fn main() { if !cfg!(feature = "static-curl") { // OSX and Haiku ships libcurl by default, so we just use that version // so long as it has the right features enabled. - if target.contains("apple") || target.contains("haiku") { - if !cfg!(feature = "http2") || curl_config_reports_http2() { - return println!("cargo:rustc-flags=-l curl"); - } + if (target.contains("apple") || target.contains("haiku")) + && (!cfg!(feature = "http2") || curl_config_reports_http2()) + { + return println!("cargo:rustc-flags=-l curl"); } // Next, fall back and try to use pkg-config if its available. @@ -34,10 +34,8 @@ fn main() { if try_vcpkg() { return; } - } else { - if try_pkg_config() { - return; - } + } else if try_pkg_config() { + return; } } @@ -468,7 +466,7 @@ fn try_pkg_config() -> bool { for path in lib.include_paths.iter() { println!("cargo:include={}", path.display()); } - return true; + true } fn xcode_major_version() -> Option { @@ -508,7 +506,7 @@ fn curl_config_reports_http2() -> bool { return false; } - return true; + true } fn macos_link_search_path() -> Option { diff --git a/src/easy/form.rs b/src/easy/form.rs index 1262830101..0e5e243ab2 100644 --- a/src/easy/form.rs +++ b/src/easy/form.rs @@ -1,6 +1,7 @@ use std::ffi::CString; use std::fmt; use std::path::Path; +use std::ptr; use curl_sys; use easy::{list, List}; @@ -34,8 +35,8 @@ impl Form { /// Creates a new blank form ready for the addition of new data. pub fn new() -> Form { Form { - head: 0 as *mut _, - tail: 0 as *mut _, + head: ptr::null_mut(), + tail: ptr::null_mut(), headers: Vec::new(), buffers: Vec::new(), strings: Vec::new(), @@ -50,10 +51,10 @@ impl Form { Part { error: None, form: self, - name: name, + name, array: vec![curl_sys::curl_forms { option: curl_sys::CURLFORM_END, - value: 0 as *mut _, + value: ptr::null_mut(), }], } } diff --git a/src/easy/handler.rs b/src/easy/handler.rs index c70f2588d6..e505809f8b 100644 --- a/src/easy/handler.rs +++ b/src/easy/handler.rs @@ -3,6 +3,7 @@ use std::ffi::{CStr, CString}; use std::fmt; use std::io::{self, SeekFrom, Write}; use std::path::Path; +use std::ptr; use std::slice; use std::str; use std::time::Duration; @@ -306,13 +307,12 @@ pub fn debug(kind: InfoType, data: &[u8]) { InfoType::HeaderOut => ">", InfoType::DataIn | InfoType::SslDataIn => "{", InfoType::DataOut | InfoType::SslDataOut => "}", - InfoType::__Nonexhaustive => " ", }; let mut out = out.lock(); drop(write!(out, "{} ", prefix)); match str::from_utf8(data) { Ok(s) => drop(out.write_all(s.as_bytes())), - Err(_) => drop(write!(out, "({} bytes of data)\n", data.len())), + Err(_) => drop(writeln!(out, "({} bytes of data)", data.len())), } } @@ -392,6 +392,7 @@ struct Inner { unsafe impl Send for Inner {} /// Possible proxy types that libcurl currently understands. +#[non_exhaustive] #[allow(missing_docs)] #[derive(Debug, Clone, Copy)] pub enum ProxyType { @@ -401,14 +402,10 @@ pub enum ProxyType { Socks5 = curl_sys::CURLPROXY_SOCKS5 as isize, Socks4a = curl_sys::CURLPROXY_SOCKS4A as isize, Socks5Hostname = curl_sys::CURLPROXY_SOCKS5_HOSTNAME as isize, - - /// Hidden variant to indicate that this enum should not be matched on, it - /// may grow over time. - #[doc(hidden)] - __Nonexhaustive, } /// Possible conditions for the `time_condition` method. +#[non_exhaustive] #[allow(missing_docs)] #[derive(Debug, Clone, Copy)] pub enum TimeCondition { @@ -416,28 +413,20 @@ pub enum TimeCondition { IfModifiedSince = curl_sys::CURL_TIMECOND_IFMODSINCE as isize, IfUnmodifiedSince = curl_sys::CURL_TIMECOND_IFUNMODSINCE as isize, LastModified = curl_sys::CURL_TIMECOND_LASTMOD as isize, - - /// Hidden variant to indicate that this enum should not be matched on, it - /// may grow over time. - #[doc(hidden)] - __Nonexhaustive, } /// Possible values to pass to the `ip_resolve` method. +#[non_exhaustive] #[allow(missing_docs)] #[derive(Debug, Clone, Copy)] pub enum IpResolve { V4 = curl_sys::CURL_IPRESOLVE_V4 as isize, V6 = curl_sys::CURL_IPRESOLVE_V6 as isize, Any = curl_sys::CURL_IPRESOLVE_WHATEVER as isize, - - /// Hidden variant to indicate that this enum should not be matched on, it - /// may grow over time. - #[doc(hidden)] - __Nonexhaustive = 500, } /// Possible values to pass to the `http_version` method. +#[non_exhaustive] #[derive(Debug, Clone, Copy)] pub enum HttpVersion { /// We don't care what http version to use, and we'd like the library to @@ -472,14 +461,10 @@ pub enum HttpVersion { /// /// (Added in CURL 7.66.0) V3 = curl_sys::CURL_HTTP_VERSION_3 as isize, - - /// Hidden variant to indicate that this enum should not be matched on, it - /// may grow over time. - #[doc(hidden)] - __Nonexhaustive = 500, } /// Possible values to pass to the `ssl_version` and `ssl_min_max_version` method. +#[non_exhaustive] #[allow(missing_docs)] #[derive(Debug, Clone, Copy)] pub enum SslVersion { @@ -491,14 +476,10 @@ pub enum SslVersion { Tlsv11 = curl_sys::CURL_SSLVERSION_TLSv1_1 as isize, Tlsv12 = curl_sys::CURL_SSLVERSION_TLSv1_2 as isize, Tlsv13 = curl_sys::CURL_SSLVERSION_TLSv1_3 as isize, - - /// Hidden variant to indicate that this enum should not be matched on, it - /// may grow over time. - #[doc(hidden)] - __Nonexhaustive = 500, } /// Possible return values from the `seek_function` callback. +#[non_exhaustive] #[derive(Debug, Clone, Copy)] pub enum SeekResult { /// Indicates that the seek operation was a success @@ -511,15 +492,11 @@ pub enum SeekResult { /// Indicates that although the seek failed libcurl should attempt to keep /// working if possible (for example "seek" through reading). CantSeek = curl_sys::CURL_SEEKFUNC_CANTSEEK as isize, - - /// Hidden variant to indicate that this enum should not be matched on, it - /// may grow over time. - #[doc(hidden)] - __Nonexhaustive = 500, } /// Possible data chunks that can be witnessed as part of the `debug_function` /// callback. +#[non_exhaustive] #[derive(Debug, Clone, Copy)] pub enum InfoType { /// The data is informational text. @@ -542,14 +519,10 @@ pub enum InfoType { /// The data is SSL/TLS (binary) data sent to the peer. SslDataOut, - - /// Hidden variant to indicate that this enum should not be matched on, it - /// may grow over time. - #[doc(hidden)] - __Nonexhaustive, } /// Possible error codes that can be returned from the `read_function` callback. +#[non_exhaustive] #[derive(Debug)] pub enum ReadError { /// Indicates that the connection should be aborted immediately @@ -557,23 +530,14 @@ pub enum ReadError { /// Indicates that reading should be paused until `unpause` is called. Pause, - - /// Hidden variant to indicate that this enum should not be matched on, it - /// may grow over time. - #[doc(hidden)] - __Nonexhaustive, } /// Possible error codes that can be returned from the `write_function` callback. +#[non_exhaustive] #[derive(Debug)] pub enum WriteError { /// Indicates that reading should be paused until `unpause` is called. Pause, - - /// Hidden variant to indicate that this enum should not be matched on, it - /// may grow over time. - #[doc(hidden)] - __Nonexhaustive, } /// Options for `.netrc` parsing. @@ -623,17 +587,17 @@ impl Easy2 { assert!(!handle.is_null()); let mut ret = Easy2 { inner: Box::new(Inner { - handle: handle, + handle, header_list: None, resolve_list: None, connect_to_list: None, form: None, error_buf: RefCell::new(vec![0; curl_sys::CURL_ERROR_SIZE]), - handler: handler, + handler, }), }; ret.default_configure(); - return ret; + ret } } @@ -2658,7 +2622,7 @@ impl Easy2 { /// if the option isn't supported. pub fn cookies(&mut self) -> Result { unsafe { - let mut list = 0 as *mut _; + let mut list = ptr::null_mut(); let rc = curl_sys::curl_easy_getinfo( self.inner.handle, curl_sys::CURLINFO_COOKIELIST, @@ -2721,7 +2685,7 @@ impl Easy2 { pub fn perform(&self) -> Result<(), Error> { let ret = unsafe { self.cvt(curl_sys::curl_easy_perform(self.inner.handle)) }; panic::propagate(); - return ret; + ret } /// Unpause reading on a connection. @@ -2781,7 +2745,7 @@ impl Easy2 { let ret = str::from_utf8(CStr::from_ptr(p).to_bytes()).unwrap(); let ret = String::from(ret); curl_sys::curl_free(p as *mut _); - return ret; + ret } } @@ -2815,7 +2779,7 @@ impl Easy2 { let slice = slice::from_raw_parts(p as *const u8, len as usize); let ret = slice.to_vec(); curl_sys::curl_free(p as *mut _); - return ret; + ret } } @@ -3060,9 +3024,7 @@ extern "C" fn write_cb( let input = slice::from_raw_parts(ptr as *const u8, size * nmemb); match (*(data as *mut Inner)).handler.write(input) { Ok(s) => s, - Err(WriteError::Pause) | Err(WriteError::__Nonexhaustive) => { - curl_sys::CURL_WRITEFUNC_PAUSE - } + Err(WriteError::Pause) => curl_sys::CURL_WRITEFUNC_PAUSE, } }) .unwrap_or(!0) @@ -3079,9 +3041,7 @@ extern "C" fn read_cb( match (*(data as *mut Inner)).handler.read(input) { Ok(s) => s, Err(ReadError::Pause) => curl_sys::CURL_READFUNC_PAUSE, - Err(ReadError::__Nonexhaustive) | Err(ReadError::Abort) => { - curl_sys::CURL_READFUNC_ABORT - } + Err(ReadError::Abort) => curl_sys::CURL_READFUNC_ABORT, } }) .unwrap_or(!0) @@ -3145,7 +3105,7 @@ extern "C" fn debug_cb( }; (*(userptr as *mut Inner)).handler.debug(kind, data) }); - return 0; + 0 } extern "C" fn ssl_ctx_cb( diff --git a/src/easy/list.rs b/src/easy/list.rs index af18f8a0d9..b2c34bcea9 100644 --- a/src/easy/list.rs +++ b/src/easy/list.rs @@ -1,5 +1,6 @@ use std::ffi::{CStr, CString}; use std::fmt; +use std::ptr; use curl_sys; use Error; @@ -21,7 +22,7 @@ pub fn raw(list: &List) -> *mut curl_sys::curl_slist { } pub unsafe fn from_raw(raw: *mut curl_sys::curl_slist) -> List { - List { raw: raw } + List { raw } } unsafe impl Send for List {} @@ -29,7 +30,9 @@ unsafe impl Send for List {} impl List { /// Creates a new empty list of strings. pub fn new() -> List { - List { raw: 0 as *mut _ } + List { + raw: ptr::null_mut(), + } } /// Appends some data into this list. @@ -86,7 +89,7 @@ impl<'a> Iterator for Iter<'a> { unsafe { let ret = Some(CStr::from_ptr((*self.cur).data).to_bytes()); self.cur = (*self.cur).next; - return ret; + ret } } } diff --git a/src/error.rs b/src/error.rs index 5c7972bc0b..56f0a45edd 100644 --- a/src/error.rs +++ b/src/error.rs @@ -18,10 +18,7 @@ pub struct Error { impl Error { /// Creates a new error from the underlying code returned by libcurl. pub fn new(code: curl_sys::CURLcode) -> Error { - Error { - code: code, - extra: None, - } + Error { code, extra: None } } /// Stores some extra information about this error inside this error. @@ -315,7 +312,7 @@ impl Error { /// Returns the extra description of this error, if any is available. pub fn extra_description(&self) -> Option<&str> { - self.extra.as_ref().map(|s| &**s) + self.extra.as_deref() } } @@ -352,7 +349,7 @@ pub struct ShareError { impl ShareError { /// Creates a new error from the underlying code returned by libcurl. pub fn new(code: curl_sys::CURLSHcode) -> ShareError { - ShareError { code: code } + ShareError { code } } /// Returns whether this error corresponds to CURLSHE_BAD_OPTION. @@ -425,7 +422,7 @@ pub struct MultiError { impl MultiError { /// Creates a new error from the underlying code returned by libcurl. pub fn new(code: curl_sys::CURLMcode) -> MultiError { - MultiError { code: code } + MultiError { code } } /// Returns whether this error corresponds to CURLM_BAD_HANDLE. @@ -511,7 +508,7 @@ pub struct FormError { impl FormError { /// Creates a new error from the underlying code returned by libcurl. pub fn new(code: curl_sys::CURLFORMcode) -> FormError { - FormError { code: code } + FormError { code } } /// Returns whether this error corresponds to CURL_FORMADD_MEMORY. diff --git a/src/multi.rs b/src/multi.rs index 9205e38b26..ebc9606f19 100644 --- a/src/multi.rs +++ b/src/multi.rs @@ -2,6 +2,7 @@ use std::fmt; use std::marker; +use std::ptr; use std::time::Duration; use curl_sys; @@ -379,7 +380,7 @@ impl Multi { cvt(curl_sys::curl_multi_add_handle(self.raw, easy.raw()))?; } Ok(EasyHandle { - easy: easy, + easy, _marker: marker::PhantomData, }) } @@ -390,7 +391,7 @@ impl Multi { cvt(curl_sys::curl_multi_add_handle(self.raw, easy.raw()))?; } Ok(Easy2Handle { - easy: easy, + easy, _marker: marker::PhantomData, }) } @@ -448,10 +449,7 @@ impl Multi { if ptr.is_null() { break; } - f(Message { - ptr: ptr, - _multi: self, - }) + f(Message { ptr, _multi: self }) } } } @@ -579,7 +577,7 @@ impl Multi { // Duration too large, clamp at maximum value. i32::max_value() } else { - secs as i32 * 1000 + timeout.subsec_nanos() as i32 / 1000_000 + secs as i32 * 1000 + timeout.subsec_nanos() as i32 / 1_000_000 } }; unsafe { @@ -682,9 +680,9 @@ impl Multi { ) -> Result, MultiError> { unsafe { let mut ret = 0; - let read = read.map(|r| r as *mut _).unwrap_or(0 as *mut _); - let write = write.map(|r| r as *mut _).unwrap_or(0 as *mut _); - let except = except.map(|r| r as *mut _).unwrap_or(0 as *mut _); + let read = read.map(|r| r as *mut _).unwrap_or(ptr::null_mut()); + let write = write.map(|r| r as *mut _).unwrap_or(ptr::null_mut()); + let except = except.map(|r| r as *mut _).unwrap_or(ptr::null_mut()); cvt(curl_sys::curl_multi_fdset( self.raw, read, write, except, &mut ret, ))?; @@ -950,7 +948,7 @@ impl<'multi> Message<'multi> { e.set_extra(s); } } - return err; + err } /// Same as `result`, except only returns `Some` for the specified handle. @@ -968,7 +966,7 @@ impl<'multi> Message<'multi> { e.set_extra(s); } } - return err; + err } /// Returns whether this easy message was for the specified easy handle or @@ -1167,7 +1165,7 @@ impl From for WaitFd { WaitFd { inner: curl_sys::curl_waitfd { fd: pfd.fd, - events: events, + events, revents: 0, }, }