chore: use is_empty() instead of .len() == 0 / .len() > 0 - #829
Merged
Conversation
Mechanical Clippy-style refactor across 21 files (49 occurrences). Replaces `.len() == 0` with `.is_empty()` and `.len() > 0` with `!x.is_empty()`. Verification.rs already covered by #827. Also includes a few related simplifications in link_store.rs: - Drops duplicate `is_empty() || .len() == 0` checks in link_add_key and link_remove_key (the OR-clauses were logically redundant) - Removes unreachable `is_empty()` check on `Option<&[u8; 24]>` — a fixed-size 24-byte array can never be empty - Simplifies `data_bytes.is_some() && data_bytes.as_ref().unwrap().len() > 0` in store/account/message.rs to `data_bytes.as_ref().is_some_and(|b| !b.is_empty())` Adds 6 regression tests in link_store_test.rs covering the error branches in link_add_key / link_remove_key (`"targetId provided without type"`, `"link type invalid"`) which had no prior direct coverage. Supersedes #592. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR performs an idiomatic Rust refactor replacing .len() == 0 / .len() > 0 checks with .is_empty() / !is_empty() across the codebase, and includes a small set of link_store simplifications plus regression tests for newly-covered error branches.
Changes:
- Replace empty/non-empty checks with
is_empty()/!is_empty()across storage, networking, consensus, and validation modules. - Simplify redundant/previously-unreachable validations in
src/storage/store/account/link_store.rs. - Add regression tests in
link_store_test.rscoveringlink_add_key/link_remove_keyerror branches.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/storage/trie/trie_node.rs | Uses is_empty() for key/prefix emptiness checks. |
| src/storage/store/shard.rs | Uses !is_empty() when computing next_page_token. |
| src/storage/store/engine_tests.rs | Updates test assertions to use is_empty() idioms. |
| src/storage/store/block.rs | Uses !is_empty() when computing next_page_token. |
| src/storage/store/account/username_proof_store.rs | Uses is_empty() for username proof name validation and merge-conflict checks. |
| src/storage/store/account/reaction_store.rs | Uses !is_empty() for pagination token logic. |
| src/storage/store/account/onchain_event_store.rs | Uses !is_empty() for pagination token logic in event paging. |
| src/storage/store/account/message.rs | Uses !is_empty() for page token logic and simplifies data_bytes presence/non-empty checks via is_some_and. |
| src/storage/store/account/link_store_test.rs | Adds regression tests for make_add_key / make_remove_key error branches. |
| src/storage/store/account/link_store.rs | Simplifies redundant validations and updates empty checks; removes unreachable len()==0 check on fixed-size ts-hash reference. |
| src/storage/store/account/event.rs | Uses !is_empty() for event page token logic. |
| src/storage/store/account/cast_store.rs | Uses !is_empty() for pagination token logic in cast paging. |
| src/storage/store/account/block_event_store.rs | Uses !is_empty() for pagination token logic in block-event paging. |
| src/perf/perftest.rs | Uses !is_empty() in perf statistics computations. |
| src/network/http_server.rs | Uses is_empty() in base64 optional deserialization. |
| src/network/gossip.rs | Uses !is_empty() for config override checks. |
| src/mempool/block_receiver.rs | Uses is_empty() for early returns / continues on empty event lists. |
| src/core/validations/message.rs | Uses is_empty() for required-bytes, signatures, hashes, and fname checks. |
| src/core/types.rs | Uses !is_empty() for proposer selection precondition assertions. |
| src/consensus/malachite/read_sync.rs | Uses is_empty() for peer set emptiness check. |
| src/consensus/consensus.rs | Uses !is_empty() for validator set/address configuration assertions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
5 tasks
Two issues caught by CI and Copilot review: 1. block_event_store.rs no longer needs `use tracing::error;` — the import was carried over from an older revision when the file's only call site used the macro. Rust 1.95 + -Dwarnings turns this unused import into a hard CI failure. 2. link_store.rs's link_remove_key error message was "targetID …" while link_add_key (and other stores like reaction_store) use "targetId …". Standardize on the lowercase 'd' variant; update the matching test assertion. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diff CoverageDiff: origin/main...HEAD, staged and unstaged changes
Summary
src/consensus/consensus.rssrc/network/http_server.rssrc/perf/perftest.rssrc/storage/store/account/link_store_test.rs |
topocount
approved these changes
Apr 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Mechanical Clippy-style refactor:
.len() == 0→.is_empty()and.len() > 0→!x.is_empty()across 21 files (49 occurrences).verification.rsis already handled by #827, so this PR skips it.Also includes a few related simplifications in
link_store.rsthat the refactor surfaced:is_empty() || .len() == 0checks inlink_add_key/link_remove_key— the OR-clauses were logically redundant.is_empty()check onOption<&[u8; 24]>— a fixed-size 24-byte array reference can never be empty (caught in PR chore: drop unused malloc_conf, idiomatic cleanups, and first tests for src/jobs/ #796 review).data_bytes.is_some() && data_bytes.as_ref().unwrap().len() > 0instore/account/message.rstodata_bytes.as_ref().is_some_and(|b| !b.is_empty()).Adds 6 regression tests in
link_store_test.rscovering the error branches inlink_add_key/link_remove_key("targetId provided without type","link type invalid") which had no prior direct test coverage.Supersedes #592. Split out from #796 per review feedback.
Test plan
cargo testpasses locallycargo fmt --checkpasseslink_store_testregression tests pass🤖 Generated with Claude Code