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

I kept getting this error … idk why .

mac silicon rust 1.86 avm 0.31.0

i tried all different installs

error[E0599]: no method named source_file found for struct proc_macro2::Span in the current scope –> /Users/stevensanborn/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anchor-syn-0.31.0/src/idl/defined.rs:499:66 | 499 | …n::call_site().source_file().path(); | ^^^^^^^^^^^ method not found in Span

so what fixed it for em was

line 499 … let source_path = proc_macro2::Span::call_site().file();

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 26 (11 by maintainers)

Most upvoted comments

same issue

Also, as a temporary workaround you can do

anchor build --no-idl

RUSTUP_TOOLCHAIN=nightly-2025-04-01 anchor idl build -o target/idl/YOUR_PROG_NAME.json -t target/types/YOUR_PROG_NAME.ts

(and replace YOUR_PROG_NAME with your program name)

Also, as a temporary workaround you can do

anchor build --no-idl

RUSTUP_TOOLCHAIN=nightly-2025-04-01 anchor idl build -o target/idl/YOUR_PROG_NAME.json -t target/types/YOUR_PROG_NAME.ts

(and replace YOUR_PROG_NAME with your program name)

I tried this solution, however:

error[E0599]: no method named file found for reference &proc_macro::Span in the current scope –> /home/cedro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/proc-macro2-1.0.95/src/wrapper.rs:465:36 | 465 | Span::Compiler(s) => s.file(), | ^^^^ method not found in &Span

error[E0599]: no method named local_file found for reference &proc_macro::Span in the current scope –> /home/cedro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/proc-macro2-1.0.95/src/wrapper.rs:473:36 | 473 | Span::Compiler(s) => s.local_file(), | ^^^^^^^^^^ method not found in &Span

Replace the line with this :

In defined.rs

Line 499

use this

let source_path = proc_macro2::Span::call_site().file();

instead of previous line :

let source_path = proc_macro2::Span::call_site().source_file();

Make sure you’re inside your project directory

Make sure you’re using proc-macro2 v0.1.94, not v0.1.95

Yep, you’re correct. Opened a PR for it: https://github.com/solana-foundation/anchor/pull/3663