From a765600f0e89fd6de46194d032661ffca5fbc9b7 Mon Sep 17 00:00:00 2001 From: James Youngman Date: Sun, 14 Jul 2024 08:46:42 +0100 Subject: [PATCH] Fix some clippy issues. --- assembler/src/asmlib/driver.rs | 2 +- assembler/src/asmlib/driver/tests.rs | 2 +- assembler/src/asmlib/parser/tests.rs | 8 ++++---- assembler/tests/hello-golden.rs | 14 ++++++-------- base/src/collections/pq.rs | 2 +- base/src/instruction.rs | 4 ++-- base/src/onescomplement/signed/tests18.rs | 20 ++++++++++---------- base/src/onescomplement/signed/tests36.rs | 2 +- base/src/onescomplement/signed/tests5.rs | 12 ++++++------ base/src/onescomplement/signed/tests9.rs | 12 ++++++------ base/src/onescomplement/unsigned/tests.rs | 12 ++++++------ base/src/types.rs | 4 ++-- cpu/src/control/op_index.rs | 19 ++++++------------- cpu/src/control/op_loadstore.rs | 5 ++--- cpu/src/memory.rs | 4 ++-- 15 files changed, 56 insertions(+), 66 deletions(-) diff --git a/assembler/src/asmlib/driver.rs b/assembler/src/asmlib/driver.rs index 40dbd82..8ca66a4 100644 --- a/assembler/src/asmlib/driver.rs +++ b/assembler/src/asmlib/driver.rs @@ -153,7 +153,7 @@ fn assemble_pass1<'a>( /// This test helper is defined here so that we don't have to expose /// assemble_pass1, assemble_pass2. #[cfg(test)] -pub(crate) fn assemble_nonempty_valid_input<'a>(input: &'a str) -> (Directive, SymbolTable) { +pub(crate) fn assemble_nonempty_valid_input(input: &str) -> (Directive, SymbolTable) { let mut errors: Vec> = Vec::new(); let result: Result<(Option, OutputOptions), AssemblerFailure> = assemble_pass1(input, &mut errors); diff --git a/assembler/src/asmlib/driver/tests.rs b/assembler/src/asmlib/driver/tests.rs index 9711ed8..1c8a3e8 100644 --- a/assembler/src/asmlib/driver/tests.rs +++ b/assembler/src/asmlib/driver/tests.rs @@ -58,7 +58,7 @@ fn assemble_check_symbols(input: &str, target_address: Address, expected: &[(&st use crate::eval::HereValue; let (_directive, mut symtab) = assemble_nonempty_valid_input(input); - for (name, expected_value) in expected.into_iter() { + for (name, expected_value) in expected.iter() { let sym = SymbolName { canonical: name.to_string(), }; diff --git a/assembler/src/asmlib/parser/tests.rs b/assembler/src/asmlib/parser/tests.rs index 3f1305f..adbf70a 100644 --- a/assembler/src/asmlib/parser/tests.rs +++ b/assembler/src/asmlib/parser/tests.rs @@ -24,7 +24,7 @@ use super::super::symbol::SymbolName; use super::symex::{parse_multi_syllable_symex, parse_symex}; use super::*; -fn errors_as_string<'a, T: Display>(errors: &[Rich<'a, T>]) -> String { +fn errors_as_string(errors: &[Rich<'_, T>]) -> String { let n = errors.len(); errors .iter() @@ -736,7 +736,7 @@ fn assignment_of_literal(name: &str, assignment_span: Span, literal: LiteralValu #[test] fn test_assignment_literal() { - const INPUTS: &[(&'static str, usize)] = &[ + const INPUTS: &[(&str, usize)] = &[ ("FOO=2", 4), ("FOO =2", 5), ("F O O = 2", 8), // spaces are also allowed inside symexes. @@ -757,7 +757,7 @@ fn test_assignment_literal() { #[test] fn test_assignment_superscript() { - const INPUTS: &[(&'static str, usize, usize)] = &[ + const INPUTS: &[(&str, usize, usize)] = &[ // Unicode code point B2 is a superscript 2. ("FOO=\u{00B2}", 4, 6), ("FOO =\u{00B2}", 5, 7), @@ -778,7 +778,7 @@ fn test_assignment_superscript() { #[test] fn test_assignment_subscript() { - const INPUTS: &[(&'static str, usize, usize)] = &[ + const INPUTS: &[(&str, usize, usize)] = &[ // Unicode code point 2083 is a subscript 3. ("FOO=\u{2083}", 4, 7), ("FOO =\u{2083}", 5, 8), diff --git a/assembler/tests/hello-golden.rs b/assembler/tests/hello-golden.rs index c543653..6009c7d 100644 --- a/assembler/tests/hello-golden.rs +++ b/assembler/tests/hello-golden.rs @@ -3,8 +3,6 @@ use std::fs::{File, OpenOptions}; use std::io::{BufWriter, Read, Write}; use std::path::{Path, PathBuf}; -use tempfile; - use assembler::*; fn get_test_input_file_name(relative_to_manifest: &str) -> PathBuf { @@ -31,11 +29,11 @@ fn get_temp_output_file_name() -> tempfile::TempPath { fn files_are_identical(expected: &OsStr, got: &OsStr) -> Result<(), String> { fn must_open(name: &OsStr) -> File { - File::open(name).expect(&format!("should be able to open test file {name:?}")) + File::open(name).unwrap_or_else(|_| panic!("should be able to open test file {name:?}")) } - let expected_file = must_open(&expected); - let got_file = must_open(&got); + let expected_file = must_open(expected); + let got_file = must_open(got); const COMPLAIN: &str = "should be able to obtain file size"; let expected_file_len = expected_file.metadata().expect(COMPLAIN).len(); let got_file_len = got_file.metadata().expect(COMPLAIN).len(); @@ -97,15 +95,15 @@ fn assembler_golden_output_test( let input = get_test_input_file_name(input_relative_path); let golden = get_test_input_file_name(golden_output_relative_path); let actual_output = get_temp_output_file_name(); - fill_output_file_with_garbage(&actual_output.to_path_buf()); - match assemble_file(input.as_os_str(), &actual_output.to_path_buf()) { + fill_output_file_with_garbage(&actual_output); + match assemble_file(input.as_os_str(), &actual_output) { Ok(()) => match files_are_identical(golden.as_os_str(), actual_output.as_os_str()) { Ok(()) => Ok(()), Err(e) => Err(format!( "{} and {} are not identical: {}", golden.display(), actual_output.display(), - e.to_string() + e )), }, Err(e) => Err(format!("failed to assemble {input_relative_path}: {e}")), diff --git a/base/src/collections/pq.rs b/base/src/collections/pq.rs index 0272325..841f4b0 100644 --- a/base/src/collections/pq.rs +++ b/base/src/collections/pq.rs @@ -45,7 +45,7 @@ fn test_reverse_order() { assert_ne!(ReverseOrdered::from(1), ReverseOrdered::from(0)); assert!(ReverseOrdered::from(1) < ReverseOrdered::from(0)); assert_ne!(ReverseOrdered::from(1), ReverseOrdered::from(0)); - assert!(!(ReverseOrdered::from(1) > ReverseOrdered::from(0))); + assert!(ReverseOrdered::from(1) <= ReverseOrdered::from(0)); } pub struct KeyedReversePriorityQueueUnknownKeyError {} diff --git a/base/src/instruction.rs b/base/src/instruction.rs index 55e85da..b64459c 100644 --- a/base/src/instruction.rs +++ b/base/src/instruction.rs @@ -554,11 +554,11 @@ mod tests { OperandAddress::Direct(addr(0o0377750_u32)), "wrong address" ); - assert_eq!(inst.is_deferred_addressing(), false, "wrong dismis"); + assert!(!inst.is_deferred_addressing(), "wrong dismiss"); assert_eq!(inst.index_address(), 0, "wrong index"); assert_eq!(inst.opcode_number(), 5, "wrong opcode"); assert!(inst.configuration().is_zero(), "wrong cf"); - assert_eq!(inst.is_held(), false, "wrong held"); + assert!(!inst.is_held(), "wrong held"); } #[test] diff --git a/base/src/onescomplement/signed/tests18.rs b/base/src/onescomplement/signed/tests18.rs index 637a169..b7e3114 100644 --- a/base/src/onescomplement/signed/tests18.rs +++ b/base/src/onescomplement/signed/tests18.rs @@ -19,8 +19,8 @@ macro_rules! assert_octal_eq { fn test_signed18_max_value() { assert_eq!(u64::try_from(Signed18Bit::MAX), Ok(0o377_777_u64)); assert_eq!(u32::try_from(Signed18Bit::MAX), Ok(0o377_777_u32)); - assert_eq!(i64::from(Signed18Bit::MAX), 0o377_777 as i64); - assert_eq!(i32::from(Signed18Bit::MAX), 0o377_777 as i32); + assert_eq!(i64::from(Signed18Bit::MAX), 0o377_777_i64); + assert_eq!(i32::from(Signed18Bit::MAX), 0o377_777_i32); } #[test] @@ -31,8 +31,8 @@ fn test_signed18_max_range() { #[test] fn test_signed18_min_value() { - assert_eq!(i64::from(Signed18Bit::MIN), -(0o377_777 as i64)); - assert_eq!(i32::from(Signed18Bit::MIN), -(0o377_777 as i32)); + assert_eq!(i64::from(Signed18Bit::MIN), -0o377_777_i64); + assert_eq!(i32::from(Signed18Bit::MIN), -0o377_777_i32); } #[test] @@ -352,14 +352,14 @@ fn test_from_signed18bit_to_u16() { #[test] fn test_signed18bit_ord() { assert!(Signed18Bit::ZERO < Signed18Bit::ONE); - assert!(!(Signed18Bit::ONE < Signed18Bit::ZERO)); - assert!(!(Signed18Bit::ZERO < Signed18Bit::ZERO)); - assert!(!(Signed18Bit::ONE < Signed18Bit::ONE)); + assert!(Signed18Bit::ONE >= Signed18Bit::ZERO); + assert!(Signed18Bit::ZERO >= Signed18Bit::ZERO); + assert!(Signed18Bit::ONE >= Signed18Bit::ONE); assert!(Signed18Bit::ONE > Signed18Bit::ZERO); - assert!(!(Signed18Bit::ZERO > Signed18Bit::ZERO)); - assert!(!(Signed18Bit::ONE > Signed18Bit::ONE)); - assert!(!(Signed18Bit::ZERO > Signed18Bit::ONE)); + assert!(Signed18Bit::ZERO <= Signed18Bit::ZERO); + assert!(Signed18Bit::ONE <= Signed18Bit::ONE); + assert!(Signed18Bit::ZERO <= Signed18Bit::ONE); assert!(Signed18Bit::MIN < Signed18Bit::MAX); assert!(Signed18Bit::MAX > Signed18Bit::MIN); diff --git a/base/src/onescomplement/signed/tests36.rs b/base/src/onescomplement/signed/tests36.rs index 9c9079e..5855e48 100644 --- a/base/src/onescomplement/signed/tests36.rs +++ b/base/src/onescomplement/signed/tests36.rs @@ -123,7 +123,7 @@ fn test_i64_round_tripping() { assert!(input <= -(1_i64 << 35)); } Ok(x) => { - let result: i64 = x.try_into().expect("round-trip should work"); + let result: i64 = x.into(); assert_octal_eq!(input, result); } } diff --git a/base/src/onescomplement/signed/tests5.rs b/base/src/onescomplement/signed/tests5.rs index aec34a7..3c86462 100644 --- a/base/src/onescomplement/signed/tests5.rs +++ b/base/src/onescomplement/signed/tests5.rs @@ -34,14 +34,14 @@ fn test_signed5bit_ord() { let zero: Signed5Bit = Signed5Bit::try_from(0_i8).unwrap(); let one: Signed5Bit = Signed5Bit::try_from(1_i8).unwrap(); assert!(zero < one); - assert!(!(one < zero)); - assert!(!(zero < zero)); - assert!(!(one < one)); + assert!(one >= zero); + assert!(zero >= zero); + assert!(one >= one); assert!(one > zero); - assert!(!(zero > zero)); - assert!(!(one > one)); - assert!(!(zero > one)); + assert!(zero <= zero); + assert!(one <= one); + assert!(zero <= one); assert!(Signed5Bit::MIN < Signed5Bit::MAX); assert!(Signed5Bit::MAX > Signed5Bit::MIN); diff --git a/base/src/onescomplement/signed/tests9.rs b/base/src/onescomplement/signed/tests9.rs index a0f9561..6a2a78f 100644 --- a/base/src/onescomplement/signed/tests9.rs +++ b/base/src/onescomplement/signed/tests9.rs @@ -204,14 +204,14 @@ fn test_signed9bit_ord() { let zero: Signed9Bit = Signed9Bit::from(0_i8); let one: Signed9Bit = Signed9Bit::from(1_i8); assert!(zero < one); - assert!(!(one < zero)); - assert!(!(zero < zero)); - assert!(!(one < one)); + assert!(one >= zero); + assert!(zero >= zero); + assert!(one >= one); assert!(one > zero); - assert!(!(zero > zero)); - assert!(!(one > one)); - assert!(!(zero > one)); + assert!(zero <= zero); + assert!(one <= one); + assert!(zero <= one); assert!(Signed9Bit::MIN < Signed9Bit::MAX); assert!(Signed9Bit::MAX > Signed9Bit::MIN); diff --git a/base/src/onescomplement/unsigned/tests.rs b/base/src/onescomplement/unsigned/tests.rs index e88cf00..0bb6d2b 100644 --- a/base/src/onescomplement/unsigned/tests.rs +++ b/base/src/onescomplement/unsigned/tests.rs @@ -214,14 +214,14 @@ fn test_unsigned9bit_ord() { let zero: Unsigned9Bit = Unsigned9Bit::from(0_u8); let one: Unsigned9Bit = Unsigned9Bit::from(1_u8); assert!(zero < one); - assert!(!(one < zero)); - assert!(!(zero < zero)); - assert!(!(one < one)); + assert!(one >= zero); + assert!(zero >= zero); + assert!(one >= one); assert!(one > zero); - assert!(!(zero > zero)); - assert!(!(one > one)); - assert!(!(zero > one)); + assert!(zero <= zero); + assert!(one <= one); + assert!(zero <= one); assert!(Unsigned9Bit::MIN < Unsigned9Bit::MAX); assert!(Unsigned9Bit::MAX > Unsigned9Bit::MIN); diff --git a/base/src/types.rs b/base/src/types.rs index a568379..c4a8477 100644 --- a/base/src/types.rs +++ b/base/src/types.rs @@ -316,8 +316,8 @@ fn test_sequence_numnber() { assert!(ZERO < ONE); assert_eq!(ONE, ONE); assert_eq!(ZERO, ZERO); - assert!(!(ONE == ZERO)); - assert!(!(ZERO == ONE)); + assert!(ONE != ZERO); + assert!(ZERO != ONE); // When SequenceNumber is Unsigned6Bit, SequenceNumber::MAX should be 0o77. // assert_eq!(SequenceNumber::MAX, SequenceNumber::try_from(0o77_u8).unwrap()); diff --git a/cpu/src/control/op_index.rs b/cpu/src/control/op_index.rs index f424fd3..6cc88de 100644 --- a/cpu/src/control/op_index.rs +++ b/cpu/src/control/op_index.rs @@ -427,7 +427,7 @@ mod tests { Signed18Bit::ZERO, &[Unsigned36Bit::ONE], false, - Some(&vec![(1usize, SystemConfiguration::from(0_u8))]), + Some(&[(1usize, SystemConfiguration::from(0_u8))]), 1, ); assert_eq!(sum, Signed18Bit::ONE); @@ -439,15 +439,8 @@ mod tests { fn op_aux_negative() { const COMPLAIN: &str = "failed to set up AUX test data"; let context = make_ctx(); - let minus_three = Signed36Bit::try_from(-3) - .expect(COMPLAIN) - .reinterpret_as_unsigned(); - let items_to_add = [ - Signed36Bit::try_from(-1) - .expect(COMPLAIN) - .reinterpret_as_unsigned(), - minus_three, - ]; + let minus_three = Signed36Bit::from(-3).reinterpret_as_unsigned(); + let items_to_add = [Signed36Bit::from(-1).reinterpret_as_unsigned(), minus_three]; let (sum, e) = simulate_aux( &context, Unsigned6Bit::ONE, // Use register X₁ @@ -457,7 +450,7 @@ mod tests { // System configuration 0o340 uses only the right-hand // subword, which is how AUX behaves anyway - so this // should make no difference. - Some(&vec![(1usize, SystemConfiguration::from(0o340_u8))]), + Some(&[(1usize, SystemConfiguration::from(0o340_u8))]), 1usize, ); assert_eq!(sum, Signed18Bit::try_from(0o250073).expect(COMPLAIN)); @@ -475,7 +468,7 @@ mod tests { u18!(0o000_111).reinterpret_as_signed(), &[u36!(0o444_000_222_010)], false, - Some(&vec![(1usize, SystemConfiguration::from(0_u8))]), + Some(&[(1usize, SystemConfiguration::from(0_u8))]), 1, ); assert_eq!(sum, u18!(0o222_121).reinterpret_as_signed()); @@ -621,7 +614,7 @@ mod tests { u18!(0o300_555).reinterpret_as_signed(), // initial value &[u36!(0o020_010)], false, - Some(&vec![(1usize, SystemConfiguration::from(u9!(0o750)))]), // 0o750: q2 only + Some(&[(1usize, SystemConfiguration::from(u9!(0o750)))]), // 0o750: q2 only 1usize, ); // The sum should be formed from q2 of the initial value diff --git a/cpu/src/control/op_loadstore.rs b/cpu/src/control/op_loadstore.rs index 6034d7f..482a309 100644 --- a/cpu/src/control/op_loadstore.rs +++ b/cpu/src/control/op_loadstore.rs @@ -285,8 +285,7 @@ mod tests { let base: Signed18Bit = final_operand_address .reinterpret_as_signed() .checked_sub(defer_index.unwrap_or(Signed18Bit::ZERO)) - .map(|x| x.checked_sub(xj)) - .flatten() + .and_then(|x| x.checked_sub(xj)) .expect("test data caused arithmetic overflow"); let defer: Unsigned36Bit = join_halves( defer_index.unwrap_or_default().reinterpret_as_unsigned(), @@ -367,7 +366,7 @@ mod tests { .memory_store_without_exchange( ctx, &mut mem, - &working_address, + working_address, &mem_word, &UpdateE::No, &MetaBitChange::None, diff --git a/cpu/src/memory.rs b/cpu/src/memory.rs index ae51666..72e5840 100644 --- a/cpu/src/memory.rs +++ b/cpu/src/memory.rs @@ -1210,7 +1210,7 @@ fn test_ae_registers_share_metabit() { let ae_regs = [a_addr, b_addr, c_addr, d_addr, e_addr]; fn set_metabit(context: &Context, mem: &mut MemoryUnit, addr: Address, value: bool) { - match mem.write_access(&context, &addr) { + match mem.write_access(context, &addr) { Ok(Some(mut word)) => word.set_meta_bit_to_value(value), Ok(None) => { panic!("AE register at {addr:o} is not mapped"); @@ -1222,7 +1222,7 @@ fn test_ae_registers_share_metabit() { } fn get_metabit(context: &Context, mem: &mut MemoryUnit, addr: Address) -> bool { - match mem.read_access(&context, &addr) { + match mem.read_access(context, &addr) { Ok(word) => word.get_meta_bit(), Err(e) => { panic!("failed to read memory at {addr:o}: {e}");