Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

proc macro not found

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)
like image 940
Thorkil Værge Avatar asked Dec 03 '25 17:12

Thorkil Værge


2 Answers

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.

like image 111
sshine Avatar answered Dec 05 '25 14:12

sshine


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.

like image 22
Thorkil Værge Avatar answered Dec 05 '25 14:12

Thorkil Værge