-
Notifications
You must be signed in to change notification settings - Fork 3
fix: handle arithmetic panics #45
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
Merged
Merged
Conversation
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
- Remove unused imports - Add Default trait implementations for Logger and ResolveLogger - Simplify unnecessary clone and ref patterns 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Add clippy allow attributes to suppress arithmetic_side_effects warnings in prost and pbjson generated code: - Apply to all generated proto types via prost config - Inject before each impl block in serde files post-generation This reduces clippy errors from 363 to 43 when arithmetic_side_effects lint is enabled. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Change bucket() to return Fallible<usize> instead of Option<usize> for better error context when buckets is 0 - Add explicit zero-check with meaningful error tag :bucket.zero_buckets - Remove unnecessary .or_fail() calls at bucket() call sites - Add clippy::arithmetic_side_effects allow on bucket() function with comment explaining buckets != 0 is checked - Add clippy allows to err.rs helper functions (fnv1a64, b64u6) This addresses PR feedback from @andreas-karlsson about using Result/Fallible for better error handling instead of Option. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Remove unnecessary wrapping_add/wrapping_sub in loop counters and base64 encoding. The #[allow(clippy::arithmetic_side_effects)] attribute is sufficient - only the hash multiplication actually needs wrapping behavior. This makes the code simpler and closer to the main branch while still satisfying clippy. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
andreas-karlsson
approved these changes
Oct 9, 2025
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.
Enable clippy arithmetic side effects lint and fix violations
This PR enables strict clippy lints to catch potential runtime panics from arithmetic operations and fixes all violations in the codebase.
Background
The Rust resolver has
#![deny(...)]
directives for several clippy lints includingarithmetic_side_effects
,panic
,unwrap_used
,expect_used
, andindexing_slicing
. These lints help prevent runtime panics in production code.Changes
1. Fixed arithmetic operations throughout the codebase
err.rs
: Use wrapping arithmetic for error code calculationsflag_logger.rs
: Use saturating arithmetic for counter incrementsgzip.rs
: Use checked arithmetic operations with proper error handlinglib.rs
: Use checked/saturating operations for bucket hashing and time calculationsresolve_logger.rs
: Add overflow protection2. Improved proto-generated code handling
The previous approach only suppressed
arithmetic_side_effects
in generated code. However, proto-generated code can violate multiple clippy lints (panic, unwrap, indexing, etc.).Solution: Suppress all clippy warnings in proto-generated code by:
#[allow(...)]
attributes to prost-generated types viaconfig.type_attribute()
impl
blockThis approach follows the pattern from rust-clippy#702 for handling generated code.
Testing
cargo clippy --all-targets --all-features
passes for confidence_resolver