Skip to content

Commit

Permalink
Fix some clippy issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
youngman-g committed Jul 14, 2024
1 parent 9d13ee5 commit a765600
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 66 deletions.
2 changes: 1 addition & 1 deletion assembler/src/asmlib/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Rich<'_, char>> = Vec::new();
let result: Result<(Option<SourceFile>, OutputOptions), AssemblerFailure> =
assemble_pass1(input, &mut errors);
Expand Down
2 changes: 1 addition & 1 deletion assembler/src/asmlib/driver/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
Expand Down
8 changes: 4 additions & 4 deletions assembler/src/asmlib/parser/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Display>(errors: &[Rich<'_, T>]) -> String {
let n = errors.len();
errors
.iter()
Expand Down Expand Up @@ -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.
Expand All @@ -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),
Expand All @@ -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),
Expand Down
14 changes: 6 additions & 8 deletions assembler/tests/hello-golden.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
Expand Down Expand Up @@ -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}")),
Expand Down
2 changes: 1 addition & 1 deletion base/src/collections/pq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
4 changes: 2 additions & 2 deletions base/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
20 changes: 10 additions & 10 deletions base/src/onescomplement/signed/tests18.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion base/src/onescomplement/signed/tests36.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
12 changes: 6 additions & 6 deletions base/src/onescomplement/signed/tests5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions base/src/onescomplement/signed/tests9.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions base/src/onescomplement/unsigned/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions base/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
19 changes: 6 additions & 13 deletions cpu/src/control/op_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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₁
Expand All @@ -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));
Expand All @@ -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());
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions cpu/src/control/op_loadstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -367,7 +366,7 @@ mod tests {
.memory_store_without_exchange(
ctx,
&mut mem,
&working_address,
working_address,
&mem_word,
&UpdateE::No,
&MetaBitChange::None,
Expand Down
4 changes: 2 additions & 2 deletions cpu/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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}");
Expand Down

0 comments on commit a765600

Please sign in to comment.