Bump the MSRV to 1.62 and using #[derive(Default)] on enums (#3304)

## Issue Addressed

N/A

## Proposed Changes

Since Rust 1.62, we can use `#[derive(Default)]` on enums.  

https://blog.rust-lang.org/2022/06/30/Rust-1.62.0.html#default-enum-variants

There are no changes to functionality in this PR, just replaced the `Default` trait implementation with `#[derive(Default)]`.
This commit is contained in:
Akihito Nakano 2022-07-15 07:31:19 +00:00
parent 1f54e10b7b
commit 98a9626ef5
8 changed files with 15 additions and 37 deletions

View File

@ -18,6 +18,9 @@ jobs:
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- name: Get latest version of stable Rust
run: rustup update stable
- name: Install ganache - name: Install ganache
run: npm install ganache@latest --global run: npm install ganache@latest --global

View File

@ -1,4 +1,4 @@
FROM rust:1.58.1-bullseye AS builder FROM rust:1.62.0-bullseye AS builder
RUN apt-get update && apt-get -y upgrade && apt-get install -y cmake libclang-dev RUN apt-get update && apt-get -y upgrade && apt-get install -y cmake libclang-dev
COPY . lighthouse COPY . lighthouse
ARG FEATURES ARG FEATURES

View File

@ -10,7 +10,7 @@ use types::{Graffiti, PublicKeyBytes};
const DEFAULT_FREEZER_DB_DIR: &str = "freezer_db"; const DEFAULT_FREEZER_DB_DIR: &str = "freezer_db";
/// Defines how the client should initialize the `BeaconChain` and other components. /// Defines how the client should initialize the `BeaconChain` and other components.
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub enum ClientGenesis { pub enum ClientGenesis {
/// Creates a genesis state as per the 2019 Canada interop specifications. /// Creates a genesis state as per the 2019 Canada interop specifications.
Interop { Interop {
@ -21,6 +21,7 @@ pub enum ClientGenesis {
FromStore, FromStore,
/// Connects to an eth1 node and waits until it can create the genesis state from the deposit /// Connects to an eth1 node and waits until it can create the genesis state from the deposit
/// contract. /// contract.
#[default]
DepositContract, DepositContract,
/// Loads the genesis state from SSZ-encoded `BeaconState` bytes. /// Loads the genesis state from SSZ-encoded `BeaconState` bytes.
/// ///
@ -38,12 +39,6 @@ pub enum ClientGenesis {
}, },
} }
impl Default for ClientGenesis {
fn default() -> Self {
Self::DepositContract
}
}
/// The core configuration of a Lighthouse beacon node. /// The core configuration of a Lighthouse beacon node.
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config { pub struct Config {

View File

@ -477,7 +477,7 @@ pub enum ConnectionDirection {
} }
/// Connection Status of the peer. /// Connection Status of the peer.
#[derive(Debug, Clone)] #[derive(Debug, Clone, Default)]
pub enum PeerConnectionStatus { pub enum PeerConnectionStatus {
/// The peer is connected. /// The peer is connected.
Connected { Connected {
@ -507,6 +507,7 @@ pub enum PeerConnectionStatus {
since: Instant, since: Instant,
}, },
/// The connection status has not been specified. /// The connection status has not been specified.
#[default]
Unknown, Unknown,
} }
@ -561,9 +562,3 @@ impl Serialize for PeerConnectionStatus {
} }
} }
} }
impl Default for PeerConnectionStatus {
fn default() -> Self {
PeerConnectionStatus::Unknown
}
}

View File

@ -78,18 +78,13 @@ impl std::fmt::Display for GossipKind {
} }
/// The known encoding types for gossipsub messages. /// The known encoding types for gossipsub messages.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)] #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash, Default)]
pub enum GossipEncoding { pub enum GossipEncoding {
/// Messages are encoded with SSZSnappy. /// Messages are encoded with SSZSnappy.
#[default]
SSZSnappy, SSZSnappy,
} }
impl Default for GossipEncoding {
fn default() -> Self {
GossipEncoding::SSZSnappy
}
}
impl GossipTopic { impl GossipTopic {
pub fn new(kind: GossipKind, encoding: GossipEncoding, fork_digest: [u8; 4]) -> Self { pub fn new(kind: GossipKind, encoding: GossipEncoding, fork_digest: [u8; 4]) -> Self {
GossipTopic { GossipTopic {

View File

@ -58,9 +58,10 @@ impl Kdf {
} }
/// PRF for use in `pbkdf2`. /// PRF for use in `pbkdf2`.
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Default)]
pub enum Prf { pub enum Prf {
#[serde(rename = "hmac-sha256")] #[serde(rename = "hmac-sha256")]
#[default]
HmacSha256, HmacSha256,
} }
@ -73,12 +74,6 @@ impl Prf {
} }
} }
impl Default for Prf {
fn default() -> Self {
Prf::HmacSha256
}
}
/// Parameters for `pbkdf2` key derivation. /// Parameters for `pbkdf2` key derivation.
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)] #[serde(deny_unknown_fields)]

View File

@ -4,7 +4,7 @@ version = "2.3.2-rc.0"
authors = ["Sigma Prime <contact@sigmaprime.io>"] authors = ["Sigma Prime <contact@sigmaprime.io>"]
edition = "2021" edition = "2021"
autotests = false autotests = false
rust-version = "1.58" rust-version = "1.62"
[features] [features]
# Writes debugging .ssz files to /tmp during block processing. # Writes debugging .ssz files to /tmp during block processing.

View File

@ -2,20 +2,15 @@ use self::BlsSetting::*;
use crate::error::Error; use crate::error::Error;
use serde_repr::Deserialize_repr; use serde_repr::Deserialize_repr;
#[derive(Deserialize_repr, Debug, Clone, Copy)] #[derive(Deserialize_repr, Debug, Clone, Copy, Default)]
#[repr(u8)] #[repr(u8)]
pub enum BlsSetting { pub enum BlsSetting {
#[default]
Flexible = 0, Flexible = 0,
Required = 1, Required = 1,
Ignored = 2, Ignored = 2,
} }
impl Default for BlsSetting {
fn default() -> Self {
Flexible
}
}
impl BlsSetting { impl BlsSetting {
/// Check the BLS setting and skip the test if it isn't compatible with the crypto config. /// Check the BLS setting and skip the test if it isn't compatible with the crypto config.
pub fn check(self) -> Result<(), Error> { pub fn check(self) -> Result<(), Error> {