Add lints (and fix warnings) for Rust 2018 code.

This commit is contained in:
Isis Lovecruft 2018-12-30 03:13:13 +00:00
parent ce857a50e7
commit 1cf581d67d
No known key found for this signature in database
GPG key ID: AB41313533E8E812
4 changed files with 20 additions and 24 deletions

View file

@ -36,16 +36,16 @@ use curve25519_dalek::edwards::CompressedEdwardsY;
use curve25519_dalek::edwards::EdwardsPoint; use curve25519_dalek::edwards::EdwardsPoint;
use curve25519_dalek::scalar::Scalar; use curve25519_dalek::scalar::Scalar;
pub use constants::*; pub use crate::constants::*;
pub use errors::*; pub use crate::errors::*;
pub use signature::*; pub use crate::signature::*;
/// An EdDSA secret key. /// An EdDSA secret key.
#[derive(Default)] // we derive Default in order to use the clear() method in Drop #[derive(Default)] // we derive Default in order to use the clear() method in Drop
pub struct SecretKey(pub (crate) [u8; SECRET_KEY_LENGTH]); pub struct SecretKey(pub (crate) [u8; SECRET_KEY_LENGTH]);
impl Debug for SecretKey { impl Debug for SecretKey {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
write!(f, "SecretKey: {:?}", &self.0[..]) write!(f, "SecretKey: {:?}", &self.0[..])
} }
} }
@ -198,7 +198,7 @@ impl<'d> Deserialize<'d> for SecretKey {
impl<'d> Visitor<'d> for SecretKeyVisitor { impl<'d> Visitor<'d> for SecretKeyVisitor {
type Value = SecretKey; type Value = SecretKey;
fn expecting(&self, formatter: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { fn expecting(&self, formatter: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
formatter.write_str("An ed25519 secret key as 32 bytes, as specified in RFC8032.") formatter.write_str("An ed25519 secret key as 32 bytes, as specified in RFC8032.")
} }
@ -528,7 +528,7 @@ impl<'d> Deserialize<'d> for ExpandedSecretKey {
impl<'d> Visitor<'d> for ExpandedSecretKeyVisitor { impl<'d> Visitor<'d> for ExpandedSecretKeyVisitor {
type Value = ExpandedSecretKey; type Value = ExpandedSecretKey;
fn expecting(&self, formatter: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { fn expecting(&self, formatter: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
formatter.write_str("An ed25519 expanded secret key as 64 bytes, as specified in RFC8032.") formatter.write_str("An ed25519 expanded secret key as 64 bytes, as specified in RFC8032.")
} }
@ -548,7 +548,7 @@ pub struct PublicKey(
); );
impl Debug for PublicKey { impl Debug for PublicKey {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
write!(f, "PublicKey({:?}), {:?})", self.0, self.1) write!(f, "PublicKey({:?}), {:?})", self.0, self.1)
} }
} }
@ -880,7 +880,7 @@ impl<'d> Deserialize<'d> for PublicKey {
impl<'d> Visitor<'d> for PublicKeyVisitor { impl<'d> Visitor<'d> for PublicKeyVisitor {
type Value = PublicKey; type Value = PublicKey;
fn expecting(&self, formatter: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { fn expecting(&self, formatter: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
formatter.write_str("An ed25519 public key as a 32-byte compressed point, as specified in RFC8032") formatter.write_str("An ed25519 public key as a 32-byte compressed point, as specified in RFC8032")
} }
@ -1202,7 +1202,7 @@ impl<'d> Deserialize<'d> for Keypair {
impl<'d> Visitor<'d> for KeypairVisitor { impl<'d> Visitor<'d> for KeypairVisitor {
type Value = Keypair; type Value = Keypair;
fn expecting(&self, formatter: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { fn expecting(&self, formatter: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
formatter.write_str("An ed25519 keypair, 64 bytes in total where the secret key is \ formatter.write_str("An ed25519 keypair, 64 bytes in total where the secret key is \
the first 32 bytes and is in unexpanded form, and the second \ the first 32 bytes and is in unexpanded form, and the second \
32 bytes is a compressed point for a public key.") 32 bytes is a compressed point for a public key.")

View file

@ -33,7 +33,7 @@ pub (crate) enum InternalError {
} }
impl Display for InternalError { impl Display for InternalError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self { match *self {
InternalError::PointDecompressionError InternalError::PointDecompressionError
=> write!(f, "Cannot decompress Edwards point"), => write!(f, "Cannot decompress Edwards point"),
@ -67,13 +67,13 @@ impl ::failure::Fail for InternalError {}
pub struct SignatureError(pub (crate) InternalError); pub struct SignatureError(pub (crate) InternalError);
impl Display for SignatureError { impl Display for SignatureError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0) write!(f, "{}", self.0)
} }
} }
impl ::failure::Fail for SignatureError { impl ::failure::Fail for SignatureError {
fn cause(&self) -> Option<&::failure::Fail> { fn cause(&self) -> Option<&dyn (::failure::Fail)> {
Some(&self.0) Some(&self.0)
} }
} }

View file

@ -238,6 +238,9 @@
//! ``` //! ```
#![no_std] #![no_std]
#![warn(future_incompatible)]
#![warn(rust_2018_compatibility)]
#![warn(rust_2018_idioms)]
#![deny(missing_docs)] // refuse to compile if documentation is missing #![deny(missing_docs)] // refuse to compile if documentation is missing
extern crate clear_on_drop; extern crate clear_on_drop;
@ -251,15 +254,9 @@ extern crate std;
extern crate sha2; extern crate sha2;
#[cfg(test)]
extern crate hex;
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
extern crate serde; extern crate serde;
#[cfg(all(test, feature = "serde"))]
extern crate bincode;
mod constants; mod constants;
mod ed25519; mod ed25519;
mod signature; mod signature;
@ -267,5 +264,4 @@ mod signature;
pub mod errors; pub mod errors;
// Export everything public in ed25519. // Export everything public in ed25519.
pub use ed25519::*; pub use crate::ed25519::*;
pub use errors::*;

View file

@ -23,8 +23,8 @@ use serde::de::Error as SerdeError;
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::de::Visitor; use serde::de::Visitor;
use constants::*; use crate::constants::*;
use errors::*; use crate::errors::*;
/// An ed25519 signature. /// An ed25519 signature.
/// ///
@ -64,7 +64,7 @@ impl Clone for Signature {
} }
impl Debug for Signature { impl Debug for Signature {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
write!(f, "Signature( R: {:?}, s: {:?} )", &self.R, &self.s) write!(f, "Signature( R: {:?}, s: {:?} )", &self.R, &self.s)
} }
} }
@ -116,7 +116,7 @@ impl<'d> Deserialize<'d> for Signature {
impl<'d> Visitor<'d> for SignatureVisitor { impl<'d> Visitor<'d> for SignatureVisitor {
type Value = Signature; type Value = Signature;
fn expecting(&self, formatter: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { fn expecting(&self, formatter: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
formatter.write_str("An ed25519 signature as 64 bytes, as specified in RFC8032.") formatter.write_str("An ed25519 signature as 64 bytes, as specified in RFC8032.")
} }