News Releases

IntelliJ Rust: Updates for the 2020.2 Release

Read on to learn about the latest updates in the IntelliJ Rust plugin:

New macro expansion engine

In the 2020.2 release cycle, IntelliJ Rust has progressed to version 0.3 with the official introduction of the new macro expansion engine. The new engine was previously available as an experimental feature, but it is now enabled by default.

Find out more about the new engine in our detailed blog post. In short, here’s what it brings for your code:

  • Code insight for macro-generated modules and impl blocks.
  • Highlighting of the entire macro call body.
  • Completion inside macro invocations.
  • Navigation through the generated items.
  • Rename refactoring and other editor actions.

Debugging for Rust’s MSVC

In CLion 2020.2, you can now debug projects that were built on Windows using Rust’s MSVC. For this, IntelliJ Rust will employ the LLDB-based debugger bundled in CLion as part of the C/C++ Visual Studio toolchain.

Note that you don’t necessarily need to install Microsoft Visual Studio or any other software in addition to what is required for compilation. For more information on building with MSVC, take a look at the rustup documentation.

Before a debug session, go to Settings / Preferences | Build, Execution, Deployment | Toolchains and create a Visual Studio toolchain. Check that CLion has detected ‘Bundled LLDB’ as the toolchain’s debugger and move this toolchain to the top of the list. Then you’ll be ready to go.

Visual Studio toolchain in CLion

Start debugging, and IntelliJ Rust will check the toolchains and notify you if there is a mismatch:

Toolchain mismatch notification

Note that Rust’s MSVC debugging is still in the early stages of development. If you are interested in tracking its progress, keep an eye on this meta issue.

Initial support for or_patterns

or_patterns is an experimental language feature that allows ‘|’ to be arbitrarily nested within a pattern.

For example, or_patterns make it possible for an expression like Some(Enum::A) | Some(Enum::B) | Some(Enum::C) | Some(Enum::D) to be shortened to Some(Enum::A | Enum::B | Enum::C | Enum::D) and still be valid.

Currently, IntelliJ Rust provides parsing, name resolution, and type inference for code with or_patterns. Code analysis, such as liveness checks, is still a work-in-progress.

Or_patterns feature

To start using this feature, invoke it with the #![feature(or_patterns)] attribute and switch to the nightly toolchain. Otherwise, or_patterns in your code will be annotated as compilation errors.

Tip: if you are switching the compiler to nightly for an open project, make sure to finish by calling Refresh Cargo Project from the Cargo tool window or via Help | Find Action (Ctrl+Shift+A on Linux/Windows, ⇧⌘A on macOS).

New refactorings

Three new refactoring actions have been added to the plugin with the recent releases:

  • Move for module files and top-level items.
  • Introduce Constant.
  • The initial version of Inline for methods.

These refactorings are available via shortcuts, Refactor This (Ctrl+Alt+Shift+T on Linux/Windows, ⌃T on macOS), and from the Refactor section of the main menu.

Move File changes the location of a module file and updates all the related references. To call it, press F6, select Refactor | Move File, or simply drag a file within the Project tree:

Move File

Move also works for top-level items like structs and enums. Press F6 while on the desired element, and you will be asked to select a new location and which items to move:

Move for structs

Introduce Constant (Ctrl+Alt+C on Linux/Windows, ⌥⌘C on macOS) helps you quickly transform an expression into a constant affecting all references:

Introduce Constant

When you need to inline a function body, call Refactor | Inline, or press Ctrl+Alt+N on Linux/Windows or ⌥⌘N on macOS. You can choose to keep the function or remove it after inlining. Currently, only calls without arguments can be processed correctly.

Inline for methods

Other editor enhancements

  • Inlay hints now work for chained method calls:
    Inlay hints for chained methods

    As a quick reminder, you can use the hints to navigate through declarations: hover the mouse over a hint while pressing Ctrl to unfold the type and then choose the element you want to jump to.

    To adjust how the hints are displayed or to turn them on/off, go to Settings / Preferences | Editor | Inlay Hints | Rust, Chain Method Hints.

  • Documentation comments can be viewed fully rendered, just click the gutter icon next to a particular comment:

    Rendered docs

    You can set the rendered view as the default by toggling ‘Render documentation comments’ in Settings / Preferences | Editor | General | Appearance.

  • Also, the plugin now highlights and annotates errors in format strings inside macros like println!:

    Format string error annotation

____

That’s it in terms of the most significant changes we’ve made to IntelliJ Rust for the 2020.2 release. Get CLion 2020.2, update the plugin, and give the new features a try!

DOWNLOAD CLION 2020.2

Please leave your feedback in the comments below or use the plugin’s issue tracker. Thank you!

Your Rust team
JetBrains
The Drive to Develop

image description

Discover more