SonarSource Rules
  • Products

    In-IDE

    Code Quality and Security in your IDE with SonarQube Ide

    IDE extension that lets you fix coding issues before they exist!

    Discover SonarQube for IDE

    SaaS

    Code Quality and Security in the cloud with SonarQube Cloud

    Setup is effortless and analysis is automatic for most languages

    Discover SonarQube Cloud

    Self-Hosted

    Code Quality and Security Self-Hosted with SonarQube Server

    Fast, accurate analysis; enterprise scalability

    Discover SonarQube Server
  • SecretsSecrets
  • ABAPABAP
  • AnsibleAnsible
  • ApexApex
  • AzureResourceManagerAzureResourceManager
  • CC
  • C#C#
  • C++C++
  • CloudFormationCloudFormation
  • COBOLCOBOL
  • CSSCSS
  • DartDart
  • DockerDocker
  • FlexFlex
  • GitHub ActionsGitHub Actions
  • GoGo
  • HTMLHTML
  • JavaJava
  • JavaScriptJavaScript
  • JSONJSON
  • JCLJCL
  • KotlinKotlin
  • KubernetesKubernetes
  • Objective CObjective C
  • PHPPHP
  • PL/IPL/I
  • PL/SQLPL/SQL
  • PythonPython
  • RPGRPG
  • RubyRuby
  • RustRust
  • ScalaScala
  • ShellShell
  • SwiftSwift
  • TerraformTerraform
  • TextText
  • TypeScriptTypeScript
  • T-SQLT-SQL
  • VB.NETVB.NET
  • VB6VB6
  • XMLXML
  • YAMLYAML
Rust

Rust static code analysis

Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your RUST code

  • All rules 85
  • Bug60
  • Code Smell25

  • Quick Fix 4
Filtered: 83 rules found
clippy
    Impact
      Clean code attribute
        1. Match expression conditions should not have boolean type

           Code Smell
        2. Non-empty statements should change control flow or have at least one side-effect

           Bug
        3. Infinite iterators should be finished off with a terminating operation

           Bug
        4. `saturating_sub` should be used to avoid subtraction underflow

           Bug
        5. `mem::uninitialized` and `mem::zeroed()` should not be used to replace values

           Bug
        6. Conflicting `Borrow` and `Hash` implementations should be avoided

           Bug
        7. Serde `visit_str` method should be implemented when `visit_string` is implemented

           Bug
        8. `set_len` should not be called on uninitialized vectors

           Bug
        9. Inherent shadowing definitions of to_string should be avoided

           Bug
        10. Calls to `step_by` that always panic should not be made

           Bug
        11. `skip(0)` should not be used on iterators

           Bug
        12. The return value of `next` should not be looped over

           Bug
        13. Numeric literal suffixes should not be mistyped

           Bug
        14. Functions should not return mutable references from immutable parameters

           Bug
        15. Remainder operations with `1` or `-1` should be avoided

           Bug
        16. Synchronization locks should not be dropped immediately after acquisition

           Bug
        17. The `#[inline]` attribute should not be used on trait methods without implementation

           Bug
        18. Unix file permissions should be set with octal values

           Bug
        19. File open options should be consistent

           Bug
        20. Functions expecting raw pointer arguments should be marked as unsafe

           Bug
        21. `env!` should be preferred over `option_env!`

           Bug
        22. `checked_add` and `overflowing_add` should be used to prevent overflows

           Bug
        23. Calls to `std::mem::transmute` should not be evaluated eagerly

           Bug
        24. `unwrap()` should only be used when there is a value to unwrap

           Bug
        25. Lines read from the standard input should be trimmed

           Bug
        26. Formatting trait implementations should not be recursive

           Bug
        27. Comparisons with overlapping ranges that are always false should not be made

           Bug
        28. Incompatible bit masks should not be used in comparisons

           Bug
        29. Variables should be swapped using `std::mem::swap`

           Bug
        30. Redundant comparisons should be removed

           Bug
        31. Raw pointers should not be casted to slices with differently sized elements

           Bug
        32. Reversed ranges and slices should not be empty

           Bug
        33. `size_of::<T>` should not be used to count elements of type `T`

           Bug
        34. `splitn` should not be used with a limit of 0 or 1

           Bug
        35. Null function pointers should not be created through `transmute`

           Bug
        36. Case mismatches in pattern arms of match expressions should be avoided

           Bug
        37. Null pointers should not be transmuted

           Bug
        38. C-like enums should not have unportable variants

           Bug
        39. `MaybeUninit::uninit().assume_init()` should not be used

           Bug
        40. Avoid manual PartialEq implementation with a derived Hash

           Bug
        41. Unit values should not be compared

           Bug
        42. Unit values should not be hashed

           Bug
        43. Closures of `type Fn(...) -> Ord` should not return the unit type

           Bug
        44. Collections should not be transmuted to different types

           Bug
        45. I/O buffers should be processed entirely

           Bug
        46. Lint attributes should not be used on crate imports

           Bug
        47. Manual PartialOrd implementation should be avoided when Ord is derived

           Bug
        48. Immutable variables should not be used in while loop conditions

           Bug
        49. Avoid transmutes that can never be correct

           Bug
        50. Await should be used for awaitable returns in async blocks and functions

           Bug
        51. Pointer arithmetic should not be performed on zero-sized types

           Code Smell
        52. Shared code in all branches should be extracted

           Code Smell
        53. Avoid resizing a vector to zero using `vec.resize(0, value)`

           Bug
        54. Inline vector literals should be preferred to chains of insertions

           Code Smell
        55. Clamping values with `cmp::min` and `cmp::max` should use correct ranges

           Bug
        56. Accessing an array element should not trigger a panic

           Bug
        57. Mathematical constants should not be hardcoded

           Code Smell
        58. Regular expressions should be syntactically valid

           Bug
        59. "std::ptr::null" should be used to denote the null pointer

           Code Smell
        60. Redundant casts should be avoided

           Code Smell
        61. Getters should access the expected fields

           Bug
        62. Null pointers should not be passed to functions expecting non-null arguments

           Bug
        63. Array elements should be separated by commas

           Code Smell
        64. Field init shorthand should be used

           Code Smell
        65. Boolean expressions should not be gratuitous

           Code Smell
        66. Invisible Unicode characters should not be used

           Code Smell
        67. Unnecessary bit operations should not be performed

           Code Smell
        68. Wildcard imports should not be used

           Code Smell
        69. Unnecessary mathematical comparisons should not be made

           Code Smell
        70. "while" loop counters should not have floating type

           Bug
        71. Erasing mathematical operations should not be performed

           Code Smell
        72. Underscores should be used to make large numbers readable

           Code Smell
        73. Related "if/else if" statements should not have the same condition

           Bug
        74. "to_string()" should never be called on a String value

           Code Smell
        75. Identical expressions should not be used on both sides of a binary operator

           Bug
        76. Loops with at most one iteration should be refactored

           Bug
        77. Variables should not be self-assigned

           Bug
        78. Closures should be replaced with function pointers

           Code Smell
        79. Local variables should not be declared and then immediately returned

           Code Smell
        80. "if ... else if" constructs should end with "else" clauses

           Code Smell
        81. Empty statements should be removed

           Code Smell
        82. Functions should not have too many parameters

           Code Smell
        83. Standard outputs should not be used directly to log anything

           Code Smell

        Variables should not be self-assigned

        intentionality - logical
        reliability
        Bug
        • clippy

        Why is this an issue?

        More Info

        There is no reason to re-assign a variable to itself. Either this statement is redundant and should be removed, or the re-assignment is a mistake and some other value or variable was intended for the assignment instead.

        Noncompliant code example

        let mut x = 5;
        x = x; // Self-assignment - does nothing
        

        Compliant solution

        let mut x = 5;
        // Removed the self-assignment
        
          Available In:
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories

        © 2008-2025 SonarSource SA. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use