Tracking issue for procedural macro support
Procedural macro support feature depends on the following (experimental) features:
-
org.rust.cargo.evaluate.build.scripts- enables building and collecting build artifacts including proc-macro libraries during importing of project structure -
org.rust.macros.proc- enables expansion of procedural macros
To enable an experimental feature, type Experimental feature in the dialog of Help | Find Action action, enable the corresponding items and reload the project model via Refresh Cargo Projects action in Cargo tool window
- [x] introduce proc macro server to evaluate procedural macro functions #6658
- [x] compile only "host" code of project: build scripts and proc-macro targets when
org.rust.cargo.evaluate.build.scriptsexperimental feature is enabled #6735 - [x] support Apple silicon machines (
aarch64-apple-darwintarget) #7307 - [x] expand function-like macros #6564 Fixes #4707 Fixes #6367 Fixes #6983 Fixes #7090 Fixes #7242 Fixes #7608 Fixes #7699 Fixes #8049 Fixes #8785 Fixes #9266
- [x] expand custom derive macros (impl only) #6992 Fixes #4629 Fixes #5468 Fixes #5478 Fixes #5728 Fixes #5954 Fixes #6036 Fixes #6489 Fixes #6880 Fixes #7158 (requires #7184) Fixes #7848 Fixes #8193 Fixes #8415 Fixes #8581 Fixes #8610 Fixes #8847 Fixes #8856 Fixes #9133 Fixes #9216
- [x] take into account all items generated by custom derive macros #7725 Fixes #1786 Fixes #7365 Fixes #7901 Fixes #7997
- [x] expand attribute macros #7194 Fixes #5104 Fixes #5239 Fixes #5748 Fixes #5896 Fixes #5975 (requires changes in the corresponding inspection) Fixes #6006 Fixes #6091 Fixes #6093 Fixes #6162 (requires changes in the annotator) Fixes #6482 Fixes #6938 Fixes #7610 Fixes #7863 Fixes #8350 Fixes #8407 FIxes #8640 Fixes #9384
- [ ] enable
org.rust.cargo.evaluate.build.scriptsexperimental feature by default - [ ] enable
org.rust.macros.procexperimental feature by default - [ ] Other Fixes #7170
Does this mean that a subset of derive macro code is currently considered (e.g. for code completion and missing-symbol highlighting?
take into account all items generated by custom derive macros
For example, the Snafu derive macro produces structs which intellij-rust seems to be unaware of.
Would a minimal use case example of this and tracking issue be of any benefit?
@webern
Does this mean that a subset of derive macro code is currently considered (e.g. for code completion and missing-symbol highlighting?
Yep. Currently, the plugin takes into account only impl blocks generated by derive proc macro
Would a minimal use case example of this and tracking issue be of any benefit?
I don't think that we need additional tracking issue only for that case because the current issue already contains a similar item: "take into account all items generated by custom derive macros". But an additional use-case can be useful indeed to check it during the corresponding implementation
additional use-case can be useful indeed to check it during the corresponding implementation
Here is the use-case:
Cargo.toml:
[package]
name = "snafu-jetbrains"
version = "0.1.0"
edition = "2018"
[dependencies]
snafu = "0.6"
main.rs
use snafu::Snafu;
/// The error type for this library.
#[derive(Debug, Snafu)]
enum Error {
#[snafu(display("This is always an error:: {}", message))]
AlwaysError { message: String },
}
fn hello_world() -> Result<(), Error> {
AlwaysError {
message: "this is a struct created by snafu",
}
.fail()
}
fn main() {
hello_world().unwrap()
}
Problem:

Desired behavior: code completion should be available for the struct AlwaysError:

Desired behavior: context actions should provide the ability to fill in missing struct fields for the AlwaysError struct.

Thank you! 🚀
@webern Thank you for your example. I've filed a separate issue #7365 with it
How are we coming along on take into account all items generated by custom derive macros and #7365? This is suuuuuch a huge feature for me. Is at the top of the intellij-rust priority list?
Right now I have to open Sublime Text using Rust Analyzer to discover generated structs and functions! Help, I'm lost without my IDE!
@webern #7725
What's blocking https://github.com/intellij-rust/intellij-rust/issues/6732? I don't see that issue mentioned here. I'm experiencing the same problem and would love if that is fixed.
@hamza1311, I suppose it's #7725, but you can use the latest yew version from GitHub (not from crates.io) that works well right now.
@vlad20012, I see. It seems that specific case is fixed but there are other cases where the bug still exists. For example, the following code still gives the same message:
lib.rs:
use yew::prelude::*;
fn _test() -> Html {
use_effect(|| {
|| {}
});
html! {
}
}
Cargo.toml:
[package]
name = "yew-html-macro-bug-repro"
version = "0.1.0"
edition = "2018"
[dependencies]
yew = { git = "https://github.com/yewstack/yew/" }
Screenshot:

It is also worth mentioning that the warning disappears if I do this:

EDIT: Fixed with #8238 and #8236
Can't seem to get this working with the sqlx::query_as! macro. I have enabled both org.rust.cargo.evaluate.build.scripts and org.rust.macros.proc
I get no methods on sqlx::query_as!(). see image below
https://youtrack.jetbrains.com/api/files/74-1179280?sign=MTYzNDUxNTIwMDAwMHwxMS02Mjg0MTF8NzQtMTE3OTI4MHxDTUUwRmRSSmRZUnRYakVienVnTHZz%0D%0AcEdxT2pDNnQyaDdOeGI5ZzNmSnpRDQo%0D%0A&updated=1634324447434
@longfellowone could you, please, post the image here itself or provide another link? I see only 404 with this one
Actual

Expected (this is what rust-analyzer shows in vscode) - Note correct methods showing such as fetch_all() https://docs.rs/sqlx/0.5.9/sqlx/query/struct.QueryAs.html
)
I've noted that for sqlx I need to
- set
SQLX_OFFLINE=truein my project's root.env - run
cargo sqlx prepare
for intellij-rust to be able to expand query! macros. (both documented in https://github.com/launchbadge/sqlx/tree/ce801b933006c422ada464d0663c68dcf6c680d4/sqlx-cli#force-building-in-offline-mode)
Setting DATABASE_URL in this .env does not work. I suspect the macro expander can't reach the database for some reason.
I think https://github.com/intellij-rust/intellij-rust/issues/8221 could be part of this tracking issue.
With #7194 and with all experimental features enabled, wonder why code highlighting for functions is different (i.e. half-disabled) when applying even a dummy attribute macro like this one?
// do nothing, just return the input back
#[proc_macro_attribute]
pub fn dummy(_args: TokenStream, input: TokenStream) -> TokenStream {
input
}
and then:

Can anything be done from the proc macro authors standpoint so that it would be properly recognized by intellij-rust (or is it a bug of some sort and it should already work)? (e.g. in my particular case, I know that the input to a proc macro must be ItemFn)
@aldanor Most likely you need to update the IntelliJ Rust plugin
I've noted that for sqlx I need to
- set
SQLX_OFFLINE=truein my project's root.env- run
cargo sqlx preparefor
intellij-rustto be able to expandquery!macros. (both documented in https://github.com/launchbadge/sqlx/tree/ce801b933006c422ada464d0663c68dcf6c680d4/sqlx-cli#force-building-in-offline-mode)Setting
DATABASE_URLin this.envdoes not work. I suspect the macro expander can't reach the database for some reason.
@hectorj
Fixed: #8238 and #8236
Little confused about the status of #1786 -- the issue is shown with a checkmark here and a merged fix back in August, but the functionality doesn't work for me on the latest 0.4.162.4321-213 plugin build with org.rust.macros.proc enabled. Still waiting on something else?
@thurn could you provide an example where the plugin doesn't work with proc macros as expected, please?
reported as #8328
Having issues with proc macros again #8423
Is there any work going on for reporting errors generated by function-like macros? Right now, they just fail silently, forcing user to run cargo check to see what happened
I tried enabling this, refreshed a cargo project and it just worked. Unfortunately, it only worked once. All changes since the initial refresh don't show up. I tried refreshing, I disabled and reenabled the functionality but nothing worked.
My code compiles fine even though IntelliJ now shows it as "red".
Before I open a new ticket I thought I'd ask if I am maybe missing something: Do I need to do anything to manually update proc macro details and/or can I delete a cache somewhere? A cargo clean followed by a refresh works. Is this intended?
Had a issue with Sycamore (originally reported it for Yew) but these experimental features solved it for me. Also added screenshots and a repo to reproduce it: https://github.com/intellij-rust/intellij-rust/issues/6732#issuecomment-1248386202
Hi I wanted to activate org.rust.macros.proc as an experimental feature, but I do not see it in there, what can I do to make it available? Thanks
@CristianKerr follow this instruction
@CristianKerr follow this instruction Its not there
@CristianKerr I suppose you use too old plugin version
@CristianKerr I suppose you use too old plugin version
You are right, I have 0.3.140.3644-202, but I do not know why it doesn't show latest version for me (it looks like its up to date). Thanks!
I do not know why it doesn't show latest version for me
Probably, you use old IDE version as well
