Rust plugin update: language support improvements, new quick-fixes, improved debugger and more


CLion 2018.2 was released just recently. Along with the release, the Rust plugin has had an update! In this blog post, we’d like to highlight some of the main improvements in the plugin.

However, before we do that, let me briefly remind you about the current state of the Rust plugin:

  • It’s available in all our IntelliJ-based IDEs.
  • It relies on the Cargo build system, and CLion is no exception here!
  • The debugging feature for Rust code is currently only available in CLion.

Here we listed earlier the features in the Rust plugin. What’s new for Rust with the 2018.2 update?

Language support

There is a set of language support improvements. We’ll highlight the most important:

  • Pattern-matching on references got some attention in the language (RFC 2005), and now it is supported properly in the IntelliJ Rust plugin, which means the types are inferred correctly.
  • The expansion of declarative macros guarantees that you can now get better code insight when using macros. For example, the completion works:
    Macro Expansion
    The best use of it is for error handling via error-chain crate based on macros.

    Keep in mind its limitations – if the impl block is generated with the macro on its own, then such completion won’t work as the IDE currently is not aware of its expansion.

New and improved quick-fixes

A whole new set of quick-fixes were implemented to make your Rust code more accurate and save you time while coding. The first group of quick-fixes is related to the type-check errors. For example, when a manual cast is missing in the code (as an implicit cast is not allowed for primitive types) you can generate a proper cast with Alt+Enter: Numeric type cast

As CLion (and the other IntelliJ-based IDEs with the Rust plugin) is aware of the traits available for the type, it can suggest type conversions to fix type checking errors in the code using the proper trait. An example of how this could be used is if a string was used by mistake, but the FromStr trait is present for the type, then a quick-fix invoked with Alt+Enter can generate a proper conversion:
String trait usage

By the way, while we are on the topic of strings, as you know String and &str are not the same in Rust. The main difference is in the object ownership – &str is just a reference to some location in the memory, it doesn’t own it. So what if a &str is passed where the String is needed? There are several options actually, and all of them are available in the quick-fix menu:
String convertion

You can also convert a struct to reference to this struct where needed:
Reference quick-fix

There are even more quick-fixes available for the type checks, thanks to oleg-semenov’s incredible contribution to the IntelliJ Rust plugin!

As for the other code analysis checks, an unresolved reference check with the Auto Import quick-fix can save you time if you have tried to start using something before importing it:
Unresolved reference

Besides, when you implement missing members via a quick-fix, the IntelliJ Rust plugin will correctly substitute a generic type parameter and lifetimes for you! How cool is that?Implement missing members

Quick documentation update

Quick Documentation (Ctrl+Q on Linux/Windows, F1/^J on macOS) shows the documentation for the symbol at the caret. And now it includes the links to for the standard library items:
Quick Documentation

Pretty-printers in debugger

CLion comes with the Rust debugger included. You know that! And now it loads the default Rust pretty-printers for you, so that you now have a nice view of the values of the default types like strings or vectors.

Better project view

The Cargo tool window (View | Toolwindows | Cargo) now shows all the workspace members and targets:
Cargo toolwindow
It simplifies the way to run targets – you can now simply click on them in this tool window. You can also refresh your Cargo project, run clippy or a Cargo command, and attach or detach a Cargo project to the workspace.

There are some important enhancements to the editor’s performance, so that the typing in Rust feels smoother and the editor is more responsive. And there is even more! Check out the collection of recent release notes here.

Wanna give new features a try? Get CLion (or any other IntelliJ-based IDE) with the Rust plugin now!

Download CLion

Your Rust Team

The Drive to Develop

This entry was posted in Announcement and tagged , . Bookmark the permalink.

10 Responses to Rust plugin update: language support improvements, new quick-fixes, improved debugger and more

  1. Rafal says:

    This looks great, please continue for rust support, this will speed up adoption for this great language!

  2. Linker Nick says:

    Thank you, this is awesome!

  3. Denys Vitali says:

    Is a Rust IDE planned for the future?

    JetBrains makes pretty good IDEs, it would be pretty awesome if you guys decided to start an independent IDE like GoLand, but specifically made for Rust (Rustland?)

    Whilst the Rust plugin for IntelliJ / CLion is already pretty good, feature-wise (compared to other plugins for other editors), it is still tremendously slow :(

    • Anastasia Kazakova says:

      No such plans for now. Also, I don’t see how the stand-alone IDE will help with the performance? I would recommend you to report performance issues to the Rust team tracker, so that we take a look and improve.

  4. Just Me says:

    When will it be possible to create Modules in CLion just like in Intellij years? This is the only reason I use intellij when I don’t need a debugger.

  5. Xymist says:

    I’m primarily a Ruby developer, so I use RubyMine rather than CLion; is there a plan/timeline for adding the debugger support to IDEs other than CLion? Otherwise this works very well.

  6. Fabio Rafael da Rosa says:

    Does Clion still enforces the existence of cmake files in Rust projects ?

Leave a Reply

Your email address will not be published. Required fields are marked *