anchor: error[E0599]: no method named `local_file` found for struct `proc_macro2::Span` in the current scope

I’m having a new trouble when I build anchor initial project today:

error[E0599]: no method named local_file found for struct proc_macro2::Span in the current scope –> /home/haodev007/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anchor-syn-0.31.1/src/idl/defined.rs:501:22 | 500 | let source_path = proc_macro2::Span::call_site() | ______________- 501 | | .local_file() | | -^^^^^^^^^^ method not found in Span | || |

I’ve checked the issue https://github.com/solana-foundation/anchor/issues/3662 yesterday and downgraded proc-macro2 crate version cargo update -p proc-macro2 --precise 1.0.94 It worked with anchor version 0.31.0 yesterday after downgraded proc-macro2 version but it doesnt work again

current rust and anchor version is rustc 1.86.0 (05f9846f8 2025-03-31) anchor-cli 0.31.1

Please help me, thanks!

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 20 (1 by maintainers)

Most upvoted comments

For those that are running into this issue, do the following:

  1. rustup update
  2. Remove your cargo.lock or confirm that proc-macro2 is 1.0.95 or higher
  3. anchor build

and you should complete successfully. The problem lies in you not having nightly 04-16 or higher locally, anchor 0.31.1, and proc-macro2 <1.0.95

@h0lme3 could you run cargo update? Seems people are running into this because their crates.io cache is out of date.

@jacobcreech sorry, it’s just not working and anchor build --no-idl works to build project temporarily without idl. But we should still do like that?

I’m experiencing the same issue, it worked yesterday but not today.

UPD: Updating anchor worked for me

Was only able to get it back working with IDL using these (Linux): anchor: 0.31.0 rustc: 1.79.0 solana-cli: 2.1.0

proc-macro2: 1.0.95

And applying the fix described here: https://solana.stackexchange.com/questions/21553/proc-macro2-issue

In anchor-syn-0.31.0 file defined.rs:499 line replace with -> let source_path = proc_macro2::Span::call_site().file();

Otherwise only worked with --no-idl

@h0lme3 could you run cargo update? Seems people are running into this because their crates.io cache is out of date.

cargo update not work anchor build --no-idl works