Fix rustc warnings

- Use `..=` for inclusive ranges
- Add the `dyn` keyword for trait objects
- Switch from `ONCE_INIT` to `std::sync::Once::new()`
This commit is contained in:
Matt Vertescher 2019-10-08 08:25:26 -04:00
parent 7c2a68c719
commit b771738a3a
6 changed files with 10 additions and 10 deletions

View File

@ -259,7 +259,7 @@ fn parse_version(version: &str) -> u64 {
// and the type specifier suffix // and the type specifier suffix
let version = version.trim_right_matches(|c: char| match c { let version = version.trim_right_matches(|c: char| match c {
'0'...'9' | 'a'...'f' | 'A'...'F' => false, '0'..='9' | 'a'..='f' | 'A'..='F' => false,
_ => true, _ => true,
}); });

View File

@ -88,10 +88,10 @@ pub type PasswordCallback = unsafe extern "C" fn(
#[cfg(ossl110)] #[cfg(ossl110)]
pub fn init() { pub fn init() {
use std::ptr; use std::ptr;
use std::sync::{Once, ONCE_INIT}; use std::sync::Once;
// explicitly initialize to work around https://github.com/openssl/openssl/issues/3505 // explicitly initialize to work around https://github.com/openssl/openssl/issues/3505
static INIT: Once = ONCE_INIT; static INIT: Once = Once::new();
INIT.call_once(|| unsafe { INIT.call_once(|| unsafe {
OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, ptr::null_mut()); OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, ptr::null_mut());

View File

@ -17,7 +17,7 @@ use error::ErrorStack;
pub struct StreamState<S> { pub struct StreamState<S> {
pub stream: S, pub stream: S,
pub error: Option<io::Error>, pub error: Option<io::Error>,
pub panic: Option<Box<Any + Send>>, pub panic: Option<Box<dyn Any + Send>>,
} }
/// Safe wrapper for BIO_METHOD /// Safe wrapper for BIO_METHOD
@ -55,7 +55,7 @@ pub unsafe fn take_error<S>(bio: *mut BIO) -> Option<io::Error> {
state.error.take() state.error.take()
} }
pub unsafe fn take_panic<S>(bio: *mut BIO) -> Option<Box<Any + Send>> { pub unsafe fn take_panic<S>(bio: *mut BIO) -> Option<Box<dyn Any + Send>> {
let state = state::<S>(bio); let state = state::<S>(bio);
state.panic.take() state.panic.take()
} }

View File

@ -127,7 +127,7 @@ impl error::Error for Error {
"an OpenSSL error" "an OpenSSL error"
} }
fn cause(&self) -> Option<&error::Error> { fn cause(&self) -> Option<&dyn error::Error> {
match self.cause { match self.cause {
Some(InnerError::Io(ref e)) => Some(e), Some(InnerError::Io(ref e)) => Some(e),
Some(InnerError::Ssl(ref e)) => Some(e), Some(InnerError::Ssl(ref e)) => Some(e),
@ -159,7 +159,7 @@ impl<S: fmt::Debug> StdError for HandshakeError<S> {
} }
} }
fn cause(&self) -> Option<&StdError> { fn cause(&self) -> Option<&dyn StdError> {
match *self { match *self {
HandshakeError::SetupFailure(ref e) => Some(e), HandshakeError::SetupFailure(ref e) => Some(e),
HandshakeError::Failure(ref s) | HandshakeError::WouldBlock(ref s) => Some(s.error()), HandshakeError::Failure(ref s) | HandshakeError::WouldBlock(ref s) => Some(s.error()),

View File

@ -46,8 +46,8 @@ impl Server {
pub struct Builder { pub struct Builder {
ctx: SslContextBuilder, ctx: SslContextBuilder,
ssl_cb: Box<FnMut(&mut SslRef) + Send>, ssl_cb: Box<dyn FnMut(&mut SslRef) + Send>,
io_cb: Box<FnMut(SslStream<TcpStream>) + Send>, io_cb: Box<dyn FnMut(SslStream<TcpStream>) + Send>,
should_error: bool, should_error: bool,
} }

View File

@ -14,7 +14,7 @@ pub struct CallbackState<F> {
cb: Option<F>, cb: Option<F>,
/// If the callback panics, we place the panic object here, to be re-thrown once OpenSSL /// If the callback panics, we place the panic object here, to be re-thrown once OpenSSL
/// returns. /// returns.
panic: Option<Box<Any + Send + 'static>>, panic: Option<Box<dyn Any + Send + 'static>>,
} }
impl<F> CallbackState<F> { impl<F> CallbackState<F> {