News Releases

What’s New in IntelliJ Rust for the 2021.2 Release Cycle

For IntelliJ Rust, this release cycle has been full of significant updates. We have added new functionality to language support, code insight, and run/debug support, along with many fixes and smaller enhancements.

IntelliJ Rust 0.4: new name resolution engine

The major plugin version has been upgraded to 0.4 as a result of the new name resolution engine being enabled by default.

The new engine uses the fixed-point iteration approach and aims to provide better support for complex glob imports (use foo::*), re-exports (use foo as bar), and macro-generated items. It also finds all possible impl blocks for type aliases.

You can find more details about the new engine algorithm and the improvements it brings in these blog posts: Experimental engine for name resolution (2020.3) and Experimental name resolution engine: fixes, features, and optimizations (2021.1).

Enhancements to procedural macro support

We’re continuing to work on procedural macro support, which is still in the early stages of development. You can track the progress in this umbrella issue.

The plugin is now capable of expanding derive procedural macros with custom input inside the #derive attribute.

When expanding such macros, IntelliJ Rust only processes the generated impl blocks. Other items generated by derive procedural macros are not currently taken into account during type inference and name resolution.

Expanding a custom derive procedural macro

IntelliJ Rust can now expand procedural macros on Apple Silicon machines. Make sure to use the aarch64-apple-darwin toolchain.

Note that procedural macro support in the plugin is disabled by default. If you decide to try it out, please be aware of possible unexpected issues. To turn the feature on, call Help | Find Action (Ctrl+Shift+A on Linux/Windows, ⇧⌘A on macOS), search for Experimental Features, and enable org.rust.cargo.evaluate.build.scripts and org.rust.macros.proc:

Experimental features

Cargo configs in conditional compilation

IntelliJ Rust now evaluates cfg conditions in your code according to Cargo configuration files. For example, here is how having a custom target other than the current machine set inside a config affects the processing of conditional blocks:

Handling Cargo config options in cfg blocks

Fetching options from Cargo configs requires the cargo rustc --print cfg command, which is available in Rust starting from version 1.52.0. If you are using an older toolchain, the plugin will not take the config options into account.

Code insight updates

  • Unreachable code detection

    The plugin’s set of inspections now includes Unreachable code. It finds code fragments that are never going to be executed and provides a quick-fix to remove them quickly and safely:

    Unreachable code detection

  • Refactoring suggestions in Change Signature

    Recently we introduced the Change Signature refactoring for Rust code. Using this refactoring has become even easier, as it now tracks the signature modifications as you type and suggests making changes right away:

    Change Signature suggestions

  • Custom postfix completion templates

    Postfix completion can save you a lot of time by minimizing the number of backward caret jumps. Postfix templates for Rust have been available in the plugin for a while, but now you can also create your own templates to cover all the required cases.

    Creating a custom postfix completion template

  • More code insight for Cargo.toml

    There is a new intention action that expands dependency specifications in Cargo.toml, either inline or into a separate table below the current one.

    Extracting a dependency specification

    We’ve also added the Unresolved reference inspection for Cargo.toml files. It highlights unresolved references in TOML string literals and provides a quick-fix to create a new file for the corresponding unresolved path. At the moment, the inspection works for local dependencies, build scripts, workspace paths, and Cargo features.

    Detecting an unresolved reference in Cargo.toml

    The local crates index, which the plugin uses when performing dependency completion and inspections in Cargo.toml, is now updated with every change to the Cargo registry index on disk (see the tracking issue). This enhances the quality of completion for crates and versions, and adds two useful inspections: Crate not found and New crate version available. This is an experimental feature which can be enabled via org.rust.crates.local.index in the Experimental features dialog.

    New version available for a crate

Initial WSL support

In this release cycle, IntelliJ Rust introduced the initial implementation of WSL support. To enable it, tick the org.rust.wsl flag in the Experimental features dialog. After that, you will be able to select a WSL toolchain in Settings | Languages & Frameworks | Rust (or in the New Project wizard):

Selecting a WSL toolchain

If for some reason your WSL toolchain location has not been detected, you can set the path manually using the \\wsl$ prefix.

Note that debugging on WSL works in CLion only. See this ticket for the status summary.

Launching with root privileges

Now you can run and debug Rust applications with root privileges. The option is called Run with root privileges on macOS / Linux and Run with Administrator privileges on Windows:

Option to run with root privileges

Currently, the feature doesn’t work for the cargo test command. Also, if you have previously disabled the Build tool window via the org.rust.cargo.build.window option, make sure to turn it back on to use this feature.

Improvements in LLDB renderers

Quick reminder: you can debug your Rust code in CLion and in IntelliJ IDEA Ultimate, GoLand, and PyCharm Pro with the Native Debugging Support plugin. See the Debug section in our documentation.

We are continuing to enrich the plugin’s MSVC LLDB support. If you are interested in tracking the progress of it, keep an eye on this parent ticket. One of the recently added features is the proper rendering of &str string slices:

LLDB renderers for &str

The plugin is now capable of rendering the OsStr, CString, CStr, PathBuf, and Path standard types.

LLDB renderers for more standart types

Security checking for Cargo projects

IntelliJ Rust now checks the sources of Cargo projects when you open them for the first time. If the source is unknown, the IDE shows a warning and prompts you to choose whether or not it’s safe to open the project and perform the tasks that may cause security problems (take a look at the “Malicious” Example Crate):

  • Running any external Rust tool, such as cargo, rustc, rustfmt, which may be overridden to execute arbitrary code.
  • Running build scripts and procedural macros, which can contain arbitrary code.

Trust a Cargo project dialog

To learn more about the project security policy in JetBrains IDEs, check out the IntelliJ IDEA documentation.

___________

We would like to thank the external contributors who have helped us in this release cycle:

Those are the most notable changes we’ve made to IntelliJ Rust for the 2021.2 release cycle. Please share your feedback with us, and don’t hesitate to report any issues in the plugin’s tracker. We also encourage you to take a look at the IntelliJ Rust documentation. Thank you!

Your Rust team
JetBrains
The Drive to Develop

image description