From 58e107e16f76c424697fd5b73897171f525e79df Mon Sep 17 00:00:00 2001 From: Sebastian Lorenz Date: Thu, 14 Aug 2025 12:09:15 +0200 Subject: [PATCH] all: Fix all cargo check warnings and make cargo check mandatory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes all 16 cargo check warnings across the codebase: **Cargo.toml fixes:** - Remove invalid `doc = false` key from git dependency **Dead code warnings:** - Add #[allow(dead_code)] to reference implementations and test utilities - PoI struct and helper functions (proof_of_indexing/reference.rs) - AscSubgraphEntityOp enum (runtime/wasm) - CopyVid struct (store/postgres) **Lifetime syntax warnings:** - Add explicit '_ lifetime parameters to fix confusing syntax - Fix 11 lifetime warnings across store, runtime, and utility modules **Documentation updates:** - Update CLAUDE.md to make `cargo check` mandatory alongside tests - Establish clear success criteria: tests pass + zero warnings + formatting - Add stronger enforcement language for code quality requirements All tests pass and cargo check now produces zero warnings. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- CLAUDE.md | 22 ++++++++++++++----- graph/Cargo.toml | 2 +- graph/src/components/store/write.rs | 4 ++-- .../subgraph/proof_of_indexing/reference.rs | 3 +++ graph/src/util/timed_rw_lock.rs | 8 +++---- runtime/wasm/src/module/instance.rs | 2 +- runtime/wasm/src/to_from/external.rs | 1 + store/postgres/src/relational/dsl.rs | 2 +- store/postgres/src/relational_queries.rs | 1 + store/postgres/src/subgraph_store.rs | 2 +- store/postgres/src/writable.rs | 2 +- 11 files changed, 32 insertions(+), 17 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 9f5056addcc..1f8d2cff820 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -34,12 +34,16 @@ THEGRAPH_STORE_POSTGRES_DIESEL_URL="postgresql://graph:graph@127.0.0.1:5432/grap # 🚨 MANDATORY: Format all code IMMEDIATELY after any .rs file edit cargo fmt --all -# Check code without building +# 🚨 MANDATORY: Check code for warnings and errors - MUST have zero warnings cargo check ``` -🚨 **CRITICAL REMINDER**: `cargo fmt --all` is MANDATORY after editing ANY .rs file - NO EXCEPTIONS! -This must be done from the project root BEFORE any commit. Forgetting this means you failed to follow instructions. +🚨 **CRITICAL REQUIREMENTS for ANY implementation**: +1. **`cargo fmt --all`** is MANDATORY after editing ANY .rs file - NO EXCEPTIONS! +2. **`cargo check`** MUST show zero warnings before any commit - NO EXCEPTIONS! +3. **All tests** MUST pass before any commit +4. All requirements must be met from the project root BEFORE any commit +5. Forgetting any of these means you failed to follow instructions ## High-Level Architecture @@ -91,12 +95,18 @@ Use format: `{crate-name}: {description}` - Keep commits logical and atomic - Use `git rebase -i` to clean up history before merging -### Testing Requirements +### Implementation Success Criteria +Before any commit or PR, ALL of the following MUST be satisfied: + +1. **🚨 MANDATORY**: All tests MUST pass +2. **🚨 MANDATORY**: `cargo check` MUST show zero warnings +3. **🚨 MANDATORY**: `cargo fmt --all` MUST be run after editing ANY .rs file + +**Testing Notes**: - Unit tests inline with source code -- Integration tests require Docker Compose setup and additional environment dependencies +- Integration tests require Docker Compose setup and additional environment dependencies - Claude cannot run integration tests due to missing environment dependencies - Claude must set `THEGRAPH_STORE_POSTGRES_DIESEL_URL` before running any tests -- **🚨 MANDATORY**: Always run `cargo fmt --all` after editing .rs files, BEFORE committing ### Environment Variables - `GRAPH_LOG=debug`: Enable debug logging diff --git a/graph/Cargo.toml b/graph/Cargo.toml index 35f28b959ab..09ee5e810d5 100644 --- a/graph/Cargo.toml +++ b/graph/Cargo.toml @@ -61,7 +61,7 @@ sqlparser = { workspace = true } # stable-hash_legacy = { version = "0.3.3", package = "stable-hash" } # stable-hash = { version = "0.4.2" } stable-hash = { git = "https://github.com/graphprotocol/stable-hash", branch = "main" } -stable-hash_legacy = { git = "https://github.com/graphprotocol/stable-hash", branch = "old", package = "stable-hash", doc = false } +stable-hash_legacy = { git = "https://github.com/graphprotocol/stable-hash", branch = "old", package = "stable-hash" } strum_macros = "0.27.1" slog-async = "2.5.0" slog-envlogger = "2.1.0" diff --git a/graph/src/components/store/write.rs b/graph/src/components/store/write.rs index b75d2912de2..fc0ebaea856 100644 --- a/graph/src/components/store/write.rs +++ b/graph/src/components/store/write.rs @@ -145,7 +145,7 @@ impl EntityModification { /// Return the details of the write if `self` is a write operation for a /// new or an existing entity - fn as_write(&self) -> Option { + fn as_write(&self) -> Option> { EntityWrite::try_from(self).ok() } @@ -823,7 +823,7 @@ impl Batch { &self, entity_type: &EntityType, at: BlockNumber, - ) -> impl Iterator { + ) -> impl Iterator> { self.mods .group(entity_type) .map(|group| group.effective_ops(at)) diff --git a/graph/src/components/subgraph/proof_of_indexing/reference.rs b/graph/src/components/subgraph/proof_of_indexing/reference.rs index 5c7d269d7a7..3a11a4db4e3 100644 --- a/graph/src/components/subgraph/proof_of_indexing/reference.rs +++ b/graph/src/components/subgraph/proof_of_indexing/reference.rs @@ -9,6 +9,7 @@ use web3::types::{Address, H256}; /// well-implemented (without conflicting sequence numbers, or other oddities). /// It's just way easier to check that this works, and serves as a kind of /// documentation as a side-benefit. +#[allow(dead_code)] pub struct PoI<'a> { pub causality_regions: HashMap>, pub subgraph_id: DeploymentHash, @@ -16,10 +17,12 @@ pub struct PoI<'a> { pub indexer: Option
, } +#[allow(dead_code)] fn h256_as_bytes(val: &H256) -> AsBytes<&[u8]> { AsBytes(val.as_bytes()) } +#[allow(dead_code)] fn indexer_opt_as_bytes(val: &Option
) -> Option> { val.as_ref().map(|v| AsBytes(v.as_bytes())) } diff --git a/graph/src/util/timed_rw_lock.rs b/graph/src/util/timed_rw_lock.rs index 4a52d531604..e8ff394be44 100644 --- a/graph/src/util/timed_rw_lock.rs +++ b/graph/src/util/timed_rw_lock.rs @@ -20,7 +20,7 @@ impl TimedRwLock { } } - pub fn write(&self, logger: &Logger) -> parking_lot::RwLockWriteGuard { + pub fn write(&self, logger: &Logger) -> parking_lot::RwLockWriteGuard<'_, T> { loop { let mut elapsed = Duration::from_secs(0); match self.lock.try_write_for(self.log_threshold) { @@ -36,11 +36,11 @@ impl TimedRwLock { } } - pub fn try_read(&self) -> Option> { + pub fn try_read(&self) -> Option> { self.lock.try_read() } - pub fn read(&self, logger: &Logger) -> parking_lot::RwLockReadGuard { + pub fn read(&self, logger: &Logger) -> parking_lot::RwLockReadGuard<'_, T> { loop { let mut elapsed = Duration::from_secs(0); match self.lock.try_read_for(self.log_threshold) { @@ -73,7 +73,7 @@ impl TimedMutex { } } - pub fn lock(&self, logger: &Logger) -> parking_lot::MutexGuard { + pub fn lock(&self, logger: &Logger) -> parking_lot::MutexGuard<'_, T> { let start = Instant::now(); let guard = self.lock.lock(); let elapsed = start.elapsed(); diff --git a/runtime/wasm/src/module/instance.rs b/runtime/wasm/src/module/instance.rs index 63845e81c60..cddac22f9fc 100644 --- a/runtime/wasm/src/module/instance.rs +++ b/runtime/wasm/src/module/instance.rs @@ -141,7 +141,7 @@ impl WasmInstance { self.store.into_data() } - pub(crate) fn instance_ctx(&mut self) -> WasmInstanceContext { + pub(crate) fn instance_ctx(&mut self) -> WasmInstanceContext<'_> { WasmInstanceContext::new(&mut self.store) } diff --git a/runtime/wasm/src/to_from/external.rs b/runtime/wasm/src/to_from/external.rs index 6bb7122613f..3f19716f487 100644 --- a/runtime/wasm/src/to_from/external.rs +++ b/runtime/wasm/src/to_from/external.rs @@ -466,6 +466,7 @@ where } #[derive(Debug, Clone, Eq, PartialEq, AscType)] +#[allow(dead_code)] pub enum AscSubgraphEntityOp { Create, Modify, diff --git a/store/postgres/src/relational/dsl.rs b/store/postgres/src/relational/dsl.rs index e804a4d06ca..13cab9dd9d0 100644 --- a/store/postgres/src/relational/dsl.rs +++ b/store/postgres/src/relational/dsl.rs @@ -176,7 +176,7 @@ impl<'a> Table<'a> { } /// Reference a column in this table and use the correct SQL type `ST` - fn bind(&self, name: &str) -> Option> { + fn bind(&self, name: &str) -> Option> { self.column(name).map(|c| c.bind()) } diff --git a/store/postgres/src/relational_queries.rs b/store/postgres/src/relational_queries.rs index 1fe09fb3acc..0295ed24cab 100644 --- a/store/postgres/src/relational_queries.rs +++ b/store/postgres/src/relational_queries.rs @@ -4976,6 +4976,7 @@ impl<'a, Conn> RunQueryDsl for CountCurrentVersionsQuery<'a> {} /// Helper struct for returning the id's touched by the RevertRemove and /// RevertExtend queries #[derive(QueryableByName, PartialEq, Eq, Hash)] +#[allow(dead_code)] pub struct CopyVid { #[diesel(sql_type = BigInt)] pub vid: i64, diff --git a/store/postgres/src/subgraph_store.rs b/store/postgres/src/subgraph_store.rs index 28fe5bba514..2cb2df8a0d6 100644 --- a/store/postgres/src/subgraph_store.rs +++ b/store/postgres/src/subgraph_store.rs @@ -789,7 +789,7 @@ impl SubgraphStoreInner { /// connections can deadlock the entire process if the pool runs out /// of connections in between getting the first one and trying to get the /// second one. - pub(crate) fn primary_conn(&self) -> Result { + pub(crate) fn primary_conn(&self) -> Result, StoreError> { let conn = self.mirror.primary().get()?; Ok(primary::Connection::new(conn)) } diff --git a/store/postgres/src/writable.rs b/store/postgres/src/writable.rs index 74b516433b6..9c512e27ae7 100644 --- a/store/postgres/src/writable.rs +++ b/store/postgres/src/writable.rs @@ -49,7 +49,7 @@ use crate::{primary, primary::Site, relational::Layout, SubgraphStore}; struct WritableSubgraphStore(SubgraphStore); impl WritableSubgraphStore { - fn primary_conn(&self) -> Result { + fn primary_conn(&self) -> Result, StoreError> { self.0.primary_conn() }