From c4ade0f70b872fae55aa8564070b6bb06fc25d12 Mon Sep 17 00:00:00 2001 From: "Christopher H. Jordan" Date: Wed, 15 Jun 2022 14:11:09 +0800 Subject: [PATCH] Clippy lints and update cbindgen. cast_abs_to_unsigned is a fun one. --- Cargo.toml | 2 +- src/convert/mod.rs | 8 ++++---- src/ffi/test.rs | 32 ++++++++++++++------------------ src/metafits_context/test.rs | 2 +- src/voltage_context/test.rs | 12 ++++-------- 5 files changed, 24 insertions(+), 32 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b17531c..7e73d97 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,7 +49,7 @@ tempdir = "0.3.6" [build-dependencies] built = "0.5.0" -cbindgen = "0.21.0" +cbindgen = "0.24.0" [[example]] name = "mwalib-data-dump" diff --git a/src/convert/mod.rs b/src/convert/mod.rs index 398aa40..10955ac 100644 --- a/src/convert/mod.rs +++ b/src/convert/mod.rs @@ -72,13 +72,13 @@ impl LegacyConversionBaseline { baseline, ant1, ant2, - xx_index: xx.abs() as usize, + xx_index: xx.unsigned_abs() as usize, xx_conjugate: xx < 0, - xy_index: xy.abs() as usize, + xy_index: xy.unsigned_abs() as usize, xy_conjugate: xy < 0, - yx_index: yx.abs() as usize, + yx_index: yx.unsigned_abs() as usize, yx_conjugate: yx < 0, - yy_index: yy.abs() as usize, + yy_index: yy.unsigned_abs() as usize, yy_conjugate: yy < 0, } } diff --git a/src/ffi/test.rs b/src/ffi/test.rs index 5168c4a..2416df5 100644 --- a/src/ffi/test.rs +++ b/src/ffi/test.rs @@ -1741,18 +1741,16 @@ fn test_mwalib_metafits_metadata_get_from_metafits_context_legacy_vcs_valid() { // // Test antennas // - let item: Vec = + let items: Vec = ffi_boxed_slice_to_array(metafits_metadata.antennas, metafits_metadata.num_ants); - assert_eq!(item.len(), 128, "Array length is not correct"); - - for i in 0..128 { - if item[i].tile_id == 154 { - assert_eq!(item[i].rfinput_y, 1); - } + assert_eq!(items.len(), 128, "Array length is not correct"); - if item[i].tile_id == 104 { - assert_eq!(item[i].rfinput_y, 0); + for item in items { + if item.tile_id == 154 { + assert_eq!(item.rfinput_y, 1); + } else if item.tile_id == 104 { + assert_eq!(item.rfinput_y, 0); } } } @@ -1872,18 +1870,16 @@ fn test_mwalib_metafits_metadata_get_from_voltage_context_valid() { // // Test antennas // - let item: Vec = + let items: Vec = ffi_boxed_slice_to_array(metafits_metadata.antennas, metafits_metadata.num_ants); - assert_eq!(item.len(), 128, "Array length is not correct"); - - for i in 0..128 { - if item[i].tile_id == 154 { - assert_eq!(item[i].rfinput_y, 1); - } + assert_eq!(items.len(), 128, "Array length is not correct"); - if item[i].tile_id == 104 { - assert_eq!(item[i].rfinput_y, 0); + for item in items { + if item.tile_id == 154 { + assert_eq!(item.rfinput_y, 1); + } else if item.tile_id == 104 { + assert_eq!(item.rfinput_y, 0); } } diff --git a/src/metafits_context/test.rs b/src/metafits_context/test.rs index 9048fe5..ad199c6 100644 --- a/src/metafits_context/test.rs +++ b/src/metafits_context/test.rs @@ -91,7 +91,7 @@ fn test_metafits_context_new_corrlegacy_valid() { assert_eq!(context.delays[15], 0); // Calibrator - assert_eq!(context.calibrator, false); + assert!(!context.calibrator); assert_eq!(context.calibrator_source, ""); // Global attenuation: 1 dB, diff --git a/src/voltage_context/test.rs b/src/voltage_context/test.rs index 11c95b9..bf133ae 100644 --- a/src/voltage_context/test.rs +++ b/src/voltage_context/test.rs @@ -151,8 +151,6 @@ pub(crate) fn get_index_for_location_in_test_voltage_file_legacy( rfinput_index: usize, ) -> usize { let num_rfinputs = 2; - let rf: usize; - let fc: usize; // Note for legacy always only have 1 block (i.e. no concept of a block) let bytes_per_rfinput = 1; @@ -165,10 +163,10 @@ pub(crate) fn get_index_for_location_in_test_voltage_file_legacy( let s = sample_index * bytes_per_sample; // Now within the sample, move to the correct fine chan - fc = fine_chan_index * bytes_per_fine_chan; + let fc = fine_chan_index * bytes_per_fine_chan; // Now within the fine channel get the rf_input - rf = rfinput_index * bytes_per_rfinput; + let rf = rfinput_index * bytes_per_rfinput; // Return the correct index s + rf + fc @@ -183,8 +181,6 @@ pub(crate) fn get_index_for_location_in_test_voltage_file_mwaxv2( ) -> usize { let num_finechan = 1; let num_rfinputs = 2; - let vb: usize; - let rf: usize; let bytes_per_fine_chan = 64000 * 2; @@ -193,10 +189,10 @@ pub(crate) fn get_index_for_location_in_test_voltage_file_mwaxv2( let bytes_per_voltage_block = num_rfinputs * bytes_per_rfinput; // This will position us at the correct block - vb = voltage_block_index * bytes_per_voltage_block; + let vb = voltage_block_index * bytes_per_voltage_block; // Now within the block, move to the correct rf_input - rf = rfinput_index * bytes_per_rfinput; + let rf = rfinput_index * bytes_per_rfinput; // Return the correct index vb + rf + (sample_index * 2) + value_index