From c13d0a21077127fbd4e2a84a2c8ec9830f0f3147 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 31 Dec 2020 19:45:38 +0100 Subject: Use edition 2018 idioms and warn when they are not followed This was mostly automated using `cargo fix --edition-idioms`. --- openssl/examples/mk_certs.rs | 2 -- openssl/src/asn1.rs | 12 ++++++------ openssl/src/bn.rs | 8 ++++---- openssl/src/dsa.rs | 2 +- openssl/src/ec.rs | 2 +- openssl/src/error.rs | 6 +++--- openssl/src/hash.rs | 2 +- openssl/src/lib.rs | 6 ++---- openssl/src/pkcs12.rs | 4 +--- openssl/src/pkcs5.rs | 2 -- openssl/src/pkey.rs | 2 +- openssl/src/rsa.rs | 2 +- openssl/src/sha.rs | 2 -- openssl/src/ssl/error.rs | 4 ++-- openssl/src/ssl/mod.rs | 8 ++++---- openssl/src/ssl/test/mod.rs | 3 +-- openssl/src/stack.rs | 13 +++++-------- openssl/src/string.rs | 8 ++++---- openssl/src/x509/extension.rs | 6 +++--- openssl/src/x509/mod.rs | 16 ++++++++-------- systest/src/main.rs | 3 --- 21 files changed, 48 insertions(+), 65 deletions(-) diff --git a/openssl/examples/mk_certs.rs b/openssl/examples/mk_certs.rs index 5c9ec682..849cc4d2 100644 --- a/openssl/examples/mk_certs.rs +++ b/openssl/examples/mk_certs.rs @@ -1,8 +1,6 @@ //! A program that generates ca certs, certs verified by the ca, and public //! and private keys. -extern crate openssl; - use openssl::asn1::Asn1Time; use openssl::bn::{BigNum, MsbOption}; use openssl::error::ErrorStack; diff --git a/openssl/src/asn1.rs b/openssl/src/asn1.rs index 69f2026a..758a5d9d 100644 --- a/openssl/src/asn1.rs +++ b/openssl/src/asn1.rs @@ -65,7 +65,7 @@ foreign_type_and_impl_send_sync! { } impl fmt::Display for Asn1GeneralizedTimeRef { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { unsafe { let mem_bio = match MemBio::new() { Err(_) => return f.write_str("error"), @@ -284,7 +284,7 @@ impl<'a> PartialOrd for &'a Asn1TimeRef { } impl fmt::Display for Asn1TimeRef { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { unsafe { let mem_bio = match MemBio::new() { Err(_) => return f.write_str("error"), @@ -300,7 +300,7 @@ impl fmt::Display for Asn1TimeRef { } impl fmt::Debug for Asn1TimeRef { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(&self.to_string()) } } @@ -481,7 +481,7 @@ impl Asn1StringRef { } impl fmt::Debug for Asn1StringRef { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { match self.as_utf8() { Ok(openssl_string) => openssl_string.fmt(fmt), Err(_) => fmt.write_str("error"), @@ -636,7 +636,7 @@ impl Asn1ObjectRef { } impl fmt::Display for Asn1ObjectRef { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { unsafe { let mut buf = [0; 80]; let len = ffi::OBJ_obj2txt( @@ -654,7 +654,7 @@ impl fmt::Display for Asn1ObjectRef { } impl fmt::Debug for Asn1ObjectRef { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.write_str(self.to_string().as_str()) } } diff --git a/openssl/src/bn.rs b/openssl/src/bn.rs index 4371e741..7a5484e3 100644 --- a/openssl/src/bn.rs +++ b/openssl/src/bn.rs @@ -1122,7 +1122,7 @@ impl BigNum { } impl fmt::Debug for BigNumRef { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.to_dec_str() { Ok(s) => f.write_str(&s), Err(e) => Err(e.into()), @@ -1131,7 +1131,7 @@ impl fmt::Debug for BigNumRef { } impl fmt::Debug for BigNum { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.to_dec_str() { Ok(s) => f.write_str(&s), Err(e) => Err(e.into()), @@ -1140,7 +1140,7 @@ impl fmt::Debug for BigNum { } impl fmt::Display for BigNumRef { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.to_dec_str() { Ok(s) => f.write_str(&s), Err(e) => Err(e.into()), @@ -1149,7 +1149,7 @@ impl fmt::Display for BigNumRef { } impl fmt::Display for BigNum { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.to_dec_str() { Ok(s) => f.write_str(&s), Err(e) => Err(e.into()), diff --git a/openssl/src/dsa.rs b/openssl/src/dsa.rs index c58c6486..11fece79 100644 --- a/openssl/src/dsa.rs +++ b/openssl/src/dsa.rs @@ -288,7 +288,7 @@ impl Dsa { } impl fmt::Debug for Dsa { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "DSA") } } diff --git a/openssl/src/ec.rs b/openssl/src/ec.rs index f43c8d3d..8218d65e 100644 --- a/openssl/src/ec.rs +++ b/openssl/src/ec.rs @@ -915,7 +915,7 @@ impl Clone for EcKey { } impl fmt::Debug for EcKey { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "EcKey") } } diff --git a/openssl/src/error.rs b/openssl/src/error.rs index 55567e2b..0fc5d015 100644 --- a/openssl/src/error.rs +++ b/openssl/src/error.rs @@ -58,7 +58,7 @@ impl ErrorStack { } impl fmt::Display for ErrorStack { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { if self.0.is_empty() { return fmt.write_str("OpenSSL error"); } @@ -236,7 +236,7 @@ impl Error { } impl fmt::Debug for Error { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { let mut builder = fmt.debug_struct("Error"); builder.field("code", &self.code()); if let Some(library) = self.library() { @@ -258,7 +258,7 @@ impl fmt::Debug for Error { } impl fmt::Display for Error { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "error:{:08X}", self.code())?; match self.library() { Some(l) => write!(fmt, ":{}", l)?, diff --git a/openssl/src/hash.rs b/openssl/src/hash.rs index c5c39a08..05f81019 100644 --- a/openssl/src/hash.rs +++ b/openssl/src/hash.rs @@ -390,7 +390,7 @@ impl AsRef<[u8]> for DigestBytes { } impl fmt::Debug for DigestBytes { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&**self, fmt) } } diff --git a/openssl/src/lib.rs b/openssl/src/lib.rs index 05c3eb8c..ca2cfc52 100644 --- a/openssl/src/lib.rs +++ b/openssl/src/lib.rs @@ -109,6 +109,7 @@ //! ctx.set_ciphersuites("TLS_AES_256_GCM_SHA384:TLS_AES_128_GCM_SHA256").unwrap(); //! ``` #![doc(html_root_url = "https://docs.rs/openssl/0.10")] +#![warn(rust_2018_idioms)] #[macro_use] extern crate bitflags; @@ -116,14 +117,11 @@ extern crate bitflags; extern crate cfg_if; #[macro_use] extern crate foreign_types; -extern crate libc; -extern crate once_cell; + extern crate openssl_sys as ffi; #[cfg(test)] extern crate hex; -#[cfg(test)] -extern crate tempdir; #[doc(inline)] pub use ffi::init; diff --git a/openssl/src/pkcs12.rs b/openssl/src/pkcs12.rs index b2764786..4e61d291 100644 --- a/openssl/src/pkcs12.rs +++ b/openssl/src/pkcs12.rs @@ -197,10 +197,8 @@ impl Pkcs12Builder { #[cfg(test)] mod test { - use crate::hash::MessageDigest; - use hex; - use crate::asn1::Asn1Time; + use crate::hash::MessageDigest; use crate::nid::Nid; use crate::pkey::PKey; use crate::rsa::Rsa; diff --git a/openssl/src/pkcs5.rs b/openssl/src/pkcs5.rs index 6cc9609c..370db4da 100644 --- a/openssl/src/pkcs5.rs +++ b/openssl/src/pkcs5.rs @@ -281,8 +281,6 @@ mod tests { #[test] #[cfg(any(ossl110))] fn scrypt() { - use hex; - let pass = "pleaseletmein"; let salt = "SodiumChloride"; let expected = diff --git a/openssl/src/pkey.rs b/openssl/src/pkey.rs index dcf941af..8c9c6999 100644 --- a/openssl/src/pkey.rs +++ b/openssl/src/pkey.rs @@ -292,7 +292,7 @@ where } impl fmt::Debug for PKey { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { let alg = match self.id() { Id::RSA => "RSA", Id::HMAC => "HMAC", diff --git a/openssl/src/rsa.rs b/openssl/src/rsa.rs index 446da6ab..8ff9965e 100644 --- a/openssl/src/rsa.rs +++ b/openssl/src/rsa.rs @@ -651,7 +651,7 @@ impl Rsa { } impl fmt::Debug for Rsa { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Rsa") } } diff --git a/openssl/src/sha.rs b/openssl/src/sha.rs index d6e69385..232ad856 100644 --- a/openssl/src/sha.rs +++ b/openssl/src/sha.rs @@ -341,8 +341,6 @@ impl Sha512 { #[cfg(test)] mod test { - use hex; - use super::*; #[test] diff --git a/openssl/src/ssl/error.rs b/openssl/src/ssl/error.rs index 06cbb35e..5ec3e56a 100644 --- a/openssl/src/ssl/error.rs +++ b/openssl/src/ssl/error.rs @@ -99,7 +99,7 @@ impl From for Error { } impl fmt::Display for Error { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { match self.code { ErrorCode::ZERO_RETURN => fmt.write_str("the SSL session has been shut down"), ErrorCode::WANT_READ => match self.io_error() { @@ -157,7 +157,7 @@ impl StdError for HandshakeError { } impl fmt::Display for HandshakeError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { HandshakeError::SetupFailure(ref e) => write!(f, "stream setup failed: {}", e)?, HandshakeError::Failure(ref s) => { diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index 93a3bf0a..2328106c 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -1843,7 +1843,7 @@ impl ToOwned for SslContextRef { // TODO: add useful info here impl fmt::Debug for SslContext { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "SslContext") } } @@ -2346,7 +2346,7 @@ foreign_type_and_impl_send_sync! { } impl fmt::Debug for Ssl { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&**self, fmt) } } @@ -2441,7 +2441,7 @@ impl Ssl { } impl fmt::Debug for SslRef { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("Ssl") .field("state", &self.state_string_long()) .field("verify_result", &self.verify_result()) @@ -3469,7 +3469,7 @@ impl fmt::Debug for SslStream where S: fmt::Debug, { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("SslStream") .field("stream", &self.get_ref()) .field("ssl", &self.ssl()) diff --git a/openssl/src/ssl/test/mod.rs b/openssl/src/ssl/test/mod.rs index e145d22b..8d350224 100644 --- a/openssl/src/ssl/test/mod.rs +++ b/openssl/src/ssl/test/mod.rs @@ -1,6 +1,5 @@ #![allow(unused_imports)] -use hex; use std::env; use std::fs::File; use std::io::prelude::*; @@ -1196,7 +1195,7 @@ fn stateless() { self.incoming.get_mut().extend_from_slice(data); } - pub fn take_outgoing(&mut self) -> Outgoing { + pub fn take_outgoing(&mut self) -> Outgoing<'_> { Outgoing(&mut self.outgoing) } } diff --git a/openssl/src/stack.rs b/openssl/src/stack.rs index b412029b..e5f32c77 100644 --- a/openssl/src/stack.rs +++ b/openssl/src/stack.rs @@ -50,7 +50,7 @@ where T: Stackable, T::Ref: fmt::Debug, { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_list().entries(self).finish() } } @@ -199,14 +199,14 @@ impl StackRef { self.len() == 0 } - pub fn iter(&self) -> Iter { + pub fn iter(&self) -> Iter<'_, T> { Iter { stack: self, idxs: 0..self.len() as c_int, } } - pub fn iter_mut(&mut self) -> IterMut { + pub fn iter_mut(&mut self) -> IterMut<'_, T> { IterMut { idxs: 0..self.len() as c_int, stack: self, @@ -310,10 +310,7 @@ impl<'a, T: Stackable> iter::IntoIterator for &'a mut Stack { } /// An iterator over the stack's contents. -pub struct Iter<'a, T: Stackable> -where - T: 'a, -{ +pub struct Iter<'a, T: Stackable> { stack: &'a StackRef, idxs: Range, } @@ -347,7 +344,7 @@ impl<'a, T: Stackable> DoubleEndedIterator for Iter<'a, T> { impl<'a, T: Stackable> ExactSizeIterator for Iter<'a, T> {} /// A mutable iterator over the stack's contents. -pub struct IterMut<'a, T: Stackable + 'a> { +pub struct IterMut<'a, T: Stackable> { stack: &'a mut StackRef, idxs: Range, } diff --git a/openssl/src/string.rs b/openssl/src/string.rs index f20e8434..5dd1f1ae 100644 --- a/openssl/src/string.rs +++ b/openssl/src/string.rs @@ -18,13 +18,13 @@ foreign_type_and_impl_send_sync! { } impl fmt::Display for OpensslString { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(&**self, f) } } impl fmt::Debug for OpensslString { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&**self, f) } } @@ -69,13 +69,13 @@ impl AsRef<[u8]> for OpensslStringRef { } impl fmt::Display for OpensslStringRef { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(&**self, f) } } impl fmt::Debug for OpensslStringRef { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&**self, f) } } diff --git a/openssl/src/x509/extension.rs b/openssl/src/x509/extension.rs index dd4899c8..efe70f2b 100644 --- a/openssl/src/x509/extension.rs +++ b/openssl/src/x509/extension.rs @@ -397,7 +397,7 @@ impl SubjectKeyIdentifier { } /// Return a `SubjectKeyIdentifier` extension as an `X509Extension`. - pub fn build(&self, ctx: &X509v3Context) -> Result { + pub fn build(&self, ctx: &X509v3Context<'_>) -> Result { let mut value = String::new(); let mut first = true; append(&mut value, &mut first, self.critical, "critical"); @@ -449,7 +449,7 @@ impl AuthorityKeyIdentifier { } /// Return a `AuthorityKeyIdentifier` extension as an `X509Extension`. - pub fn build(&self, ctx: &X509v3Context) -> Result { + pub fn build(&self, ctx: &X509v3Context<'_>) -> Result { let mut value = String::new(); let mut first = true; append(&mut value, &mut first, self.critical, "critical"); @@ -538,7 +538,7 @@ impl SubjectAlternativeName { } /// Return a `SubjectAlternativeName` extension as an `X509Extension`. - pub fn build(&self, ctx: &X509v3Context) -> Result { + pub fn build(&self, ctx: &X509v3Context<'_>) -> Result { let mut value = String::new(); let mut first = true; append(&mut value, &mut first, self.critical, "critical"); diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs index ad983fbd..b982be43 100644 --- a/openssl/src/x509/mod.rs +++ b/openssl/src/x509/mod.rs @@ -678,7 +678,7 @@ impl Clone for X509 { } impl fmt::Debug for X509 { - fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { let serial = match &self.serial_number().to_bn() { Ok(bn) => match bn.to_hex_str() { Ok(hex) => hex.to_string(), @@ -749,7 +749,7 @@ impl X509Extension { /// See the extension module for builder types which will construct certain common extensions. pub fn new( conf: Option<&ConfRef>, - context: Option<&X509v3Context>, + context: Option<&X509v3Context<'_>>, name: &str, value: &str, ) -> Result { @@ -775,7 +775,7 @@ impl X509Extension { /// See the extension module for builder types which will construct certain common extensions. pub fn new_nid( conf: Option<&ConfRef>, - context: Option<&X509v3Context>, + context: Option<&X509v3Context<'_>>, name: Nid, value: &str, ) -> Result { @@ -956,7 +956,7 @@ impl X509NameRef { } impl fmt::Debug for X509NameRef { - fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { formatter.debug_list().entries(self.entries()).finish() } } @@ -1036,7 +1036,7 @@ impl X509NameEntryRef { } impl fmt::Debug for X509NameEntryRef { - fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { formatter.write_fmt(format_args!("{:?} = {:?}", self.object(), self.data())) } } @@ -1283,7 +1283,7 @@ impl X509ReqRef { pub struct X509VerifyResult(c_int); impl fmt::Debug for X509VerifyResult { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("X509VerifyResult") .field("code", &self.0) .field("error", &self.error_string()) @@ -1292,7 +1292,7 @@ impl fmt::Debug for X509VerifyResult { } impl fmt::Display for X509VerifyResult { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.write_str(self.error_string()) } } @@ -1397,7 +1397,7 @@ impl GeneralNameRef { } impl fmt::Debug for GeneralNameRef { - fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { if let Some(email) = self.email() { formatter.write_str(email) } else if let Some(dnsname) = self.dnsname() { diff --git a/systest/src/main.rs b/systest/src/main.rs index 3e5888c8..cbfa3da6 100644 --- a/systest/src/main.rs +++ b/systest/src/main.rs @@ -1,8 +1,5 @@ #![allow(bad_style, clippy::all)] -extern crate libc; -extern crate openssl_sys; - use libc::*; use openssl_sys::*; -- cgit v1.2.3