From c8632cd95c3cf7ba89e0b0bc09543aa259790104 Mon Sep 17 00:00:00 2001 From: Jose Garcia Crosta Date: Mon, 14 Jul 2025 15:02:10 -0300 Subject: [PATCH] Add `find_unnecessary_casts` documentation --- .../pages/en/build/smart-contracts/linter.mdx | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/apps/nextra/pages/en/build/smart-contracts/linter.mdx b/apps/nextra/pages/en/build/smart-contracts/linter.mdx index d606dd102..8d0968cc1 100644 --- a/apps/nextra/pages/en/build/smart-contracts/linter.mdx +++ b/apps/nextra/pages/en/build/smart-contracts/linter.mdx @@ -18,16 +18,16 @@ If you find any issues, please submit [bugs and feedback](https://github.com/apt Checks for patterns that look like overflow checks done in a C style: ```move // Overflow check -if (x > x + y) { +if (x > x + y) { abort 1; }; // Underflow check -if (x < x - y) { +if (x < x - y) { abort 1; }; ``` -This pattern in Move does not make sense, as it either aborts immediately or is always true/false. +This pattern in Move does not make sense, as it either aborts immediately or is always true/false. ### `almost_swapped` Checks for expression patterns that look like a failed swap attempt and notifies the user. These patterns are likely erroneous code. This currently only detects simple access patterns such as assignments to a variable or a field of a struct. Examples include: @@ -65,6 +65,22 @@ Checks for binary operations where both operands are the same, which is likely a This lint does not catch cases where the operands are vector access. +### `find_unnecessary_casts` + +Checks for unnecessary type casts where the source expression already has the same type as the target type. These casts are redundant and can be removed to improve code readability. + +For example: +```move +let x: u64 = 42; +let y = x as u64; // unnecessary cast, x is already u64 +``` + +The above can be simplified to: +```move +let x: u64 = 42; +let y = x; // cast removed +``` + ### `known_to_abort` Checks for expressions that will always abort at runtime due to known constant values that violate runtime constraints. This lint helps identify code that will deterministically fail before it reaches production.