3

My main function is decorated with two proc macros like this:

#[paw::main]
#[tokio::main]
pub async fn main(args: Args) -> Result<()>

This compiles and runs as I expect it but VS code's rust-analyzer gives me this error on both lines of attribute macros #[paw::main] and #[tokio::main]. The error message is:

proc macro `main` not expanded: proc macro not found rust-analyzer (unresolved-proc-macro)
Thorkil Værge
  • 2,727
  • 5
  • 32
  • 48

2 Answers2

1

There might be a better way, but this will make the error go away:

  • Go to settings and find rust-analyzer > Diagnostics: Disabled. You can search for "rust analyzer diagnostics" to find this option.
  • Press Add Item
  • Add the item unresolved-proc-macro and press OK.

Source for this solution was found here.

Thorkil Værge
  • 2,727
  • 5
  • 32
  • 48
1

Judging by this GitHub issue, and in particular this comment, it seems that proc macro expansion is quite dependent on the version of the Rust compiler. The suggested fix is to keep your rust-analyzer updated. Switching to the pre-release version of rust-analyzer fixed this for me on rustc 1.61, which is the latest stable in time of writing. Presumably the pre-release version of rust-analyzer is always most likely to be ABI-compatible with the latest stable version of rustc.

sshine
  • 15,635
  • 1
  • 41
  • 66
  • It seems to have been fixed in the latest stable (non-pre-release version) today. #135 seems to have fixed it. The changelog also mentions proc macro errors. https://rust-analyzer.github.io/thisweek/2022/06/27/changelog-135.html So pre-release is no longer necessary :) – Thorkil Værge Jun 27 '22 at 08:57