Skip to content

fix: Update proc-macro2 usage for latest nightly #3663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

cryptopapi997
Copy link
Contributor

@cryptopapi997 cryptopapi997 commented Apr 16, 2025

As of nightly-2025-04-16, SourceFile and the methods around it don't exist anymore, so anyone updating rust or installing rust won't be able to compile the idl anymore. proc-macro2 already updated, this PR updates anchor accordingly. Note that this will require users to update to the latest nightly (and will break users with an older nightly). Idk if this counts as a breaking change since it only affects nightly...

Fixes #3662

@cryptopapi997 cryptopapi997 changed the title Update proc-macro for latest nightly Update proc-macro2 usage for latest nightly Apr 16, 2025
@cryptopapi997 cryptopapi997 changed the title Update proc-macro2 usage for latest nightly Update proc-macro2 usage for latest nightly Apr 16, 2025
@cryptopapi997 cryptopapi997 changed the title Update proc-macro2 usage for latest nightly fix: Update proc-macro2 usage for latest nightly Apr 16, 2025
@tobaccorico
Copy link

as far as I can tell it also affects stable, not only nightly (at least on my local build)

@kingmanas
Copy link

Replace the respective error line with

📁 File:

defined.rs

📝 Line 499:

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

@Rayato159
Copy link

I'm facing this problem too even though I use stable version of rustc.

@RealAyyo
Copy link

RealAyyo commented Apr 16, 2025

same. Not only nightly

@acheroncrypto acheroncrypto added idl related to the IDL, either program or client side fix Bug fix PR labels Apr 16, 2025
Copy link
Collaborator

@acheroncrypto acheroncrypto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fix.

We're also planning to make the IDL generation use the stable compiler by default and make code that required nightly optional via a CLI flag to avoid issues like this one. It sounds like these methods will be stabilized (as mentioned in rust-lang/rust#139671), so we might be able to avoid nightly completely when that happens.

Related: There is an open issue (rust-lang/rust#139903) regarding the naming of local_file.

@hryer
Copy link

hryer commented Apr 16, 2025

Is anything that I can help maybe?, I need this fix ASAP. Also, I want to tell the CI failed

no method named `source_file` found for struct `proc_macro2::Span` in the current scope
   --> /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anchor-syn-0.31.0/src/idl/defined.rs:499:66
    |
499 |                 let source_path = proc_macro2::Span::call_site().source_file().path();
    |                                                                  ^^^^^^^^^^^ method not found in `Span`

@jacobcreech
Copy link
Collaborator

@hryer we're waiting on the update and I'll check into the CI

@andreisilviudragnea
Copy link
Contributor

Hello. Is this going to be released as a hotfix for Anchor v0.31.0?

@quanghuynguyen1902
Copy link

Please fix it ASAP.

@moribus-single
Copy link

having the same issue
even in the new empty anchor project

@tobaccorico
Copy link

having the same issue even in the new empty anchor project

this is the temporary fix that worked best for me:
https://solana.stackexchange.com/a/21560/39751

@conceitodigital
Copy link

Facing the same issue.

@romeoscript
Copy link

source_path

i can't find this file , where would i locate it ?

@iamramtin
Copy link

Using anchor build --no-idl works as a temporary workaround (tested on Anchor v0.30.1)

@romeoscript
Copy link

Using anchor build --no-idl works as a temporary workaround (tested on Anchor v0.30.1)

so how do i generate IDL for frontend use ?

Copy link
Collaborator

@acheroncrypto acheroncrypto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're most likely going to make a patch release for this issue. Thanks for the fix and also responsiveness!

@acheroncrypto acheroncrypto merged commit 54d5396 into solana-foundation:master Apr 17, 2025
48 of 52 checks passed
@cryptopapi997 cryptopapi997 deleted the fix-proc-macro-2 branch April 17, 2025 21:32
@adama789
Copy link

Hi, how to pull these changes? Will it be released in anchor 0.31.1?

@Vinayapr23
Copy link

Vinayapr23 commented Apr 18, 2025

How will these changes be reflected? In anchor 0.31.1 ?
So what to do with current 0.31.0 in the meantime

@stevensanborn
Copy link

anchor-cli 0.31.0
rustc 1.88.0-nightly (191df20fc 2025-04-18)
adding to cargo toml worked for me :
proc-macro2 = { version = "1.0.95"}

@h0lme3
Copy link

h0lme3 commented Apr 19, 2025

Is it fixed?

@0xJamesBong
Copy link

So what's the solution?

@Vinayapr23
Copy link

So what's the solution?

Update to anchor 0.31.1 which was released today

@h0lme3
Copy link

h0lme3 commented Apr 20, 2025

So what's the solution?

Update to anchor 0.31.1 which was released today

please check the issue, I figured out the issue yesterday but today I am facing a new issue
#3676 (comment)

@0xm4ud
Copy link

0xm4ud commented Apr 21, 2025

@hryer this line: let source_path = proc_macro2::Span::call_site().source_file().path();
into this: let source_path = proc_macro2::Span::call_site().file().to_string();

@cryptopapi997
Copy link
Contributor Author

For anyone still runing into this issue:

Make sure you're using

  • anchor v0.31.1
  • latest rust nightly
  • proc_macro2 v0.1.95 in your cargo.lock

@rotcan
Copy link

rotcan commented Apr 21, 2025

Getting below error while using

  • anchor v0.31.1
  • rust nightly-2025-04-21
  • proc_macro2 v0.1.95

Error

no method named file found for reference &proc_macro::Span in the current scope
|
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
|
473 | Span::Compiler(s) => s.local_file(),
| ^^^^^^^^^^ method not found in &Span

@0xm4ud
Copy link

0xm4ud commented Apr 21, 2025

@rotcan

Getting below error while using

  • anchor v0.31.1
  • rust nightly-2025-04-21
  • proc_macro2 v0.1.95

Error

no method named file found for reference &proc_macro::Span in the current scope | 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 | 473 | Span::Compiler(s) => s.local_file(), | ^^^^^^^^^^ method not found in &Span

have you tried reverting proc_macro2 v0.1.95 to proc_macro2 v0.1.94?

@rotcan
Copy link

rotcan commented Apr 21, 2025

Hi @0xm4ud ,

@rotcan

Getting below error while using

  • anchor v0.31.1
  • rust nightly-2025-04-21
  • proc_macro2 v0.1.95

Error
no method named file found for reference &proc_macro::Span in the current scope | 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 | 473 | Span::Compiler(s) => s.local_file(), | ^^^^^^^^^^ method not found in &Span

have you tried reverting proc_macro2 v0.1.95 to proc_macro2 v0.1.94?

With below configuration

  • anchor v0.31.1
  • rust nightly - 2025-04-21
  • proc_macro2 v0.1.94
  • solana - 2.1.4

I am getting this error

no method named file found for struct proc_macro2::Span in the current scope
--> /.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 | | .file()
| | -^^^^ method not found in Span
| |
|
|

@0xm4ud
Copy link

0xm4ud commented Apr 21, 2025

@rotcan I saw that error this morning. What I did was: cargo update -p proc-macro2, rustup override set 1.81, which solved it for me.
btw I'm not running nightly.

@rotcan
Copy link

rotcan commented Apr 21, 2025

@0xm4ud , still getting same error with below setting :(

  • anchor 0.31.1
  • rust- 1.81
  • proc_macro2 v0.1.94
  • solana - 2.1.4

no method named file found for struct proc_macro2::Span in the current scope
--> /.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 | | .file()
| | -^^^^ method not found in Span
| |
|

@0xm4ud
Copy link

0xm4ud commented Apr 21, 2025

@rotcan hmm.. cargo update -p proc-macro2 should've changed/updated your proc-macro2 version, but by your post I see still is 1.94, try removing the lib /proc-macro2-1.0.94/directory and running cargo update -p proc-macro2 again.
Clean the project as well, and cargo clean before building it again.
Updating proc-macro2 v1.0.94 -> v1.0.95

@rotcan
Copy link

rotcan commented Apr 21, 2025

@0xm4ud Got it working thanks. I deleted proc-macro2-1.0.94 & 95 directory and anchor-syn-0.31.1 directory in cargo registry. Then ran rustup update.
Following config worked
rustup - 2025-04-21 nightly
anchor - 0.31.1
solana - 2.14.0
proc-macro2 - 1.0.95

@jgur-psyops
Copy link

Was confused by people saying you need nightly rust.

You don't need to be using nightly in your workspace, but you DO need to update your nightly because anchor idl generation uses it. Make sure you have run rustup update and your rustc 1.88.0-nightly in the resulting list is up to date. Your toolchain can be 1.81.0 or 1.79 stable without issue.

@el-tumero
Copy link

this works for me:

  • anchor - 0.31.1
  • solana - 2.1.0
  • proc-macro2 - 1.0.95
  • rust - 1.81.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix PR idl related to the IDL, either program or client side
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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