From 7969a86a71dab5070be935871e809484c158fcfa Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Fri, 7 Jun 2024 11:07:05 +0200 Subject: [PATCH 1/5] chore: Stop using RUSTFLAGS to configure Clippy lints --- .cargo/config.toml | 83 -------------------------------- Cargo.toml | 83 ++++++++++++++++++++++++++++++++ crates/edr_defaults/Cargo.toml | 3 ++ crates/edr_eth/Cargo.toml | 3 ++ crates/edr_evm/Cargo.toml | 3 ++ crates/edr_napi/Cargo.toml | 3 ++ crates/edr_provider/Cargo.toml | 3 ++ crates/edr_rpc_client/Cargo.toml | 3 ++ crates/edr_rpc_eth/Cargo.toml | 3 ++ crates/edr_solidity/Cargo.toml | 3 ++ crates/edr_test_utils/Cargo.toml | 3 ++ crates/tools/Cargo.toml | 3 ++ 12 files changed, 113 insertions(+), 83 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index d3d5453bd..ac8440302 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -3,86 +3,3 @@ gen-execution-api = "run --bin tools -- gen-execution-api" scenario = "run --release --bin tools -- scenario" scenario-with-tracing = "run --release --features tracing --bin tools -- scenario" replay-block = "run --release --bin tools -- replay-block" - -[target.'cfg(all())'] -rustflags = [ - "-Wclippy::all", - "-Wclippy::await_holding_lock", - "-Wclippy::bool-to-int-with-if", - "-Wclippy::cast_lossless", - "-Wclippy::char_lit_as_u8", - "-Wclippy::checked_conversions", - "-Wclippy::dbg_macro", - "-Wclippy::debug_assert_with_mut_call", - "-Wclippy::default_trait_access", - "-Wclippy::doc_markdown", - "-Wclippy::empty_enum", - "-Wclippy::enum_glob_use", - "-Wclippy::exit", - "-Wclippy::expl_impl_clone_on_copy", - "-Wclippy::explicit_deref_methods", - "-Wclippy::explicit_into_iter_loop", - "-Wclippy::fallible_impl_from", - "-Wclippy::filter_map_next", - "-Wclippy::flat_map_option", - "-Wclippy::float_cmp_const", - "-Wclippy::fn_params_excessive_bools", - "-Wclippy::from_iter_instead_of_collect", - "-Wclippy::if-not-else", - "-Wclippy::implicit_clone", - "-Wclippy::imprecise_flops", - "-Wclippy::inconsistent_struct_constructor", - "-Wclippy::inefficient_to_string", - "-Wclippy::invalid_upcast_comparisons", - "-Wclippy::items-after-statements", - "-Wclippy::large_digit_groups", - "-Wclippy::large_stack_arrays", - "-Wclippy::large_types_passed_by_value", - "-Wclippy::let_unit_value", - "-Wclippy::linkedlist", - "-Wclippy::lossy_float_literal", - "-Wclippy::macro_use_imports", - "-Wclippy::manual-assert", - "-Wclippy::manual_ok_or", - "-Wclippy::map_err_ignore", - "-Wclippy::map_flatten", - "-Wclippy::map_unwrap_or", - "-Wclippy::match_on_vec_items", - "-Wclippy::match_same_arms", - "-Wclippy::match_wild_err_arm", - "-Wclippy::match_wildcard_for_single_variants", - "-Wclippy::mem_forget", - "-Wclippy::missing_enforced_import_renames", - "-Wclippy::mut_mut", - "-Wclippy::mutex_integer", - "-Wclippy::needless_borrow", - "-Wclippy::needless_continue", - "-Wclippy::needless_for_each", - "-Wclippy::option_option", - "-Wclippy::path_buf_push_overwrite", - "-Wclippy::ptr_as_ptr", - "-Wclippy::rc_mutex", - "-Wclippy::redundant_closure_for_method_calls", - "-Wclippy::ref_option_ref", - "-Wclippy::rest_pat_in_fully_bound_structs", - "-Wclippy::same_functions_in_if_condition", - "-Wclippy::semicolon_if_nothing_returned", - "-Wclippy::single_match_else", - "-Wclippy::string_add_assign", - "-Wclippy::string_add", - "-Wclippy::string_lit_as_bytes", - "-Wclippy::string_to_string", - "-Wclippy::todo", - "-Wclippy::trait_duplication_in_bounds", - "-Wclippy::unimplemented", - "-Wclippy::uninlined_format_args", - "-Wclippy::unnested_or_patterns", - "-Wclippy::unused_self", - "-Wclippy::useless_transmute", - "-Wclippy::verbose_file_reads", - "-Wclippy::wildcard-imports", - "-Wclippy::zero_sized_map_values", - "-Wfuture_incompatible", - "-Wnonstandard_style", - "-Wrust_2018_idioms", -] diff --git a/Cargo.toml b/Cargo.toml index 1c2772e7b..7a057d929 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,86 @@ rpath = true [profile.test] opt-level = 2 + +[workspace.lints.rust] +rust_2018_idioms = "warn" +nonstandard_style = "warn" +future_incompatible = "warn" + +[workspace.lints.clippy] +all = "warn" +await_holding_lock = "warn" +bool-to-int-with-if = "warn" +cast_lossless = "warn" +char_lit_as_u8 = "warn" +checked_conversions = "warn" +dbg_macro = "warn" +debug_assert_with_mut_call = "warn" +default_trait_access = "warn" +doc_markdown = "warn" +empty_enum = "warn" +enum_glob_use = "warn" +exit = "warn" +expl_impl_clone_on_copy = "warn" +explicit_deref_methods = "warn" +explicit_into_iter_loop = "warn" +fallible_impl_from = "warn" +filter_map_next = "warn" +flat_map_option = "warn" +float_cmp_const = "warn" +fn_params_excessive_bools = "warn" +from_iter_instead_of_collect = "warn" +if-not-else = "warn" +implicit_clone = "warn" +imprecise_flops = "warn" +inconsistent_struct_constructor = "warn" +inefficient_to_string = "warn" +invalid_upcast_comparisons = "warn" +items-after-statements = "warn" +large_digit_groups = "warn" +large_stack_arrays = "warn" +large_types_passed_by_value = "warn" +let_unit_value = "warn" +linkedlist = "warn" +lossy_float_literal = "warn" +macro_use_imports = "warn" +manual-assert = "warn" +manual_ok_or = "warn" +map_err_ignore = "warn" +map_flatten = "warn" +map_unwrap_or = "warn" +match_on_vec_items = "warn" +match_same_arms = "warn" +match_wild_err_arm = "warn" +match_wildcard_for_single_variants = "warn" +mem_forget = "warn" +missing_enforced_import_renames = "warn" +mut_mut = "warn" +mutex_integer = "warn" +needless_borrow = "warn" +needless_continue = "warn" +needless_for_each = "warn" +option_option = "warn" +path_buf_push_overwrite = "warn" +ptr_as_ptr = "warn" +rc_mutex = "warn" +redundant_closure_for_method_calls = "warn" +ref_option_ref = "warn" +rest_pat_in_fully_bound_structs = "warn" +same_functions_in_if_condition = "warn" +semicolon_if_nothing_returned = "warn" +single_match_else = "warn" +string_add_assign = "warn" +string_add = "warn" +string_lit_as_bytes = "warn" +string_to_string = "warn" +todo = "warn" +trait_duplication_in_bounds = "warn" +unimplemented = "warn" +uninlined_format_args = "warn" +unnested_or_patterns = "warn" +unused_self = "warn" +useless_transmute = "warn" +verbose_file_reads = "warn" +wildcard-imports = "warn" +zero_sized_map_values = "warn" diff --git a/crates/edr_defaults/Cargo.toml b/crates/edr_defaults/Cargo.toml index d81d59951..be20c2750 100644 --- a/crates/edr_defaults/Cargo.toml +++ b/crates/edr_defaults/Cargo.toml @@ -4,3 +4,6 @@ version = "0.3.5" edition = "2021" [dependencies] + +[lints] +workspace = true diff --git a/crates/edr_eth/Cargo.toml b/crates/edr_eth/Cargo.toml index 10a51647f..c92760b39 100644 --- a/crates/edr_eth/Cargo.toml +++ b/crates/edr_eth/Cargo.toml @@ -42,3 +42,6 @@ serde = ["dep:serde", "c-kzg/serde", "revm-primitives/serde"] std = ["hash256-std-hasher/std", "hash-db/std", "hex/std", "itertools/use_std", "k256/std", "k256/precomputed-tables", "revm-primitives/std", "serde?/std", "sha2/std", "sha3/std", "triehash/std"] test-remote = [] tracing = ["dep:tracing"] + +[lints] +workspace = true diff --git a/crates/edr_evm/Cargo.toml b/crates/edr_evm/Cargo.toml index e60ade5d5..1e8251083 100644 --- a/crates/edr_evm/Cargo.toml +++ b/crates/edr_evm/Cargo.toml @@ -40,3 +40,6 @@ tempfile = "3.7.1" test-remote = [] test-utils = [] tracing = ["dep:tracing", "edr_eth/tracing"] + +[lints] +workspace = true diff --git a/crates/edr_napi/Cargo.toml b/crates/edr_napi/Cargo.toml index d131215aa..2c5515f3f 100644 --- a/crates/edr_napi/Cargo.toml +++ b/crates/edr_napi/Cargo.toml @@ -53,3 +53,6 @@ scenarios = ["rand"] [profile.release] lto = true + +[lints] +workspace = true diff --git a/crates/edr_provider/Cargo.toml b/crates/edr_provider/Cargo.toml index 605381da3..1217a998b 100644 --- a/crates/edr_provider/Cargo.toml +++ b/crates/edr_provider/Cargo.toml @@ -43,3 +43,6 @@ toml = { version = "0.5.9", default-features = false } [features] test-utils = ["anyhow"] tracing = ["dep:tracing", "edr_eth/tracing", "edr_evm/tracing"] + +[lints] +workspace = true diff --git a/crates/edr_rpc_client/Cargo.toml b/crates/edr_rpc_client/Cargo.toml index 34f2dbb0d..38b512356 100644 --- a/crates/edr_rpc_client/Cargo.toml +++ b/crates/edr_rpc_client/Cargo.toml @@ -33,3 +33,6 @@ walkdir = { version = "2.3.3", default-features = false } [features] test-remote = [] tracing = ["dep:tracing", "dep:reqwest-tracing"] + +[lints] +workspace = true diff --git a/crates/edr_rpc_eth/Cargo.toml b/crates/edr_rpc_eth/Cargo.toml index 018dcb4ba..7e77b9308 100644 --- a/crates/edr_rpc_eth/Cargo.toml +++ b/crates/edr_rpc_eth/Cargo.toml @@ -25,3 +25,6 @@ walkdir = { version = "2.3.3", default-features = false } [features] test-remote = [] tracing = ["dep:tracing", "edr_rpc_client/tracing"] + +[lints] +workspace = true diff --git a/crates/edr_solidity/Cargo.toml b/crates/edr_solidity/Cargo.toml index a7e3b351b..bd955c838 100644 --- a/crates/edr_solidity/Cargo.toml +++ b/crates/edr_solidity/Cargo.toml @@ -6,3 +6,6 @@ edition = "2021" [dependencies] edr_eth = { version = "0.3.5", path = "../edr_eth" } edr_evm = { version = "0.3.5", path = "../edr_evm" } + +[lints] +workspace = true diff --git a/crates/edr_test_utils/Cargo.toml b/crates/edr_test_utils/Cargo.toml index 8fc4f8b03..eb7dda584 100644 --- a/crates/edr_test_utils/Cargo.toml +++ b/crates/edr_test_utils/Cargo.toml @@ -6,3 +6,6 @@ edition = "2021" [dependencies] serde = { version = "1.0.147", default-features = false, features = ["derive"] } serde_json = { version = "1.0.89" } + +[lints] +workspace = true diff --git a/crates/tools/Cargo.toml b/crates/tools/Cargo.toml index 6e45ef080..51bd4202c 100644 --- a/crates/tools/Cargo.toml +++ b/crates/tools/Cargo.toml @@ -29,3 +29,6 @@ walkdir = { version = "2.4.0", features = [] } [features] tracing = ["dep:tracing", "dep:tracing-flame", "dep:tracing-subscriber", "edr_eth/tracing", "edr_evm/tracing", "edr_provider/tracing"] + +[lints] +workspace = true From 8997a91dc7337f32eabb59eb7fe365d4f0619e96 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Fri, 7 Jun 2024 11:32:27 +0200 Subject: [PATCH 2/5] chore: Remove now unneeded workaround for RUSTFLAGS --- .cargo-husky/hooks/pre-commit | 10 +++++----- .github/workflows/edr-ci.yml | 10 ++++------ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.cargo-husky/hooks/pre-commit b/.cargo-husky/hooks/pre-commit index 88660b911..f00158d47 100755 --- a/.cargo-husky/hooks/pre-commit +++ b/.cargo-husky/hooks/pre-commit @@ -1,7 +1,8 @@ #!/bin/sh # -# Intended to be in sync with .github/workflows/hardhat-core-ci.yml's -# test-edr-rs +# Intended to be in sync with .github/workflows/edr-ci.yml's `test-edr-rs` job. + +export RUSTFLAGS=-Dwarnings if [ -z "${ALCHEMY_URL}" ] || [ -z "${INFURA_URL}" ]; then echo WARNING: skipping remote tests because the ALCHEMY_URL and INFURA_URL environment variables are not defined. Local test results may differ from those in CI. @@ -13,9 +14,8 @@ fi # Set -x here to avoid printing secrets set -xe -# Setting RUSTFLAGS env for clippy makes it not include custom rules -RUSTFLAGS=-Dwarnings cargo check --workspace --all-targets ${ALL_FEATURES} -cargo clippy --all --all-targets ${ALL_FEATURES} -- -D warnings +cargo check --workspace --all-targets ${ALL_FEATURES} +cargo clippy --all --all-targets ${ALL_FEATURES} cargo +nightly fmt --all -- --check cargo test --doc --workspace ${ALL_FEATURES} cargo test --workspace --all-targets ${ALL_FEATURES} diff --git a/.github/workflows/edr-ci.yml b/.github/workflows/edr-ci.yml index fc99af2d8..48abe1224 100644 --- a/.github/workflows/edr-ci.yml +++ b/.github/workflows/edr-ci.yml @@ -21,6 +21,10 @@ on: - "crates/**" workflow_dispatch: +env: + RUSTFLAGS: -Dwarnings + RUSTDOCFLAGS: "-D warnings" + concurrency: group: ${{github.workflow}}-${{github.ref}} cancel-in-progress: true @@ -29,10 +33,6 @@ jobs: check-edr: name: Check EDR runs-on: ubuntu-latest - # Setting RUSTFLAGS env for clippy makes it not include custom rules - env: - RUSTFLAGS: -Dwarnings - RUSTDOCFLAGS: "-D warnings" steps: - uses: actions/checkout@v3 @@ -170,8 +170,6 @@ jobs: - name: Cargo doc uses: actions-rs/cargo@v1 - env: - RUSTDOCFLAGS: "-D warnings" with: command: doc args: --workspace --no-deps --all-features From 4cb876aeb8ccd2bb357a88e237f97d31330d3d86 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Fri, 7 Jun 2024 12:35:55 +0200 Subject: [PATCH 3/5] chore: Speed up pre-commit checks and reuse build cache more --- .cargo-husky/hooks/pre-commit | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.cargo-husky/hooks/pre-commit b/.cargo-husky/hooks/pre-commit index f00158d47..2154bde16 100755 --- a/.cargo-husky/hooks/pre-commit +++ b/.cargo-husky/hooks/pre-commit @@ -2,7 +2,6 @@ # # Intended to be in sync with .github/workflows/edr-ci.yml's `test-edr-rs` job. -export RUSTFLAGS=-Dwarnings if [ -z "${ALCHEMY_URL}" ] || [ -z "${INFURA_URL}" ]; then echo WARNING: skipping remote tests because the ALCHEMY_URL and INFURA_URL environment variables are not defined. Local test results may differ from those in CI. @@ -14,8 +13,11 @@ fi # Set -x here to avoid printing secrets set -xe -cargo check --workspace --all-targets ${ALL_FEATURES} -cargo clippy --all --all-targets ${ALL_FEATURES} +# Do not modify or set RUSTFLAGS as this overrides any flags that may have been set +# by the user and prevents from reusing the build cache. +# See https://github.com/rust-lang/cargo/issues/8424#issuecomment-1734683743 and the thread. + +cargo clippy --workspace --all-targets ${ALL_FEATURES} -- --deny warnings cargo +nightly fmt --all -- --check cargo test --doc --workspace ${ALL_FEATURES} cargo test --workspace --all-targets ${ALL_FEATURES} From 0192adbd1d5499b2575e8cefd3d06876e2df7efe Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Fri, 7 Jun 2024 12:45:29 +0200 Subject: [PATCH 4/5] fixup: Use consistent syntax in RUSTDOCFLAGS to deny warnings --- .github/workflows/edr-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/edr-ci.yml b/.github/workflows/edr-ci.yml index 48abe1224..50355083c 100644 --- a/.github/workflows/edr-ci.yml +++ b/.github/workflows/edr-ci.yml @@ -23,7 +23,7 @@ on: env: RUSTFLAGS: -Dwarnings - RUSTDOCFLAGS: "-D warnings" + RUSTDOCFLAGS: -Dwarnings concurrency: group: ${{github.workflow}}-${{github.ref}} From 74a90148714c1a80c4274db019a7b2ea65b331a4 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Fri, 7 Jun 2024 19:24:09 +0200 Subject: [PATCH 5/5] Fix rust lint ordering in Cargo.toml --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7a057d929..f9a29ab3d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,9 +14,9 @@ rpath = true opt-level = 2 [workspace.lints.rust] -rust_2018_idioms = "warn" -nonstandard_style = "warn" future_incompatible = "warn" +nonstandard_style = "warn" +rust_2018_idioms = "warn" [workspace.lints.clippy] all = "warn"