IntelliJ Rust Releases

New in IntelliJ Rust for 2023.1 (Part 2)

In the first part of this “What’s New” series, we only saw the tip of the iceberg – various feature bits that the Rust plugin developers managed to implement during the release cycle.

Now we’re going to show you the rest of the iceberg. Let’s dig in and look at all the new ways the plugin can now analyze Rust code.

Code insight

Improved Self keyword

While being referred to in the impl block, the Self synthetic type supports the missing Create-field quick-fix. When a struct with the Self keyword is initialized, you get a choice of whether to inject the missing field in the struct if the field is absent in the definition.

Analogously, the Convert struct to tuple refactoring provides the ability to convert a struct declared via block with named fields and corresponding types into the struct defined as the tuple, and vice versa. The refactoring now works across all Self usages without exceptions. 

What’s more, the Self type is currently opaque enough for the code insight to suggest the Elide lifetimes quick-fix on self receiver parameters with Self type and declared with the excessive lifetime parameters on them. The fix is suggested when a receiver self has either the type equal to referenced with lifetime Self or referenced with lifetime Self applied as a type parameter to such smart pointers as Box or Rc.

Optimized import action

Unused imports declared only inside functions are now considered potentially removable lines of code. As of now, an additional org.rust.macros.proc experimental feature needs to be enabled in order for the feature to work as intended. But you can rest assured that this will be changed soon!

Method suggestions

The code completion suggestion algorithm now filters out inaccessible methods from the list of offered methods, leaving only valid records. Combined with constantly improving ML completion, the Rust plugin’s autocompletion subsystem focuses on providing you with precise and pertinent completion predictions.

Run / Debug

References and pointers content

Automatic dereferencing of Rust references and pointers is possible when debugging with LLDB. The debugger is currently capable of rendering the contents of &Vec, *const Vec, and *mut Vec while also allowing you to inspect Vec content itself – a new feature in this release, too. It can also disclose multiple references applied one after another in order to reach the content type behind references.

In addition to the above, the Rust plugin correctly shows the contents of raw slice pointers (*const [T], *mut [T]) in the debugger. Looking behind raw slice pointers is now possible either with the LLDB debugger or any other debugger that your system supports.

Skip stepping into stdlib sources

The Rust plugin provides an additional debugging preference, allowing you to skip standard library sources: std, core, and alloc. The dedicated checkbox controls the behaviors under Settings / Preferences | Build, Execution, Deployment | Debugger | Stepping (at the very bottom of the window).

Error detection

This section represents the sparse standard errors that the Rust plugin can detect. The errors themselves are in line with those defined by Rust’s error codes index.

Patterns as arguments

  • E0130: An argument inside a foreign function declared as a pattern is prohibited.
  • E0642: Trait methods cannot take patterns as arguments.

Controls

  • E0571: A break statement with an argument appears outside of a loop construction.
  • Highlight error for an underscore (_) expression appearing on the non-left-hand side of an assignment expression.

Traits

  • E0206: The copy trait implementation was tried on a non-enum or non-struct type.
  • E0224: At least one trait is required for an object type.
  • E0323, E0324, E0325: A trait item implementation was expected, but the associated const / method / associated type doesn’t match the trait declaration.
  • E0785: The impl inheritance block was written on a dyn auto trait.

Foreign / unsafe

  • E0044: Foreign items must not have type or const parameters in their declaration.
  • E0197: Inherent implementations marked as unsafe.

Other

  • E0106: The lifetime Annotation error is shown properly in the function and types signature where it’s required.
  • E0131: The main function defined with generic parameters is not allowed.
  • E0203: Multiple relaxed bounds on a type parameter.
  • E0403: Repeating const generic parameters with duplicate names. By the way, other error messages for already defined names, like the E0428 error code, were updated in order to provide the same error message as the compiler.

Conclusion

That’s all for today! We’ve had fun sharing our most recent updates to the IntelliJ Rust plugin for the release cycle. In case you haven’t seen the first part of this series, check it out. Also, you can ping us on Twitter or file an issue in the plugin’s issue tracker. See you soon in the subsequent releases. Thank you for staying with us!

Your Rust team

JetBrains

The Drive to Develop

image description