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
 
Tags
    Impact
      Clean code attribute
        1. Non-empty statements should change control flow or have at least one side-effect

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

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

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

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

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

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

           Bug
        8. Inherent shadowing definitions of to_string should be avoided

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

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

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

           Bug
        12. Numeric literal suffixes should not be mistyped

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

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

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

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

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

           Bug
        18. File open options should be consistent

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

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

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

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

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

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

           Bug
        25. Formatting trait implementations should not be recursive

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

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

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

           Bug
        29. Redundant comparisons should be removed

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

           Bug
        31. Reversed ranges and slices should not be empty

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

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

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

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

           Bug
        36. Null pointers should not be transmuted

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

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

           Bug
        39. Avoid manual PartialEq implementation with a derived Hash

           Bug
        40. Unit values should not be compared

           Bug
        41. Unit values should not be hashed

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

           Bug
        43. Collections should not be transmuted to different types

           Bug
        44. I/O buffers should be processed entirely

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

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

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

           Bug
        48. Avoid transmutes that can never be correct

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

           Bug
        50. Avoid resizing a vector to zero using `vec.resize(0, value)`

           Bug
        51. Clamping values with `cmp::min` and `cmp::max` should use correct ranges

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

           Bug
        53. Regular expressions should be syntactically valid

           Bug
        54. Getters should access the expected fields

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

           Bug
        56. "while" loop counters should not have floating type

           Bug
        57. Related "if/else if" statements should not have the same condition

           Bug
        58. Identical expressions should not be used on both sides of a binary operator

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

           Bug
        60. Variables should not be self-assigned

           Bug

        Infinite iterators should be finished off with a terminating operation

        intentionality - logical
        reliability
        Bug
        • clippy

        Why is this an issue?

        More Info

        Infinite iteration is usually an error in most cases, leading to programs that never terminate. While there are some acceptable use cases such as event streams, developers often unintentionally create infinite loops, causing resource exhaustion or unresponsive behavior.

        Code examples

        Noncompliant code example

        use std::iter;
        
        iter::repeat(1_u8).collect::<Vec<_>>(); // Noncompliant: This creates an infinite iterator.
        

        Compliant solution

        use std::iter;
        
        iter::repeat(1_u8).take(5).collect::<Vec<_>>(); // Compliant: This creates a finite iterator by taking only the first 5 items.
        
          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