Rust is supported in CLion via the IntelliJ Rust plugin, compatible with all IntelliJ-based IDEs. The plugin provides Rust language engine with a set of code insight features, Cargo support, and debugger functionality (in CLion and IntelliJ IDEA Ultimate).
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.) and choose
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):
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
In the Rust dialog, adjust the general project settings.
Use the Expand declarative macros switcher if you want to disable the default new macro expansion engine (in case it fails for your code at some point). You can switch to the old engine or turn macro expansion off completely.
You can enable the external linter to work on the fly, but this might affect performance especially on big projects. To run the linter on demand, use the Run External Linter action.
Code insight features
IntelliJ Rust is being actively developed, and new features come with every version. In addition to the general code insight features like syntax highlighting, code formatting, navigation, and refactorings, the plugin's language support also includes:
Macro expansion engine for declarative macros.
The default engine provides code insight for generated items such as structs, enums, functions, and traits. On top of that, it 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.
You can explore the inspections and edit their severities and scopes in:
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 Rust-specific code generation options and intention actions, for example:
Full list of intentions is available in.
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 Ctrl twice to invoke the Run Anything popup:
When you run a Cargo command, CLion creates a temporary run/debug configuration of the Cargo command type:
You can edit, save, or remove configurations in.
Create a Cargo Command configuration
Go to Cargo Command., click , and select
Specify the settings for your Cargo Command configuration:
Use the following pattern for the Command field:
[build options] [--] [program arguments].
--prefix followed by an extra space. It separates the input arguments from the build options that will be passed to Cargo. For example, when you debug this configuration, the plugin will start by calling
cargo build [build options]and then it will launch the binary under the debugger with
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.
Backtrace lets you set the
RUST_BACKTRACEenvironment variable, which prints the unwound stack trace into error messages and controls its length. For more information, see Debugging Rust code in CLion: More debug features.
When you run the
cargo test command or use a gutter icon to run tests, 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 :
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.
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:
Remote debug with GDB/gdbserver
You can debug a Rust program running remotely from CLion on your local machine with the help of the build system-independent GDB Remote debug configuration.
Prepare a debug binary (take a look at these instructions on cross-compilation).
Create a GDB Remote debug configuration and fill in the settings:
As a symbol file, try using the binary itself. By default, it is placed into the ~/target/debug/ folder.
Launch your program remotely under gdbserver, place breakpoints in the code, and start a debug session. You will be able to use all the CLion debug features as if the program was running locally: