News Releases

IntelliJ Rust: Updates for 2020.3

In the previous blog post on IntelliJ Rust, we described the plugin’s major update of the 2020.3 release cycle – more support and a new UI for Cargo features. In brief, you can now toggle workspace features right in the Cargo.toml file, and code insight across the whole of your project will be adjusted accordingly.

Toggling Cargo features

Now let’s take a look at the improvements that have been made to this functionality already, along with other updates the plugin has received over the last few months:

More code insight for Cargo features

IntelliJ Rust now gives completion suggestions and provides navigation across features in Cargo.toml. You can also jump to a feature declaration from a cfg or cfg_attr attribute in your Rust code:

Completion and navigation for Cargo features

Rustfmt as default formatter

If you would prefer Rustfmt to be the default formatter for your code, tick the Use rustfmt instead of built-in formatter checkbox in Settings / Preferences | Languages & Frameworks | Rust | Rustfmt.

Rustfmt settings

Currently, this option doesn’t apply when reformatting a selection. If you select a region and call Reformat Code (Ctrl+Alt+L on Linux/Windows, ⌥⌘L on macOS), the IDE’s formatter will be used instead.

Improvements in refactorings

  • The Move (F6) refactoring now supports re-exports when moving a file:

    Move refactoring for a file

    If you select a piece of code in the editor and then call Move, the refactoring will take your selection into account when suggesting the items to be moved.

    Related impl-s are now moved together with the items, and the items with related impl– s are grouped together for easier navigation in the refactoring dialog:

    Move refactoring for items

    You can now use Move to place a file into another crate or even move multiple files and directories.

    Also, Move is now capable of detecting visibility conflicts (and making a moved item public if required), as well as other compilation errors which may occur during a move, like E0116: An inherent implementation was defined for a type outside the current crate or E0117: Only traits defined in the current crate can be implemented for arbitrary types.

  • Aside from Move, we also added a new Inline (Ctrl+Alt+N on Linux/Windows, ⌥⌘N on macOS) refactoring for local variables:

    Inline for local variables

New experimental engine for name resolution

We’ve started to redesign a part of the name resolve engine. The newer version of the algorithm (aka name resolution 2.0) is in the experimental state. If you are ready to give it a try, enable the Use experimental name resolution engine checkbox in Settings / Preferences | Languages & Frameworks | Rust:

Option to turn on the new name resolve engine

Our new algorithm uses the fixed-point iteration approach and aims to provide better support for complex glob imports (use foo::*) and re-exports (use foo as bar). It will also allow the plugin to properly expand the upcoming macros 2.0.

At the same time, the new algorithm addresses some of the existing macro-related issues. For example, it improves resolve for the code where a macro expands into another macro’s definition. It also fixes the problem with macro expansion inside an included file.

The following code fragment gives an example of how the new engine handles complex resolve:

macro_rules! bar {
    () => {
        macro_rules! foo {
            ($i:ident) => {
                fn $i() {}
            };
        }
    }
}
bar!();  // expands to foo macro definition
foo!(qwe);
fn main() {
    qwe(); // qwe will get resolved with the new engine
}

Note that the new algorithm works for top-level items only, so local variables and type inference functionality won’t be affected.

If you are interested in the implementation details of the new algorithm, you can find a longer explanation in this ticket.

This feature is in its early stages of development, so we encourage you to try it out and let us know if you have any issues. Please use the plugin’s issue tracker: just select a problematic piece of code and call Help | Create New Issue.

Cargo-generate project templates

The plugin’s wizard for creating new projects has been enhanced with two more templates, WebAssembly Lib and Procedural Macro, and the option to add other Git repositories as templates to be used with cargo-generate.

Using a custom cargo-generate template

If you don’t have cargo-generate installed, you will be able to do that from the New Project dialog.

WASM projects support

Are you working with Rust and WebAssembly together? We recently started working on WASM support, and here are the features that are already available:

  • The WebAssembly Lib template helps you quickly create new projects based on wasm-pack-template.
  • The new wasm-pack configuration lets you run wasm-pack commands without leaving the IDE.

    When you create a project using the WebAssembly Lib template, the plugin adds a Build configuration of this type automatically:

    Creating a WASM project

    You can use a wasm-pack configuration in the same way as any other IDE configuration, including by calling it from Help | Run Anything (press Ctrl twice).

  • The Go to generated declaration gutter marker lets you navigate from the #[wasm_bindgen] attribute to the corresponding TypeScript code:

    Go to declaration for wasm_bindgen

If you are interested in tracking the progress of WASM support, please follow this issue. Also, please let us know if there are any other IDE features for Rust and WebAssembly that you would like the plugin to have.

Other news

Other notable updates include completion for rustc and clippy lint attributes, and new intentions for creating a function/method from an unresolved call and for importing a qualified path.

Also, debugging for your Rust code in IntelliJ IDEA Ultimate is now available on Windows with LLDB under the MSVC toolchain. Just a quick reminder: you need the Native Debugging Support plugin for this (the IDE will prompt you to install it). There are some limitations for Rust support in MSVC LLDB though, see this issue for details.


We would like to take this opportunity to thank the external contributors who have helped us in this release cycle. Many features and fixes wouldn’t have made it to the plugin without your efforts! Our thanks go to:

Alexey Gerasimov

Mikhail Grachev

Jakub Beránek

Ondřej Lukeš

Ridan Vandenbergh

Silence Tai

Tamir Duberstein

Toshiaki Kameyama

Thank you for reading and stay tuned!

DOWNLOAD CLION 2020.3

Your Rust team
JetBrains
The Drive to Develop

image description

Discover more