Skip to content

Commit

Permalink
enable --all-targets for clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeytimoshin committed Jan 10, 2025
1 parent 4498096 commit f6211cb
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ members = [
"sdk-libs/photon-api",
"sdk-libs/program-test",
"xtask",
"examples/token-escrow/programs/*",
"examples/token-escrow/programs/token-escrow",
"program-tests/account-compression-test",
"program-tests/compressed-token-test",
"program-tests/e2e-test",
Expand Down
22 changes: 11 additions & 11 deletions program-libs/zero-copy/src/wrapped_pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,22 +199,22 @@ mod test {

#[test]
fn test_rawpointer_from_bytes_success() {
let mut buffer = [0u8; 4];
let buffer = [0u8; 4];
let value = 42u32;

// Write value to buffer
unsafe { *(buffer.as_ptr() as *mut u32) = value };

let pointer: WrappedPointer<u32> = WrappedPointer::from_bytes(&mut buffer).unwrap();
let pointer: WrappedPointer<u32> = WrappedPointer::from_bytes(&buffer).unwrap();
assert_eq!(*pointer.get(), value);
}

#[test]
fn test_rawpointer_from_bytes_insufficient_memory() {
let value = 42u32;
let mut buffer = value.to_le_bytes();
let buffer = value.to_le_bytes();

let result = WrappedPointer::<u32>::from_bytes(&mut buffer[0..2]);
let result = WrappedPointer::<u32>::from_bytes(&buffer[0..2]);
assert_eq!(
result,
Err(ZeroCopyError::InsufficientMemoryAllocated(2, 4))
Expand All @@ -223,14 +223,14 @@ mod test {

#[test]
fn test_rawpointer_from_bytes_at_success() {
let mut buffer = [0u8; 8];
let buffer = [0u8; 8];
let value = 42u32;
let mut offset = 4;
// Write value to buffer
unsafe { *(buffer[offset..].as_ptr() as *mut u32) = value };

let pointer: WrappedPointer<u32> =
WrappedPointer::from_bytes_at(&mut buffer, &mut offset).unwrap();
WrappedPointer::from_bytes_at(&buffer, &mut offset).unwrap();
assert_eq!(*pointer.get(), value);
assert_eq!(offset, 8);
}
Expand All @@ -244,15 +244,15 @@ mod test {
buffer[..8].copy_from_slice(&1u64.to_le_bytes()); // Fake discriminator
unsafe { *(buffer[8..].as_ptr() as *mut u32) = value };

let pointer = WrappedPointer::<u32>::from_bytes_with_discriminator(&mut buffer).unwrap();
let pointer = WrappedPointer::<u32>::from_bytes_with_discriminator(&buffer).unwrap();
assert_eq!(*pointer.get(), value);
}

#[test]
#[should_panic(expected = "out of range for slice of length")]
fn test_rawpointer_from_bytes_with_discriminator_fail() {
let mut buffer = [0u8; 7]; // Not enough space for discriminator
let result = WrappedPointer::<u32>::from_bytes_with_discriminator(&mut buffer);
let buffer = [0u8; 7]; // Not enough space for discriminator
let result = WrappedPointer::<u32>::from_bytes_with_discriminator(&buffer);
assert_eq!(
result,
Err(ZeroCopyError::InsufficientMemoryAllocated(7, 8))
Expand All @@ -261,8 +261,8 @@ mod test {

#[test]
fn test_rawpointer_from_bytes_with_discriminator_insufficient_memory() {
let mut buffer = [0u8; 9];
let result = WrappedPointer::<u32>::from_bytes_with_discriminator(&mut buffer);
let buffer = [0u8; 9];
let result = WrappedPointer::<u32>::from_bytes_with_discriminator(&buffer);
assert_eq!(
result,
Err(ZeroCopyError::InsufficientMemoryAllocated(1, 4))
Expand Down
2 changes: 1 addition & 1 deletion program-libs/zero-copy/tests/slice_mut_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ fn test_new_at_multiple() {
let mut account_data = vec![0u8; 128];
let mut offset = 0;
let capacity = 4;
let mut reference_vecs = vec![vec![], vec![]];
let mut reference_vecs = [vec![], vec![]];

{
let mut initialized_vecs = ZeroCopySliceMutUsize::<u64>::new_at_multiple(
Expand Down
8 changes: 4 additions & 4 deletions program-libs/zero-copy/tests/vec_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn test_zero_copy_vec() {
println!("test_zero_copy_vec_with_capacity::<u32>()");
test_zero_copy_vec_new::<u64, u32>(u8::MAX as u64);
println!("test_zero_copy_vec_with_capacity::<u64>()");
test_zero_copy_vec_new::<usize, u32>(10000 as usize);
test_zero_copy_vec_new::<usize, u32>(10000_usize);
}

#[test]
Expand Down Expand Up @@ -171,7 +171,7 @@ where
let ref_length: CAPACITY = CAPACITY::from_usize(i + 1).unwrap();
assert_eq!(length, ref_length.to_ne_bytes().as_ref().to_vec());

let padding_start = metadata_size.clone();
let padding_start = metadata_size;
add_padding::<CAPACITY, T>(&mut metadata_size);
let padding_end = metadata_size;
let data = data[padding_start..padding_end].to_vec();
Expand Down Expand Up @@ -250,7 +250,7 @@ where
let ref_length: CAPACITY = CAPACITY::zero(); //;(0).to_usize().unwrap();
assert_eq!(length, ref_length.to_ne_bytes().as_ref().to_vec());

let padding_start = metadata_size.clone();
let padding_start = metadata_size;
add_padding::<CAPACITY, T>(&mut metadata_size);
let padding_end = metadata_size;
let data = data[padding_start..padding_end].to_vec();
Expand Down Expand Up @@ -443,7 +443,7 @@ fn test_init_multiple_pass() {
assert_eq!(initialized_vecs[1].capacity(), capacity);
assert_eq!(initialized_vecs[0].len(), 0);
assert_eq!(initialized_vecs[1].len(), 0);
let mut reference_vecs = vec![vec![], vec![]];
let mut reference_vecs = [vec![], vec![]];
for i in 0..capacity {
for (j, vec) in initialized_vecs.iter_mut().enumerate() {
assert!(vec.get(i).is_none());
Expand Down
2 changes: 1 addition & 1 deletion scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ npx nx run-many --target=format:check --all
npx nx run-many --target=lint --all

cargo +nightly fmt --all -- --check
cargo clippy --workspace -- -D warnings
cargo clippy --workspace --all-targets -- -D warnings

0 comments on commit f6211cb

Please sign in to comment.