Start FreeLog in
SonarQube Cloud | Advanced setup | Languages | Rust

Rust

On this page

Prerequisites

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.
  • Clippy (cargo clippy): A Rust linter to catch common mistakes and improve your code. Install it using rustup component add clippy.

Running the analysis

You can analyze Rust projects using the SonarScanner CLI. Make sure it is available on the machine running the analysis. 

Clippy integration

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.

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.

Executing the Clippy analysis

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.enable 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.

Importing external Clippy reports

You can import Clippy issues from external JSON reports using the sonar.rust.clippy.reportPaths property. This property accepts a comma-separated list of file paths to your Clippy JSON reports.

You can generate Clippy JSON reports with the command cargo clippy --message-format=json.

Code coverage

See the Test coverage parameters page for information on importing coverage reports for Rust.

Language-specific properties

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

Troubleshooting

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.


Was this page helpful?

© 2008-2025 SonarSource SA. All rights reserved. SONAR, SONARSOURCE, SONARQUBE, and CLEAN AS YOU CODE are trademarks of SonarSource SA.

Creative Commons License