Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@divyaranjan1905
Copy link
Contributor

This PR simply replaces instances of std::error::Error with core::error::Error. It fixes #81, but as mentioned in the issue, it should probably be merged after #115.

Regards,

Divya.

@divyaranjan1905 divyaranjan1905 requested a review from a team as a code owner April 2, 2025 05:20
@joncinque joncinque added the breaking PR contains breaking changes label Apr 2, 2025
hash/src/lib.rs Outdated
Invalid,
}

#[cfg(feature = "std")]
Copy link
Contributor

Choose a reason for hiding this comment

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

i guess it can be dropped

}
}

#[cfg(feature = "std")]
Copy link
Contributor

Choose a reason for hiding this comment

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

the same here

}
}

#[cfg(feature = "std")]
Copy link
Contributor

Choose a reason for hiding this comment

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

and here

ArithmeticOverflow,
}

#[cfg(feature = "std")]
Copy link
Contributor

Choose a reason for hiding this comment

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

and this one also

// conversions must also be added
}

#[cfg(feature = "std")]
Copy link
Contributor

Choose a reason for hiding this comment

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

one more place

impl std::error::Error for InstructionError {}
impl core::error::Error for InstructionError {}

#[cfg(feature = "std")]
Copy link
Contributor

Choose a reason for hiding this comment

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

this is also can be omitted, because this is a core::fmt::Dispalay trait

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I originally considered dropping these attributes, but I wasn't sure. Thank you for confirming.

@divyaranjan1905
Copy link
Contributor Author

divyaranjan1905 commented Apr 2, 2025

Rebased the last few commits and removed the feature attributes for std.

@joncinque
Copy link
Collaborator

There have been quite a few changes since the PR was first opened, but we should be ready to integrate it -- can you rebase and update your branch? Let me know if you don't have time, and I'll be happy to take this over

@divyaranjan1905
Copy link
Contributor Author

There have been quite a few changes since the PR was first opened, but we should be ready to integrate it -- can you rebase and update your branch? Let me know if you don't have time, and I'll be happy to take this over

NO worries, will rebase and push by today.

@kevinheavey
Copy link
Contributor

Could you please add rust-version = "1.81.0" to the Cargo.toml for every crate using core::error? 🙏

Otherwise the error messages for people on old Rust versions will be confusing

- name: Check formatting
run: ./scripts/check-fmt.sh

check:
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this PR changing CI?

@joncinque
Copy link
Collaborator

@divyaranjan1905 do you still have time for this? If not I can take over the PR

@divyaranjan1905
Copy link
Contributor Author

@divyaranjan1905 do you still have time for this? If not I can take over the PR

I tried to rebase, but it didn't resolve nicely. Anything should I be specifically paying attention to? I'll try once again.

@joncinque
Copy link
Collaborator

There have been a lot of changes since the PR was created, so it would probably be easier to redo it from scratch. It looks like a few merge commits snuck in too, which probably isn't helping

@divyaranjan1905
Copy link
Contributor Author

divyaranjan1905 commented Jul 23, 2025

@joncinque Would this be required anymore? I was told to remove the std attribute from other places, but I am not sure about this.

#[cfg(all(feature = "std", feature = "alloc"))]

Copy link
Collaborator

@joncinque joncinque left a comment

Choose a reason for hiding this comment

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

Looks good overall! Just a few last things to fixup, then we should be good to go

Copy link
Collaborator

@joncinque joncinque left a comment

Choose a reason for hiding this comment

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

Just a last bit, then this can go in!

Comment on lines 15 to 17
#[cfg(feature = "std")]
use std::{error::Error, vec::Vec};
use core::error::Error;
use std::vec::Vec;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This isn't correct -- the whole point is to only bring in vec if the std feature is enabled:

Suggested change
#[cfg(feature = "std")]
use std::{error::Error, vec::Vec};
use core::error::Error;
use std::vec::Vec;
#[cfg(feature = "std")]
use std::vec::Vec;
use core::error::Error;

//! [RustCrypto's opaque signature error](https://github.com/RustCrypto/traits/tree/master/signature)
#[cfg(all(feature = "std", feature = "alloc"))]
#[cfg(all(feature = "alloc"))]
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: for all of these, we don't need all anymore

Suggested change
#[cfg(all(feature = "alloc"))]
#[cfg(feature = "alloc")]

@divyaranjan1905
Copy link
Contributor Author

That should be it :)

Sorry for the tiny mistakes.

@joncinque
Copy link
Collaborator

Looks like there are some CI failures:

  • be sure to run ./cargo nightly fmt --all to format the code
  • check the test errors by running ./scripts/build-sbf.sh or ./scripts/check-hack.sh

@divyaranjan1905
Copy link
Contributor Author

Looks like it's still failing. Interesting:
https://github.com/anza-xyz/solana-sdk/actions/runs/16509156545/job/46687480671?pr=116#step:6:659

I have not touched it in my diff though.

@divyaranjan1905
Copy link
Contributor Author

divyaranjan1905 commented Jul 24, 2025

Changing it to self.source(), I get the following complaint from the compiler:

error[E0599]: the method `as_ref` exists for reference `&&dyn Error`, but its trait bounds were not satisfied  
  --> signature/src/error.rs:85:34  
   |  
85 |             .map(|source| source.as_ref() as &(dyn core::error::Error + 'static))  
   |                                  ^^^^^^  
   |  
   = note: the following trait bounds were not satisfied:  
           `dyn StdError: AsRef<_>`  
           which is required by `&dyn StdError: AsRef<_>`  
           `&dyn StdError: AsRef<_>`  
           which is required by `&&dyn StdError: AsRef<_>`

Comment on lines 83 to 85
self.source
.as_ref()
.map(|source| source.as_ref() as &(dyn std::error::Error + 'static))
.map(|source| source.as_ref() as &(dyn core::error::Error + 'static))
Copy link
Collaborator

Choose a reason for hiding this comment

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

The issue is here -- since source only exists when the alloc feature is enabled, we need to gate this properly:

Suggested change
self.source
.as_ref()
.map(|source| source.as_ref() as &(dyn std::error::Error + 'static))
.map(|source| source.as_ref() as &(dyn core::error::Error + 'static))
#[cfg(feature = "alloc")]
{
self.source.as_ref()
.map(|source| source.as_ref() as &(dyn core::error::Error + 'static))
}
#[cfg(not(feature = "alloc"))]
{
None
}

* Also adds rust-version = "1.81.0" for all such crates
* Removes the redundant std attribute
@joncinque
Copy link
Collaborator

Looks like there's still a formatting issue and a build issue. If you can, please run the commands before committing. And if you don't have time, I can take the PR from here

@divyaranjan1905
Copy link
Contributor Author

@joncinque The commands somehow don't run on my system. And it's probably my system's issue. But yeah please take the PR from here and make the necessary formatting fixes.

Copy link
Collaborator

@joncinque joncinque 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 your contribution! I might need another approval, but let's see if this works...

Edit: I do need another approval

@joncinque joncinque requested a review from apfitzge July 28, 2025 12:42
@joncinque joncinque merged commit 7497283 into anza-xyz:master Jul 28, 2025
25 checks passed
febo pushed a commit to febo/solana-sdk that referenced this pull request Sep 21, 2025
* replace std with core for Error

* Also adds rust-version = "1.81.0" for all such crates
* Removes the redundant std attribute

* Fix CI failures

---------

Co-authored-by: Jon C <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking PR contains breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MSRV: Use core::error::Error instead of std::error::Error

5 participants