#6992 Provide initial experimental support for custom deriveprocedural macros. Now the plugin can expand such procedural macro calls and take into account expanded
implitemsin type inference and name resolution (other types of items are ignored for now).
Note, it’s only an initial implementation,so it may work in an unexpected way in some cases. The feature is disabled by default for now. To turn it on, youshould enable
Use experimental name resolution engineoption in
Preferences Languages & Frameworks Rustsettings and enable
org.rust.macros.procexperimental features.Don’t forget to reload a project structure after enabling the corresponding features via
Refresh Cargo Projectsaction on Cargo tool window. See tracking issue formore details and the current status of procedural macros support
#7093 Now the plugin takes Cargo config into account during evaluation of
cfgconditions.Note, it works since Rust 1.52.0 (currently in beta)
Introduce new intention actions:
Enable/Disable feature stateto toggles feature state from a
cfgattribute (by @Kobzol)
By the way, we have a blog post about cargo features support
Share in Playgroundto share a selected Rust code on Rust Playground
Previously, this feature was only available as
Rust Share in Playgroundaction in
Toolsand context menus
Expand dependency specificationfor
Create structto create a struct from an unresolved struct literal (by @Kobzol)
Use destructuring declarationintention action replaces usages of destructured variable (by @Kobzol)
#6986 Allow specifying the function return type in
Create functionintention action if the inferred return typeis unknown (by @Kobzol)
Improve code folding:
#7111 Support folding for multiline
whereclauses (by @Stzx)
#7112 Enable folding for series of use items by default (by @Stzx)
You can disable it via
Settings Editor General Code Foldingsettings
Method bodiesoption of
Settings Editor General Code Folding - Generalsettingsto fold function/method bodies by default (by @Stzx)
Improve experimental crate-local index:
Cargo.tomlinspection that checks crate dependency version requirements that do not match any knowncrate version (by @Kobzol)
#6599 Use semantic versioning to improve version sorting in dependency completion
#7004 Don’t perform code completion and run inspections if the index is not ready
Note, the corresponding feature is disabled by default for now. To use it, enable
#7142 Drop support of
org.rust.cargo.evaluate.build.scriptsinstead if you need to evaluate
Name resolution fixes:
#7119 Correctly resolve qualified attributeprocedural macro paths (like
#7132 Resolve field shorthandto a local variable in the case of unresolved struct literal
Improvements of new name resolution engine:
#7089 Correctly resolve macros with absolute paths (like
#7057 Exclude some cfg-disabled items from completion
Change Signaturerefactoring (
Refactor Change Signatureor Ctrl+F6) fixes:
#7081 Fix some false positives in name conflict detection (by @Kobzol)
#7080 Do not needlessly import default type arguments (by @Kobzol)
#7076 Correctly place function visibility after attributes (by @Kobzol)
#7108 Insert correct
useitem by auto-import feature in the case of arenamedCargo package
#7101 Fix false positive in
Needless lifetimesinspection when the lifetime is used in
whereclause (by @Kobzol)
#5491 Add line break after opening brace in struct blocks by built-in formatter (by @Kobzol)
#7131 Fix false-positive proofreading warnings for sentences written in several sequential Rust comments.Note, you can enable/disable proofreading in Rust files in
Preferences Editor Proofreading Grammarsettings
#7121 Reload project model automatically when workspace-root
Cargo.tomlfile is changed (and saved).Previously it was work only for package
#7079 Fix proc macro expansion if proc macro crate is added as separate cargo project in
Show the result of macro expansionintention lower in the intention list
#6013 Don’t run some inspections on Rust files outside a valid Cargo project to avoid expected false positive errors
#7070 Don’t show errors related to Rust edition if we don’t known the edition (by @Stzx)
Can't find process startererror when running DTraceprofiler with CLion 2021.1
#6201 Avoid Cargo project duplication in the project model. This fixes some issues related to such duplications
#7114 Don’t show “Tip of the Day” at startup in internal IDEs (for the plugin developers)
#7094 Enable Gradle Build Cache for local builds(see #7094 for more details)
2021edition variant in the plugin and adjust the corresponding code
Full set of changes can be found hereNews
Like C/C++ and other native languages, Rust includes support for conditional compilation. The most common way to instruct the compiler whether to include or ignore a piece of code in compilation is to add a
cfg attribute with the required condition. For example, you can use this mechanism to check the target architecture and switch code blocks at compile-time depending on the operating system.
IntelliJ Rust detects conditionally disabled blocks in your project and excludes them from the codebase. This means that name resolution and analysis ignore those pieces, so you won’t get errors and warnings inside them, and no items from that code will appear elsewhere in auto-completion. Also, the plugin grays the disabled blocks out in the editor.
This level of
cfg support has been available in the plugin for a long while, but something was missing. Conditional options can include Cargo features. Previously, IntelliJ Rust supported only the features declared in the project’s dependencies, but now your workspace features are supported too.
We’ve implemented a smart UI to make your work with features more transparent: you can enable or disable any specific feature of your workspace right inside a Cargo.toml file. Name resolution and code insight will take that into account.
Let’s examine in detail how IntelliJ Rust handles Cargo features when they are used across various levels of dependency.
The simplest case is when you need to exclude features from a library, or include only some of them in your build.
To start, let’s add the
tokio crate and enable all of its features using the
If we open
tokio’s Cargo.toml and navigate to the
[features] section, we’ll see the selected checkboxes next to all the features listed in
Now we can specify a particular feature instead of
full, for example,
tokio’s Cargo.toml, the checkboxes’ state will change accordingly. Only
signaland the features it depends on are enabled now:
Please note that in the case of external dependencies, this UI is intended to help you grasp the state of features but not to control it, so the checkboxes here in the library’s Cargo.toml are not clickable. If you need to change the list of features, keep using your project’s .toml config.
Independent package features
Another case is when you create your own features inside a package and use them in
cfg blocks. Unlike with external libraries, here you can control the list of features by clearing and selecting the corresponding checkboxes.
Usually, Cargo features are additive and don’t conflict when enabled all together, which is the reason why IntelliJ Rust enablesworkspace features by default. However, you may want to toggle them on and off, and the plugin’s UI will help you do that!
The ability to toggle workspace features is especially handy when you use them as switchers instead of additive instances (for example, the Amethyst library has features controlling which of the available rendering engines is invoked at the moment). Previously, you would have had to manually remove the unneeded features from your Cargo.toml in order to turn them off.
As the UI now allows you to easily switch between features, be careful not to enable any mutually exclusive ones simultaneously. The plugin will not prevent you from doing so and will not show a warning, because at the .toml file level there’s not enough information for the plugin to detect potential problems in the sources.
Below you can see a multiple resolve situation reported in the sources when non-additive features are enabled at the same time:
Package features that depend on each other
A slightly trickier case is when your features depend on each other:
If you toggle one of them on or off, IntelliJ Rust will recognize the dependencies and toggle the related features accordingly.
Features with cross-crate dependencies
Your package features can also depend on features from another crate. Let’s make
core from the previous example dependent on the
macros feature from
tokio’s Cargo.toml, we’ll notice how
macros, which is disabled by default, gets enabled when we toggle
core on and gets disabled again when we turn
Features in a workspace
A more complicated scenario is when features are used in a workspace consisting of several packages.
As a simple example, let’s create a workspace with two packages –
foo’s Cargo.toml, we can declare a dependency on
bar and specify that it uses a feature from
When using a workspace, you may want to develop a single crate inside it like an independent instance. In this case, you’ll need control over the crate’s features, with the ability to disable those you don’t need at a certain point.
So what happens if you focus on barand intentionally disable
bar_feature? As a result, all the code in
foothat uses itwill not be resolved, and it might be tricky to find the reason for the errors you’ll get in
To help you avoid these problems, IntelliJ Rust checks the required features in your workspace dependencies and suggests quick-fixes for them:
Finally, your workspace crates can have features that depend on each other. For example,
foo depending on
Here when we disable
bar_feature, the plugin disables
foo_feature automatically. However, when we turn
bar_feature back on,
foo_feature will not get enabled, so you need to roll back the dependent features manually.
In the future we plan to add navigation and completion for features from both .toml and source files, and start supporting
cfg_attr. In the meanwhile, we hope you find these new capabilities helpful, and we really want to hear your feedback! Please share your experience of the new UI and let us know how you would like support for Cargo features in IntelliJ Rustto improve.
Clion Intellij Free
Clion Vs Intellij Rust
Your Rust team
The Drive to Develop