# Rust

The Rust analyzer supports:

* Code Coverage import (LCOV and Cobertura formats)
* Cognitive Complexity metric
* Cyclomatic Complexity metric
* Import of Clippy output as external rules (JSON format)

## Supported versions <a href="#supported-versions" id="supported-versions"></a>

The level of support for a language is defined as follows:

* Fully supported: Analysis will complete. All the language features are understood and examined.
* Supported: Most language features are understood and examined but the version includes unsupported features. Analysis might break or provide incomplete results.

All Rust versions are fully supported (through Clippy linter).

## Prerequisites <a href="#prerequisites" id="prerequisites"></a>

Before using the Sonar Rust analyzer, ensure the following tools are installed and available in your system’s PATH:

* **Cargo**: The Rust package manager. You can install it from [rustup.rs](https://rustup.rs/).
* **Clippy (cargo clippy)**: A Rust linter to catch common mistakes and improve your code. Install it using `rustup component add clippy`.

## Running the analysis <a href="#running-the-analysis" id="running-the-analysis"></a>

You can analyze Rust projects using the [sonarscanner](https://docs.sonarsource.com/sonarqube-server/analyzing-source-code/scanners/sonarscanner "mention"). Make sure it is available on the machine running the analysis.

## Clippy integration <a href="#clippy-integration" id="clippy-integration"></a>

The Sonar Rust analyzer integrates with Clippy to provide code analysis. You can configure the Clippy integration in two ways:

* Execute Clippy Analysis: The analyzer runs Clippy automatically (default).
* Import External Reports: Load pre-generated Clippy JSON reports. See [external-analyzer-reports](https://docs.sonarsource.com/sonarqube-server/analyzing-source-code/importing-external-issues/external-analyzer-reports "mention") for setup instructions.

These two methods are not mutually exclusive and can be used simultaneously. However, be aware that using both methods might lead to undesirable effects, such as duplicated Clippy issues.

By default, the Sonar Rust analyzer automatically triggers a Clippy analysis. The analyzer will look for a *Cargo.toml* manifest in the project’s root directory and run Clippy.

* You can specify custom paths to `Cargo.toml` manifest files using `sonar.rust.cargo.manifestPaths`, which accepts a comma-separated list of file paths.
* You can disable the automatic Clippy analysis by setting the `sonar.rust.clippy.enabled` property to `false`.

Even when Clippy analysis is disabled, all other Sonar Rust analysis features, such as code metrics calculation, code complexity, and code duplication, will remain active.

## Code coverage <a href="#code-coverage" id="code-coverage"></a>

See the [test-coverage-parameters](https://docs.sonarsource.com/sonarqube-server/analyzing-source-code/test-coverage/test-coverage-parameters "mention") page for information on importing coverage reports for Rust.

## Language-specific properties <a href="#language-specific-properties" id="language-specific-properties"></a>

For a complete list of available properties and their descriptions, please refer to the Rust-specific properties by going to **Administration > Configuration > General Settings > Languages > Rust**.

## Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

If the automatically triggered analysis fails, a warning will be displayed in the logs and on the SonarQube project page. To troubleshoot the issue, try manually executing `cargo clippy` in the project directory to examine the error details.
