From 071b1b0c1f8a67d2eb335f510f9937da3dc803a0 Mon Sep 17 00:00:00 2001 From: Stanislav Tkach Date: Fri, 3 Jan 2025 17:27:24 +0100 Subject: [PATCH] Enable the 'arithmetic-side-effects' Clippy lint --- earthly/rust/stdcfgs/cargo_manifest/project.toml | 3 ++- earthly/rust/stdcfgs/cargo_manifest/workspace.toml | 3 ++- earthly/rust/stdcfgs/clippy.toml | 1 + examples/rust/Cargo.toml | 3 ++- examples/rust/clippy.toml | 1 + examples/rust/crates/bar/src/lib.rs | 2 +- examples/rust/crates/foo/benches/benchmark.rs | 2 +- 7 files changed, 10 insertions(+), 5 deletions(-) diff --git a/earthly/rust/stdcfgs/cargo_manifest/project.toml b/earthly/rust/stdcfgs/cargo_manifest/project.toml index 5278f2be3..f9a409dce 100644 --- a/earthly/rust/stdcfgs/cargo_manifest/project.toml +++ b/earthly/rust/stdcfgs/cargo_manifest/project.toml @@ -35,4 +35,5 @@ panic = "deny" string_slice = "deny" unchecked_duration_subtraction = "deny" unreachable = "deny" -missing_docs_in_private_items = "deny" \ No newline at end of file +missing_docs_in_private_items = "deny" +arithmetic_side_effects = "deny" diff --git a/earthly/rust/stdcfgs/cargo_manifest/workspace.toml b/earthly/rust/stdcfgs/cargo_manifest/workspace.toml index 86dfcc1be..a7d731c43 100644 --- a/earthly/rust/stdcfgs/cargo_manifest/workspace.toml +++ b/earthly/rust/stdcfgs/cargo_manifest/workspace.toml @@ -35,4 +35,5 @@ panic = "deny" string_slice = "deny" unchecked_duration_subtraction = "deny" unreachable = "deny" -missing_docs_in_private_items = "deny" \ No newline at end of file +missing_docs_in_private_items = "deny" +arithmetic_side_effects = "deny" diff --git a/earthly/rust/stdcfgs/clippy.toml b/earthly/rust/stdcfgs/clippy.toml index 7bada5473..caa289b27 100644 --- a/earthly/rust/stdcfgs/clippy.toml +++ b/earthly/rust/stdcfgs/clippy.toml @@ -1,3 +1,4 @@ allow-unwrap-in-tests = true allow-expect-in-tests = true allow-panic-in-tests = true +arithmetic-side-effects-allowed = ["num_bigint::BigInt"] diff --git a/examples/rust/Cargo.toml b/examples/rust/Cargo.toml index 6627e2aa8..cd92e7316 100644 --- a/examples/rust/Cargo.toml +++ b/examples/rust/Cargo.toml @@ -44,4 +44,5 @@ panic = "deny" string_slice = "deny" unchecked_duration_subtraction = "deny" unreachable = "deny" -missing_docs_in_private_items = "deny" \ No newline at end of file +missing_docs_in_private_items = "deny" +arithmetic_side_effects = "deny" diff --git a/examples/rust/clippy.toml b/examples/rust/clippy.toml index 7bada5473..caa289b27 100644 --- a/examples/rust/clippy.toml +++ b/examples/rust/clippy.toml @@ -1,3 +1,4 @@ allow-unwrap-in-tests = true allow-expect-in-tests = true allow-panic-in-tests = true +arithmetic-side-effects-allowed = ["num_bigint::BigInt"] diff --git a/examples/rust/crates/bar/src/lib.rs b/examples/rust/crates/bar/src/lib.rs index b814969bd..e39a3db28 100644 --- a/examples/rust/crates/bar/src/lib.rs +++ b/examples/rust/crates/bar/src/lib.rs @@ -3,7 +3,7 @@ /// Adds two numbers #[must_use] pub fn add(left: usize, right: usize) -> usize { - left + right + left.saturating_add(right) } #[cfg(test)] diff --git a/examples/rust/crates/foo/benches/benchmark.rs b/examples/rust/crates/foo/benches/benchmark.rs index 44f2086a9..676602d37 100644 --- a/examples/rust/crates/foo/benches/benchmark.rs +++ b/examples/rust/crates/foo/benches/benchmark.rs @@ -5,7 +5,7 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion}; fn fibonacci(n: u64) -> u64 { match n { 0 | 1 => 1, - n => fibonacci(n - 1) + fibonacci(n - 2), + n => fibonacci(n.saturating_sub(1)).saturating_add(fibonacci(n.saturating_sub(2))), } }