Skip to content

chore: bump to rust edition 2024 #10802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
with:
toolchain: nightly-2024-02-03
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found out we were pinning to this specific nightly, this seems unintended / resolved

components: rustfmt
- run: cargo fmt --all --check

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ resolver = "2"

[workspace.package]
version = "1.2.3"
edition = "2021"
edition = "2024"
# Remember to update clippy.toml as well
rust-version = "1.87"
authors = ["Foundry Contributors"]
Expand Down
4 changes: 2 additions & 2 deletions crates/anvil/core/src/eth/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub struct HexIdProvider {

impl HexIdProvider {
/// Generates a random hex encoded Id
pub fn gen(&self) -> String {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gen is now a reserved keyword, found generate better than r#gen

pub fn generate(&self) -> String {
let id: String =
(&mut rng()).sample_iter(Alphanumeric).map(char::from).take(self.len).collect();
let out = hex::encode(id);
Expand All @@ -62,5 +62,5 @@ impl Default for HexIdProvider {

/// Returns a new random hex identifier
pub fn hex_id() -> String {
HexIdProvider::default().gen()
HexIdProvider::default().generate()
}
1 change: 0 additions & 1 deletion crates/anvil/server/src/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use bytes::{BufMut, BytesMut};
use futures::{ready, Sink, Stream, StreamExt};
use interprocess::local_socket::{self as ls, tokio::prelude::*};
use std::{
future::Future,
io,
pin::Pin,
task::{Context, Poll},
Expand Down
1 change: 0 additions & 1 deletion crates/anvil/server/src/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use serde::de::DeserializeOwned;
use std::{
collections::VecDeque,
fmt,
future::Future,
hash::Hash,
pin::Pin,
sync::Arc,
Expand Down
17 changes: 8 additions & 9 deletions crates/anvil/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use foundry_config::{Chain, Config, FigmentProviders};
use futures::FutureExt;
use rand_08::{rngs::StdRng, SeedableRng};
use std::{
future::Future,
net::IpAddr,
path::{Path, PathBuf},
pin::Pin,
Expand Down Expand Up @@ -287,27 +286,27 @@ impl NodeArgs {
}

fn account_generator(&self) -> AccountGenerator {
let mut gen = AccountGenerator::new(self.accounts as usize)
let mut generate = AccountGenerator::new(self.accounts as usize)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generator

.phrase(DEFAULT_MNEMONIC)
.chain_id(self.evm.chain_id.unwrap_or(CHAIN_ID.into()));
if let Some(ref mnemonic) = self.mnemonic {
gen = gen.phrase(mnemonic);
generate = generate.phrase(mnemonic);
} else if let Some(count) = self.mnemonic_random {
let mut rng = rand_08::thread_rng();
let mnemonic = match Mnemonic::<English>::new_with_count(&mut rng, count) {
Ok(mnemonic) => mnemonic.to_phrase(),
Err(_) => DEFAULT_MNEMONIC.to_string(),
};
gen = gen.phrase(mnemonic);
generate = generate.phrase(mnemonic);
} else if let Some(seed) = self.mnemonic_seed {
let mut seed = StdRng::seed_from_u64(seed);
let mnemonic = Mnemonic::<English>::new(&mut seed).to_phrase();
gen = gen.phrase(mnemonic);
generate = generate.phrase(mnemonic);
}
if let Some(ref derivation) = self.derivation_path {
gen = gen.derivation_path(derivation);
generate = generate.derivation_path(derivation);
}
gen
generate
}

/// Returns the location where to dump the state to.
Expand Down Expand Up @@ -920,11 +919,11 @@ mod tests {
["::1", "1.1.1.1", "2.2.2.2"].map(|ip| ip.parse::<IpAddr>().unwrap()).to_vec()
);

env::set_var("ANVIL_IP_ADDR", "1.1.1.1");
unsafe { env::set_var("ANVIL_IP_ADDR", "1.1.1.1"); }
let args = NodeArgs::parse_from(["anvil"]);
assert_eq!(args.host, vec!["1.1.1.1".parse::<IpAddr>().unwrap()]);

env::set_var("ANVIL_IP_ADDR", "::1,1.1.1.1,2.2.2.2");
unsafe { env::set_var("ANVIL_IP_ADDR", "::1,1.1.1.1,2.2.2.2"); }
let args = NodeArgs::parse_from(["anvil"]);
assert_eq!(
args.host,
Expand Down
18 changes: 9 additions & 9 deletions crates/anvil/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ Private Keys
let _ = write!(s, "\n({idx}) 0x{hex}");
}

if let Some(ref gen) = self.account_generator {
if let Some(ref generate) = self.account_generator {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generator

let _ = write!(
s,
r#"
Expand All @@ -242,8 +242,8 @@ Wallet
Mnemonic: {}
Derivation path: {}
"#,
gen.phrase,
gen.get_derivation_path()
generate.phrase,
generate.get_derivation_path()
);
}

Expand Down Expand Up @@ -365,9 +365,9 @@ Genesis Number
private_keys.push(format!("0x{}", hex::encode(wallet.credential().to_bytes())));
}

if let Some(ref gen) = self.account_generator {
let phrase = gen.get_phrase().to_string();
let derivation_path = gen.get_derivation_path().to_string();
if let Some(ref generate) = self.account_generator {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generator

let phrase = generate.get_phrase().to_string();
let derivation_path = generate.get_derivation_path().to_string();

wallet_description.insert("derivation_path".to_string(), derivation_path);
wallet_description.insert("mnemonic".to_string(), phrase);
Expand Down Expand Up @@ -430,7 +430,7 @@ impl Default for NodeConfig {
fn default() -> Self {
// generate some random wallets
let genesis_accounts =
AccountGenerator::new(10).phrase(DEFAULT_MNEMONIC).gen().expect("Invalid mnemonic.");
AccountGenerator::new(10).phrase(DEFAULT_MNEMONIC).generate().expect("Invalid mnemonic.");
Self {
chain_id: None,
gas_limit: None,
Expand Down Expand Up @@ -719,7 +719,7 @@ impl NodeConfig {
/// Sets both the genesis accounts and the signer accounts
/// so that `genesis_accounts == accounts`
pub fn with_account_generator(mut self, generator: AccountGenerator) -> eyre::Result<Self> {
let accounts = generator.gen()?;
let accounts = generator.generate()?;
self.account_generator = Some(generator);
Ok(self.with_signer_accounts(accounts.clone()).with_genesis_accounts(accounts))
}
Expand Down Expand Up @@ -1551,7 +1551,7 @@ impl AccountGenerator {
}

impl AccountGenerator {
pub fn gen(&self) -> eyre::Result<Vec<PrivateKeySigner>> {
pub fn generate(&self) -> eyre::Result<Vec<PrivateKeySigner>> {
let builder = MnemonicBuilder::<English>::default().phrase(self.phrase.as_str());

// use the derivation path
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/src/eth/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ use revm::{
interpreter::{return_ok, return_revert, InstructionResult},
primitives::eip7702::PER_EMPTY_ACCOUNT_COST,
};
use std::{future::Future, sync::Arc, time::Duration};
use std::{sync::Arc, time::Duration};
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver};

/// The client version: `anvil/v{major}.{minor}.{patch}`
Expand Down
1 change: 0 additions & 1 deletion crates/anvil/src/eth/fees.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{
collections::BTreeMap,
fmt,
future::Future,
pin::Pin,
sync::Arc,
task::{Context, Poll},
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Filters {
/// Returns the original `Filter` of an `eth_newFilter`
pub async fn get_log_filter(&self, id: &str) -> Option<Filter> {
let filters = self.active_filters.lock().await;
if let Some((EthFilter::Logs(ref log), _)) = filters.get(id) {
if let Some((EthFilter::Logs(log), _)) = filters.get(id) {
return log.filter.filter.clone()
}
None
Expand Down
1 change: 0 additions & 1 deletion crates/anvil/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use parking_lot::Mutex;
use revm::primitives::hardfork::SpecId;
use server::try_spawn_ipc;
use std::{
future::Future,
net::SocketAddr,
pin::Pin,
sync::Arc,
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anvil_server::{ipc::IpcEndpoint, ServerConfig};
use axum::Router;
use futures::StreamExt;
use handler::{HttpEthRpcHandler, PubSubEthRpcHandler};
use std::{future::Future, io, net::SocketAddr, pin::pin};
use std::{io, net::SocketAddr, pin::pin};
use tokio::net::TcpListener;

pub mod error;
Expand Down
1 change: 0 additions & 1 deletion crates/anvil/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::{
use futures::{FutureExt, Stream, StreamExt};
use std::{
collections::VecDeque,
future::Future,
pin::Pin,
sync::Arc,
task::{Context, Poll},
Expand Down
1 change: 0 additions & 1 deletion crates/anvil/src/shutdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use futures::{
FutureExt,
};
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
};
Expand Down
1 change: 0 additions & 1 deletion crates/anvil/src/tasks/block_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use crate::shutdown::Shutdown;
use futures::{FutureExt, Stream, StreamExt};
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
};
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/src/tasks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use alloy_primitives::B256;
use alloy_provider::Provider;
use alloy_rpc_types::anvil::Forking;
use futures::StreamExt;
use std::{fmt, future::Future};
use std::fmt;
use tokio::{runtime::Handle, task::JoinHandle};

pub mod block_listener;
Expand Down
14 changes: 7 additions & 7 deletions crates/anvil/tests/it/anvil_api.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
//! tests for custom anvil endpoints

use crate::{
abi::{self, Greeter, Multicall, BUSD},
abi::{self, BUSD, Greeter, Multicall},
fork::fork_config,
utils::http_provider_with_signer,
};
use alloy_consensus::{SignableTransaction, TxEip1559};
use alloy_hardforks::EthereumHardfork;
use alloy_network::{EthereumWallet, TransactionBuilder, TxSignerSync};
use alloy_primitives::{address, fixed_bytes, utils::Unit, Address, Bytes, TxKind, U256};
use alloy_provider::{ext::TxPoolApi, Provider};
use alloy_primitives::{Address, Bytes, TxKind, U256, address, fixed_bytes, utils::Unit};
use alloy_provider::{Provider, ext::TxPoolApi};
use alloy_rpc_types::{
BlockId, BlockNumberOrTag, TransactionRequest,
anvil::{
ForkedNetwork, Forking, Metadata, MineOptions, NodeEnvironment, NodeForkConfig, NodeInfo,
},
BlockId, BlockNumberOrTag, TransactionRequest,
};
use alloy_serde::WithOtherFields;
use anvil::{
NodeConfig,
eth::{
api::CLIENT_VERSION,
backend::mem::{EXECUTOR, P256_DELEGATION_CONTRACT, P256_DELEGATION_RUNTIME_CODE},
},
spawn, NodeConfig,
spawn,
};
use anvil_core::{
eth::{
wallet::{Capabilities, DelegationCapability, WalletCapabilities},
EthRequest,
wallet::{Capabilities, DelegationCapability, WalletCapabilities},
},
types::{ReorgOptions, TransactionData},
};
use revm::primitives::hardfork::SpecId;
use std::{
future::IntoFuture,
str::FromStr,
time::{Duration, SystemTime},
};
Expand Down
3 changes: 1 addition & 2 deletions crates/cast/src/cmd/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ pub enum SendTxSubcommands {
}

impl SendTxArgs {
#[expect(dependency_on_unit_never_type_fallback)]
pub async fn run(self) -> eyre::Result<()> {
let Self {
eth,
Expand Down Expand Up @@ -154,7 +153,7 @@ impl SendTxArgs {
if config_chain_id != current_chain_id {
sh_warn!("Switching to chain {}", config_chain)?;
provider
.raw_request(
.raw_request::<_, ()>(
"wallet_switchEthereumChain".into(),
[serde_json::json!({
"chainId": format!("0x{:x}", config_chain_id),
Expand Down
6 changes: 3 additions & 3 deletions crates/cast/src/cmd/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ fn add_storage_layout_output<C: Compiler<CompilerContract = Contract>>(project:
}

fn is_storage_layout_empty(storage_layout: &Option<StorageLayout>) -> bool {
if let Some(ref s) = storage_layout {
if let Some(s) = storage_layout {
s.storage.is_empty()
} else {
true
Expand All @@ -361,9 +361,9 @@ mod tests {
StorageArgs::parse_from(["foundry-cli", "addr.eth", "--etherscan-api-key", "dummykey"]);
assert_eq!(args.etherscan.key(), Some("dummykey".to_string()));

std::env::set_var("ETHERSCAN_API_KEY", "FXY");
unsafe { std::env::set_var("ETHERSCAN_API_KEY", "FXY"); }
let config = args.load_config().unwrap();
std::env::remove_var("ETHERSCAN_API_KEY");
unsafe { std::env::remove_var("ETHERSCAN_API_KEY"); }
assert_eq!(config.etherscan_api_key, Some("dummykey".to_string()));

let key = config.get_etherscan_api_key(None).unwrap();
Expand Down
6 changes: 3 additions & 3 deletions crates/cheatcodes/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Cheatcode for setEnvCall {
} else if value.contains('\0') {
Err(fmt_err!("environment variable value can't contain NUL character `\\0`"))
} else {
env::set_var(key, value);
unsafe { env::set_var(key, value); }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsafe is now required for things that touch the environment

Ok(Default::default())
}
}
Expand Down Expand Up @@ -308,10 +308,10 @@ mod tests {
fn parse_env_uint() {
let key = "parse_env_uint";
let value = "t";
env::set_var(key, value);
unsafe { env::set_var(key, value); }

let err = env(key, &DynSolType::Uint(256)).unwrap_err().to_string();
assert_eq!(err.matches("$parse_env_uint").count(), 2, "{err:?}");
env::remove_var(key);
unsafe { env::remove_var(key); }
}
}
2 changes: 1 addition & 1 deletion crates/cheatcodes/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl Cheatcode for copyStorageCall {
let from_storage = from_account.storage.clone();
if let Ok(mut to_account) = ccx.ecx.journaled_state.load_account(*to) {
to_account.storage = from_storage;
if let Some(ref mut arbitrary_storage) = &mut ccx.state.arbitrary_storage {
if let Some(arbitrary_storage) = &mut ccx.state.arbitrary_storage {
arbitrary_storage.mark_copy(from, to);
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl EyreHandler for Handler {
/// Panics are always caught by the more debug-centric handler.
pub fn install() {
if std::env::var_os("RUST_BACKTRACE").is_none() {
std::env::set_var("RUST_BACKTRACE", "1");
unsafe { std::env::set_var("RUST_BACKTRACE", "1"); }
}

let panic_section =
Expand Down
1 change: 0 additions & 1 deletion crates/cli/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use foundry_config::{Chain, Config};
use serde::de::DeserializeOwned;
use std::{
ffi::OsStr,
future::Future,
path::{Path, PathBuf},
process::{Command, Output, Stdio},
time::{Duration, SystemTime, UNIX_EPOCH},
Expand Down
2 changes: 1 addition & 1 deletion crates/common/fmt/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<T: UIfmt> UIfmt for &T {

impl<T: UIfmt> UIfmt for Option<T> {
fn pretty(&self) -> String {
if let Some(ref inner) = self {
if let Some(inner) = self {
inner.pretty()
} else {
String::new()
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use foundry_block_explorers::{
contract::ContractMetadata, errors::EtherscanError, Client, EtherscanApiVersion,
};
use foundry_config::Chain;
use std::{future::Future, pin::Pin};
use std::pin::Pin;

pub fn encode_args<I, S>(inputs: &[Param], args: I) -> Result<Vec<DynSolValue>>
where
Expand Down
Loading
Loading