Releases

What’s New in IntelliJ Rust for 2022.1

In this release cycle, we’ve improved our language support, code insight, run/debug support, and tool integrations, and added many enhancements and fixes. 

Language Support

Single-step macro expansion 

We’ve significantly improved how macro expansion works.

Previously the macro expansion process was implemented in multiple steps – up to 64. The indexing would start after every step. This approach was not ideal. First, the macro expansion was slower than it could be because the cache memory would be cleared out at the end of indexing. And second, multiple steps caused a blinking UI.

We decided to redesign macro expansion in IntelliJ Rust some time ago, but this required some major architectural changes. First of all, we had to update the name resolution engine.

The work on updating the name resolution engine started at the end of 2020. We’ve been introducing the new engine gradually. For some time it worked alongside the old one, because in some cases the old engine worked better.

Now we’re happy to say the name resolution engine 2.0 is mature enough. We’ve been able to redesign the macro expansion engine, collapsing the expansion process into a single step. This has fixed the blinking during the expansion process and significantly sped up the macro expansion itself.

The plugin still has a limit of 64 steps, so macros that require more steps will not be expanded fully. We’ll keep working to improve the macro expansion process.

Name resolution improvements

Our new name resolution engine, which is enabled by default, now resolves macros 2.0 declared inside function bodies.

We also have a couple of improvements for macros in documentation tests:

  • Name resolution for macros 2.0 in doctests has been fixed.
  • The plugin now properly expands and resolves attribute procedural macros in doctests.

Thanks to improved name resolution, the plugin is able to provide better completion, quick documentation, and other code insight features.

You can find more information about the new name resolution engine in these blog posts:

Support for inline_const, inline_const_pat and ~const

IntelliJ Rust now properly parses the inline_const and inline_const_pat syntax that allows you to use inline constant expressions. The features are annotated as experimental, meaning you can’t use them with the stable toolchain.

The tilde const (~const) syntax is now supported, too.

Code insight

The Extract trait refactoring

With this new refactoring, you can quickly extract members of impl blocks into a trait and undo the changes with a single keystroke.

To refactor your code, place the caret on an item and go to Refactor | Refactor this | Extract trait. Or right-click on an item and go to Refactor | Extrait trait. The Refactor this menu is also available via the shortcut ⌃T (Ctrl+Alt+Shift+T).

The same refactoring will help you to create new traits out of existing ones.

Improved ML completion

We’ve updated the machine learning completion model to improve sorting of completion suggestions. The updated model:

  • prefers expressions of type which match the expected type.
  • differentiates between inherent, trait and blanket implementations.
  • recognises async, const and unsafe contexts.  

Remember, the data for ML completion is gathered anonymously during the IDE’s Early Access Program and your source code is never collected – only information about your interactions with the code completion UI.

You can learn which elements were reordered by the ML algorithm (note the green upward and red downward arrows). For this, tick the Mark position changes in the completion popup checkbox in Settings / Preferences | Editor | General | Code Completion. In this section you can also disable ML completion, if you prefer not to use it.

The Unnecessarily qualified path inspection

The plugin now has an Unnecessarily qualified path inspection that corresponds to the unused_qualifications lint. The new inspection detects unnecessarily qualified names, so if an item from another module has been brought into scope, you don’t have to qualify it again.

If you hover over the grayed-out item, you will get a popup window with a quick-fix to Remove unnecessary path prefix.

Run/Debug

Run targets

We’ve added initial support for Run targets. With this feature, you can build and run your code in an environment your app is intended for – in Docker containers, in WSL, or on remote machines via SSH.

To add a new target, click Run | Manage targets. Alternatively, click Add configuration or Edit configurations if you already have some, and then click Manage targets. You can also select the target from the dropdown menu.

The Run targets feature is available in CLion, IntelliJ IDEA Ultimate, and GoLand for now. Note that remote debugging using Run targets is currently unavailable. Plus, there are some other limitations. Please see the corresponding ticket for more details.

File links for dbg! macro output in the terminal

If you use dbg! macros for debugging, you can now jump from the terminal to the lines with dbg! usages in your Rust files.

Completion for private items in the debugger

Private items are now suggested when you type code in the debugger’s Evaluate expression bar or add a new watch. Previously, private items were filtered out. But since the debugger has access to them, private items should also be suggested in autocompletion. Hopefully, this will improve the debugging workflow.

Profiler in WSL 2

In the last release cycle, we enabled WSL 2 support by default. Now we’ve added support for the profiler on WSL toolchains.

When working with WSL, make sure to set the WSL toolchain location in Settings / Preferences | Languages & Frameworks | Rust.

You can learn more about setting up the profiler in WSL 2 on this page. The profiler is available only in CLion.

Valgrind memcheck in WSL

You can now use Valgrind memcheck on Windows via WSL. Like the profiler, Valgrind works in CLion only.

Tools integration

Custom parameters for rustfmt

You can now use rustfmt from a non-default toolchain and configure additional arguments and environment variables. For this, go to Settings / Preferences | Languages & Frameworks | Rust | Rustfmt.

External linter widget

IntelliJ Rust now has a widget for external linters. You can see it in the status bar on the right. The widget informs you about a linter being turned on or off. You will also receive a warning when a linter affects the performance of the IDE. Click on the widget to see the settings for external linters.

___

As usual, a big thank you goes to the external contributors who have helped us in this release cycle:

That’s it for the most recent updates in the IntelliJ Rust plugin. Tell us what you think about our new features! Write a comment here, ping us on Twitter, or file an issue in the plugin’s issue tracker. Thank you!

Your Rust team

JetBrains

The Drive to Develop

image description