Fix some clippies

This commit is contained in:
Smaug123
2025-09-09 07:01:47 +01:00
parent a360a46d76
commit 6bb30cf015
6 changed files with 11 additions and 13 deletions

View File

@@ -69,9 +69,9 @@ fn write_json(data: &HaversineData, json_filename: &str) {
let mut is_first = true;
for point in data.pairs.iter() {
if !is_first {
writer.write_all(&[b',']).unwrap();
writer.write_all(b",").unwrap();
}
writer.write_all(&[b'{']).unwrap();
writer.write_all(b"{").unwrap();
writer
.write_all(
format!(
@@ -81,7 +81,7 @@ fn write_json(data: &HaversineData, json_filename: &str) {
.as_bytes(),
)
.unwrap();
writer.write_all(&[b'}']).unwrap();
writer.write_all(b"}").unwrap();
is_first = false;
}

View File

@@ -18,7 +18,7 @@ struct Args {
fn read_answer(binary_filename: &str) -> (Vec<f64>, f64) {
let mut file = File::open(binary_filename).unwrap();
let file_size = file.metadata().unwrap().len();
if file_size % 8 != 0 {
if !file_size.is_multiple_of(8) {
panic!(
"Malformed input file of size {} is not a multiple of 8",
file_size

View File

@@ -43,11 +43,10 @@ where
.filter(|i| !matches!(i, Instruction::Trivia(_)));
for i1 in without_trivia_1 {
if let Some(i2) = without_trivia_2.next() {
if i1 != i2 {
if let Some(i2) = without_trivia_2.next()
&& i1 != i2 {
return false;
}
}
}
if without_trivia_2.next().is_some() {

View File

@@ -111,12 +111,12 @@ impl EffectiveAddress {
if mode == 3 {
panic!("we don't handle this case, you need to do it manually to get a register")
}
let source_dest = if rm % 2 == 0 {
let source_dest = if rm.is_multiple_of(2) {
SourceDest::Source
} else {
SourceDest::Dest
};
let base = if (rm / 2) % 2 == 0 {
let base = if (rm / 2).is_multiple_of(2) {
Base::Bx
} else {
Base::Bp

View File

@@ -59,7 +59,7 @@ where
}
}
impl<'a> Instruction<&'a str> {
impl Instruction<&str> {
#[must_use]
pub fn to_bytes(&self) -> Vec<u8> {
match self {

View File

@@ -37,11 +37,10 @@ where
}
let mut labels = HashMap::new();
for (counter, instruction) in self.instructions.as_ref().iter().enumerate() {
if let Instruction::Trivia(TriviaInstruction::Label(s)) = instruction {
if let Some(s) = labels.insert(s.trim(), counter) {
if let Instruction::Trivia(TriviaInstruction::Label(s)) = instruction
&& let Some(s) = labels.insert(s.trim(), counter) {
panic!("same label twice: {}", s)
}
}
}
let mut instruction_boundaries = vec![0; self.instructions.as_ref().len()];