Rust is supported in CLion via the IntelliJ Rust plugin, compatible with all IntelliJ-based IDEs. In addition to the language engine and Cargo support, the CLion's implementation of the plugin also provides the debugger for your Rust applications.
Prepare the environment
Open a Rust project
Note that only the Cargo-based Rust projects are supported.
Go to Cargo.toml.and select the project root directory containing
Check the Cargo tool window ( ) to make sure the project was imported successfully.
Create a new Rust project
Start a new project (Rust as your project type. In the New Project dialog, provide the paths to the toolchain and the standard library (which you can download via rustup right from the wizard):) and choose
Click Create, and CLion will generate a new project with the following structure:
Configure the project settings
Go to Rust node of the settings tree:and navigate to the
Code insight features
IntelliJ Rust plugin is being actively developed, and new features come with every version. In addition to the general code insights like syntax highlighting, code formatting, navigation, and refactorings, the plugin's language support includes:
Macro expansion engine for declarative macros. Currently, there are two macro expansion engines: default and experimental. To switch between them, use the Expand declarative macros option in .
Both of the engines provide code insight features for generated top-level items such as structs, enums, functions, and traits. On top of that, the experimental engine performs highlighting, name resolution, and completion for generated modules and methods from
implblocks, and enables navigation in macro calls.
On-the-fly code analysis with a list of Rust-specific inspections. To view or edit the inspections, go to :
For most of the inspections, quick-fixes are available via Alt+Enter. For example, you can implement missing members via a quick-fix, and the plugin will correctly substitute a generic type parameter and lifetimes:
Various code generation options, for example:
Also, the plugin provides a set of live templates for Rust. You can customize the built-in templates and create your own in .
Quick Documentation popup Ctrl+Q, including documentation for library functions:
The Cargo tool window ( ) shows all workspace members and targets. From this tool window, you can quickly run a target by clicking on it, refresh your project , reformat it with rustfmt, and run the external linter configured in .
To run a Cargo command, click or press Double Ctrl to invoke the Run Anything popup:
When you run a Cargo command, CLion creates a temporary run/debug configuration of the Cargo command type: Go to the dialog to edit, save, or remove configurations.
If required, you can configure the debugger data views in:
To start a debug session, select an existing Cargo command configuration, or create a new one.
Create a run/debug configuration
In the Cargo Command.dialog, press and choose
Specify the settings for your Cargo Command configuration:
The Emulate terminal in output console option can be useful for crates like color-backtrace, which behave differently when a process is run under TTY (see the feature description). This option is not available on Windows.
After the configuration is set up, you can Debug it with all the CLion debug features (breakpoints, variable monitor, stepping, and others) available for your Rust application:
When you run the
cargo test command, the plugin employs CLion's built-in test runner to help you explore the results.
The test runner window shows a progress bar for the running tests and groups all tests into a tree view according to their status and duration. From this window, you can rerun the tests or toggle automatic rerun on changes in your code, sort the tests alphabetically or by duration , and open previous results :