Skip to content

Commit c0f9a14

Browse files
authored
pubkey: Don't always mark variable as mut (#108)
#### Problem If the `std` feature is disabled on `solana-pubkey`, there's currently a warning in the build due to a variable that doesn't need to be marked as `mut`. #### Summary of changes Gate marking the variable as `mut` depending on the feature / target. Also, we already pull in the std crate earlier if the `std` feature is enabled, so we don't need to do it twice.
1 parent 920d69e commit c0f9a14

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pubkey/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,15 +480,17 @@ impl Pubkey {
480480
type T = u32;
481481
const COUNTER_BYTES: usize = size_of::<T>();
482482
let mut b = [0u8; PUBKEY_BYTES];
483+
#[cfg(any(feature = "std", target_arch = "wasm32"))]
483484
let mut i = I.fetch_add(1) as T;
485+
#[cfg(not(any(feature = "std", target_arch = "wasm32")))]
486+
let i = I.fetch_add(1) as T;
484487
// use big endian representation to ensure that recent unique pubkeys
485488
// are always greater than less recent unique pubkeys.
486489
b[0..COUNTER_BYTES].copy_from_slice(&i.to_be_bytes());
487490
// fill the rest of the pubkey with pseudorandom numbers to make
488491
// data statistically similar to real pubkeys.
489492
#[cfg(any(feature = "std", target_arch = "wasm32"))]
490493
{
491-
extern crate std;
492494
let mut hash = std::hash::DefaultHasher::new();
493495
for slice in b[COUNTER_BYTES..].chunks_mut(COUNTER_BYTES) {
494496
hash.write_u32(i);

0 commit comments

Comments
 (0)