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?
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:
The best use of it is for error handling via error-chain crate based on macros.
Keep in mind its limitations – if the
implblock 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:
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:
By the way, while we are on the topic of strings, as you know
&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:
You can also convert a struct to reference to this struct where needed:
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:
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?
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 https://doc.rust-lang.org/std/ for the standard library items:
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:
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!
Your Rust Team
The Drive to Develop
Subscribe to Blog updates
Thanks, we've got you!
CLion Nova: A New Update With Various Bug Fixes
CLion Nova, a free preview of CLion with the ReSharper C++/Rider C++ language engine, was announced recently. We’re excited to see how well you liked the first build! There are about 3,700 users right now and the overall feedback is mostly positive, especially that which is related to performance an…
CLion 2023.3 Goes Beta
The Beta version of CLion Classic 2023.3 is now available with key improvements and changes that are expected in the upcoming release. Download build 233.11799.37 from our website, via the Toolbox App, or as a snap package for Ubuntu. If you are using CLion Nova, note that we do not plan to release…
CLion Nova Explodes onto the C and C++ Development Scene
TL;DR Today, we’re announcing a free early preview of CLion, which uses the ReSharper C++/Rider C++ language engine instead of the CLion "legacy" engine. The Preview build is available via our dedicated Toolbox App feed. At some point in 2024, depending on the results of the feedback coll…
CLion 2023.3 EAP6: Support for Intel Syntax in Assembly Views
Grab the fresh CLion 2023.3 EAP5 build (233.11555.2) from our website, via the Toolbox App, or as a snap package if you are using Ubuntu, or update via a patch if you’re using the previous EAP build. DOWNLOAD CLION EAP Intel syntax in the Assembly view Previously, CLion 2023.3 EAP added an Assembly…