From ff2f29a592f9ad76793f1edd79ab726edc14a22a Mon Sep 17 00:00:00 2001 From: d3v-null Date: Thu, 4 Jul 2024 02:01:33 +0000 Subject: [PATCH] fix linter issues, downgrade vec1 for msrv compatibility --- Cargo.lock | 8 ++++---- Cargo.toml | 7 ++++--- src/beam/tests.rs | 3 --- src/cli/solutions/apply/tests.rs | 2 +- src/cli/solutions/plot/mod.rs | 3 +-- src/flagging/mwaf.rs | 4 ++-- src/io/read/mod.rs | 1 + src/io/read/ms/tests.rs | 4 ++-- src/io/write/mod.rs | 1 + src/io/write/tests.rs | 15 ++++++--------- src/math/tests.rs | 28 ++++++++++++---------------- src/solutions/tests.rs | 6 +++--- src/srclist/rts/read.rs | 2 +- src/srclist/veto.rs | 2 +- src/srclist/woden/read.rs | 2 +- 15 files changed, 40 insertions(+), 48 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c77b62e1..236e00e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,9 +62,9 @@ checksum = "d92bec98840b8f03a5ff5413de5293bfcd8bf96467cf5452609f939ec6f5de16" [[package]] name = "assert_cmd" -version = "2.0.14" +version = "2.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed72493ac66d5804837f480ab3766c72bdfab91a65e565fc54fa9e42db0073a8" +checksum = "00ad3f3a942eee60335ab4342358c161ee296829e0d16ff42fc1d6cb07815467" dependencies = [ "anstyle", "bstr", @@ -2392,9 +2392,9 @@ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "vec1" -version = "1.12.1" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eab68b56840f69efb0fefbe3ab6661499217ffdc58e2eef7c3f6f69835386322" +checksum = "2bda7c41ca331fe9a1c278a9e7ee055f4be7f5eb1c2b72f079b4ff8b5fce9d5c" dependencies = [ "serde", ] diff --git a/Cargo.toml b/Cargo.toml index 5de9fef3..eb85e924 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ authors = [ "Dev Null ", ] edition = "2021" -rust-version = "1.68" +rust-version = "1.68" # `cargo +1.68 build --locked` works, but technically development needs 1.73 license = "MPL-2.0" readme = "README.md" description = "Calibration software for the Murchison Widefield Array (MWA) radio telescope" @@ -96,7 +96,8 @@ strum = "0.24.0" strum_macros = "0.24.0" thiserror = "1.0.7" toml = "0.7.2" -vec1 = { version = "1.5.0", features = ["serde"] } +# TODO: bump vec1 after msrv update +vec1 = { version = "~1.10.0", features = ["serde"] } # "cuda" feature cuda-runtime-sys = { version = "0.3.0-alpha.1", optional = true } @@ -114,7 +115,7 @@ plotters = { version = "0.3.5", default-features = false, features = [ [dev-dependencies] approx = "0.5.1" -assert_cmd = "2.0.0" +assert_cmd = "2.0.0" # 2.0.14 requires Rust 1.73.0 criterion = { version = "0.4.0", default_features = false } indoc = "2.0.1" marlu = { version = "0.11.0", features = ["approx"] } diff --git a/src/beam/tests.rs b/src/beam/tests.rs index 58ae558d..a4b8a1e2 100644 --- a/src/beam/tests.rs +++ b/src/beam/tests.rs @@ -10,9 +10,6 @@ use serial_test::serial; use super::*; -#[cfg(any(feature = "cuda", feature = "hip"))] -use approx::abs_diff_eq; - #[test] fn no_beam_means_no_beam() { let azels = [ diff --git a/src/cli/solutions/apply/tests.rs b/src/cli/solutions/apply/tests.rs index f5db520f..6029f5aa 100644 --- a/src/cli/solutions/apply/tests.rs +++ b/src/cli/solutions/apply/tests.rs @@ -287,7 +287,7 @@ fn test_solutions_apply_trivial(mut args: SolutionsApplyArgs) { // Remove the newly-flagged chanblocks. (This is awkward because SPWs // weren't designed to be modified.) params.input_vis_params.spw.chanblocks = (0..) - .zip(params.input_vis_params.spw.chanblocks.into_iter()) + .zip(params.input_vis_params.spw.chanblocks) .filter(|(i, _)| !flagged_fine_chans.contains(i)) .map(|(_, c)| c) .collect(); diff --git a/src/cli/solutions/plot/mod.rs b/src/cli/solutions/plot/mod.rs index 31518cea..77398886 100644 --- a/src/cli/solutions/plot/mod.rs +++ b/src/cli/solutions/plot/mod.rs @@ -602,8 +602,7 @@ mod plotting { x_axis .values() .zip(amps.iter().map(|g| g[pol_index])) - .filter(|(_, y)| !y.is_nan()) - .map(|(x, y)| (x, y)), + .filter(|(_, y)| !y.is_nan()), 1, if [0, 3].contains(&pol_index) { ShapeStyle::from(&colour).filled() diff --git a/src/flagging/mwaf.rs b/src/flagging/mwaf.rs index 084204ee..dd7e387c 100644 --- a/src/flagging/mwaf.rs +++ b/src/flagging/mwaf.rs @@ -605,7 +605,7 @@ mod tests { assert_eq!(s[6], 128); assert_eq!(s[7], 3); - let expected = vec![ + let expected = [ 0.99999946, 0.99999946, 0.08406332, @@ -670,7 +670,7 @@ mod tests { assert_eq!(s[6], 128); assert_eq!(s[7], 3); - let expected = vec![ + let expected = [ 0.99999946, 0.99999946, 0.08051342, diff --git a/src/io/read/mod.rs b/src/io/read/mod.rs index 0f6dfc89..2ca68b9c 100644 --- a/src/io/read/mod.rs +++ b/src/io/read/mod.rs @@ -86,6 +86,7 @@ pub(crate) trait VisRead: Sync + Send { /// Read auto-correlation visibilities for all frequencies and tiles in a /// single timestep into the `data_array` and similar for the weights. + #[allow(dead_code)] // this is used in tests fn read_autos( &self, vis_fb: ArrayViewMut2>, diff --git a/src/io/read/ms/tests.rs b/src/io/read/ms/tests.rs index 36616323..ec89cbd0 100644 --- a/src/io/read/ms/tests.rs +++ b/src/io/read/ms/tests.rs @@ -415,12 +415,12 @@ fn test_timestep_reading() { let phase_centre = RADec::from_degrees(0., -27.); let array_pos = LatLngHeight::mwa(); #[rustfmt::skip] - let tile_xyzs = vec![ + let tile_xyzs = [ XyzGeodetic { x: 0., y: 0., z: 0., }, XyzGeodetic { x: 1., y: 0., z: 0., }, XyzGeodetic { x: 0., y: 1., z: 0., }, ]; - let tile_names = vec!["tile_0_0", "tile_1_0", "tile_0_1"]; + let tile_names = ["tile_0_0", "tile_1_0", "tile_0_1"]; let marlu_obs_ctx = MarluObsContext { sched_start_timestamp: Epoch::from_gpst_seconds(obsid as f64), diff --git a/src/io/write/mod.rs b/src/io/write/mod.rs index 2f1a8887..535b3295 100644 --- a/src/io/write/mod.rs +++ b/src/io/write/mod.rs @@ -548,6 +548,7 @@ fn can_write_to_file_inner(file: &Path) -> Result { match std::fs::OpenOptions::new() .write(true) .create(true) + .truncate(true) .open(file) .map_err(|e| e.kind()) { diff --git a/src/io/write/tests.rs b/src/io/write/tests.rs index fba2d371..da765c31 100644 --- a/src/io/write/tests.rs +++ b/src/io/write/tests.rs @@ -176,11 +176,10 @@ fn test_vis_output_no_time_averaging_no_gaps() { }); let result: Result, _> = data_handle.join(); - let result = match result { + match result { Err(_) | Ok(Err(_)) => result.map(|_| Ok(String::new())), Ok(Ok(())) => write_handle.join(), - }; - result + } }); match scoped_threads_result { @@ -379,11 +378,10 @@ fn test_vis_output_no_time_averaging_with_gaps() { }); let result: Result, _> = data_handle.join(); - let result = match result { + match result { Err(_) | Ok(Err(_)) => result.map(|_| Ok(String::new())), Ok(Ok(())) => write_handle.join(), - }; - result + } }); match scoped_threads_result { @@ -586,11 +584,10 @@ fn test_vis_output_time_averaging() { }); let result: Result, _> = data_handle.join(); - let result = match result { + match result { Err(_) | Ok(Err(_)) => result.map(|_| Ok(String::new())), Ok(Ok(())) => write_handle.join(), - }; - result + } }); match scoped_threads_result { diff --git a/src/math/tests.rs b/src/math/tests.rs index 4ae2dc3f..ec47df3f 100644 --- a/src/math/tests.rs +++ b/src/math/tests.rs @@ -48,23 +48,21 @@ fn test_tile_baseline_flags_without_flags() { assert_eq!(maps.tile_to_unflagged_cross_baseline_map[&(0, 1)], 0); assert_eq!(maps.tile_to_unflagged_cross_baseline_map[&(0, 127)], 126); assert_eq!(maps.tile_to_unflagged_cross_baseline_map[&(126, 127)], 8127); - assert!(maps + assert!(!maps .tile_to_unflagged_cross_baseline_map - .get(&(0, 0)) - .is_none()); + .contains_key(&(0, 0))); assert_eq!(maps.unflagged_cross_baseline_to_tile_map[&0], (0, 1)); assert_eq!(maps.unflagged_cross_baseline_to_tile_map[&8127], (126, 127)); - assert!(maps + assert!(!maps .unflagged_cross_baseline_to_tile_map - .get(&8128) - .is_none()); + .contains_key(&8128)); assert_eq!(maps.tile_to_unflagged_auto_index_map[&0], 0); assert_eq!(maps.tile_to_unflagged_auto_index_map[&127], 127); - assert!(maps.tile_to_unflagged_auto_index_map.get(&128).is_none()); + assert!(!maps.tile_to_unflagged_auto_index_map.contains_key(&128)); assert_eq!(maps.unflagged_auto_index_to_tile_map[&0], 0); assert_eq!(maps.unflagged_auto_index_to_tile_map[&127], 127); - assert!(maps.unflagged_auto_index_to_tile_map.get(&128).is_none()); + assert!(!maps.unflagged_auto_index_to_tile_map.contains_key(&128)); assert!(maps.flagged_tiles.is_empty()); @@ -84,24 +82,22 @@ fn test_tile_baseline_flags() { let maps = TileBaselineFlags::new(total_num_tiles, tile_flags); assert_eq!(maps.tile_to_unflagged_auto_index_map[&0], 0); assert_eq!(maps.tile_to_unflagged_auto_index_map[&2], 1); - assert!(maps.tile_to_unflagged_auto_index_map.get(&1).is_none()); - assert!(maps.tile_to_unflagged_auto_index_map.get(&128).is_none()); + assert!(!maps.tile_to_unflagged_auto_index_map.contains_key(&1)); + assert!(!maps.tile_to_unflagged_auto_index_map.contains_key(&128)); assert_eq!(maps.tile_to_unflagged_cross_baseline_map[&(0, 2)], 0); assert_eq!(maps.tile_to_unflagged_cross_baseline_map[&(0, 127)], 125); assert_eq!(maps.tile_to_unflagged_cross_baseline_map[&(2, 3)], 126); assert_eq!(maps.tile_to_unflagged_cross_baseline_map[&(126, 127)], 8000); - assert!(maps + assert!(!maps .tile_to_unflagged_cross_baseline_map - .get(&(0, 1)) - .is_none()); + .contains_key(&(0, 1))); assert_eq!(maps.unflagged_cross_baseline_to_tile_map[&0], (0, 2)); assert_eq!(maps.unflagged_cross_baseline_to_tile_map[&126], (2, 3)); assert_eq!(maps.unflagged_cross_baseline_to_tile_map[&8000], (126, 127)); - assert!(maps + assert!(!maps .unflagged_cross_baseline_to_tile_map - .get(&8001) - .is_none()); + .contains_key(&8001)); assert_eq!(maps.unflagged_auto_index_to_tile_map[&0], 0); assert_eq!(maps.unflagged_auto_index_to_tile_map[&1], 2); diff --git a/src/solutions/tests.rs b/src/solutions/tests.rs index 232f2b11..b8dc8e0c 100644 --- a/src/solutions/tests.rs +++ b/src/solutions/tests.rs @@ -106,7 +106,7 @@ fn test_write_and_read_hyperdrive_solutions() { // equality. sols.di_jones .into_iter() - .zip(sols_from_disk.di_jones.into_iter()) + .zip(sols_from_disk.di_jones) .for_each(|(expected, result)| { if expected.any_nan() { assert!(result.any_nan()); @@ -209,7 +209,7 @@ fn test_write_and_read_hyperdrive_solutions_no_metadata() { // equality. sols.di_jones .into_iter() - .zip(sols_from_disk.di_jones.into_iter()) + .zip(sols_from_disk.di_jones) .for_each(|(expected, result)| { if expected.any_nan() { assert!(result.any_nan()); @@ -285,7 +285,7 @@ fn test_write_and_read_ao_solutions() { // equality. sols.di_jones .into_iter() - .zip(sols_from_disk.di_jones.into_iter()) + .zip(sols_from_disk.di_jones) .for_each(|(expected, result)| { if expected.any_nan() { assert!(result.any_nan()); diff --git a/src/srclist/rts/read.rs b/src/srclist/rts/read.rs index 0979d8d9..25857865 100644 --- a/src/srclist/rts/read.rs +++ b/src/srclist/rts/read.rs @@ -46,7 +46,7 @@ pub(crate) fn parse_source_list( }; let float_to_int = |float: f64, line_num: u32| -> Result { - if float < 0.0 || float > std::u8::MAX as f64 { + if float < 0.0 || float > u8::MAX as f64 { Err(ReadSourceListCommonError::FloatToIntError { line_num, float }) } else { Ok(float as _) diff --git a/src/srclist/veto.rs b/src/srclist/veto.rs index 707a50f2..53eab071 100644 --- a/src/srclist/veto.rs +++ b/src/srclist/veto.rs @@ -63,7 +63,7 @@ pub(crate) fn veto_sources( // For this source, work out its smallest flux density at any of the // coarse channel frequencies. This is how we determine which // sources are "best". - let mut smallest_fd = std::f64::INFINITY; + let mut smallest_fd = f64::INFINITY; // Filter trivial sources: are any of this source's components too // low in elevation? Or too far from the phase centre? diff --git a/src/srclist/woden/read.rs b/src/srclist/woden/read.rs index f1a1298f..e1f61493 100644 --- a/src/srclist/woden/read.rs +++ b/src/srclist/woden/read.rs @@ -65,7 +65,7 @@ pub(crate) fn parse_source_list( }; let float_to_int = |float: f64, line_num: u32| -> Result { - if float < 0.0 || float > std::u32::MAX as f64 { + if float < 0.0 || float > u32::MAX as f64 { Err(ReadSourceListCommonError::FloatToIntError { line_num, float }) } else { Ok(float as u32)