Skip to content

Commit 3c9be21

Browse files
committed
Fix some clippy complaints (having updated clippy).
1 parent 417d1b8 commit 3c9be21

File tree

11 files changed

+97
-126
lines changed

11 files changed

+97
-126
lines changed

assembler/src/asmlib/collections.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<T> OneOrMore<T> {
4747
self.tail.push(item);
4848
}
4949

50-
pub fn iter(&self) -> OneOrMoreIter<T> {
50+
pub fn iter(&self) -> OneOrMoreIter<'_, T> {
5151
OneOrMoreIter {
5252
inner: std::iter::once(&self.head).chain(self.tail.iter()),
5353
}
@@ -60,7 +60,7 @@ impl<T> OneOrMore<T> {
6060
}
6161
}
6262

63-
pub fn iter_mut(&mut self) -> OneOrMoreIterMut<T> {
63+
pub fn iter_mut(&mut self) -> OneOrMoreIterMut<'_, T> {
6464
OneOrMoreIterMut {
6565
inner: std::iter::once(&mut self.head).chain(self.tail.iter_mut()),
6666
}

assembler/src/asmlib/driver.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ fn assemble_pass1<'a, 'b: 'a>(
9191
let (mut sf, mut new_errors) = parse_source_file(source_file_body.as_str(), setup);
9292
errors.append(&mut new_errors);
9393

94-
if let Some(source_file) = sf.as_mut() {
95-
if let Err(tag_errors) = source_file.build_local_symbol_tables() {
96-
errors.extend(
97-
tag_errors
98-
.into_iter()
99-
.map(|tag_err| Rich::custom(tag_err.span(), tag_err.to_string())),
100-
);
101-
}
94+
if let Some(source_file) = sf.as_mut()
95+
&& let Err(tag_errors) = source_file.build_local_symbol_tables()
96+
{
97+
errors.extend(
98+
tag_errors
99+
.into_iter()
100+
.map(|tag_err| Rich::custom(tag_err.span(), tag_err.to_string())),
101+
);
102102
}
103103
Ok((sf, options))
104104
}
@@ -298,10 +298,10 @@ fn initial_symbol_table<'a>(
298298
for r in source_file.global_symbol_references() {
299299
match r {
300300
Ok((symbol, span, context)) => {
301-
if !explicit_symbols.is_defined(&symbol) {
302-
if let Err(e) = implicit_symbols.record_usage_context(symbol.clone(), context) {
303-
errors.push(Rich::custom(span, e.to_string()));
304-
}
301+
if !explicit_symbols.is_defined(&symbol)
302+
&& let Err(e) = implicit_symbols.record_usage_context(symbol.clone(), context)
303+
{
304+
errors.push(Rich::custom(span, e.to_string()));
305305
}
306306
}
307307
Err(e) => {
@@ -461,15 +461,15 @@ fn assemble_pass3(
461461
let mut bad_symbol_definitions: BTreeMap<SymbolName, ProgramError> = Default::default();
462462
// TODO: consider moving this into pass 2.
463463
for block in blocks.values() {
464-
if let Some(Origin::Symbolic(span, symbol_name)) = block.origin.as_ref() {
465-
if !explicit_symtab.is_defined(symbol_name) {
466-
final_symbols.define_if_undefined(
467-
symbol_name.clone(),
468-
FinalSymbolType::Tag, // actually origin
469-
body.extract(span.start..span.end).to_string(),
470-
FinalSymbolDefinition::PositionIndependent(block.location.into()),
471-
);
472-
}
464+
if let Some(Origin::Symbolic(span, symbol_name)) = block.origin.as_ref()
465+
&& !explicit_symtab.is_defined(symbol_name)
466+
{
467+
final_symbols.define_if_undefined(
468+
symbol_name.clone(),
469+
FinalSymbolType::Tag, // actually origin
470+
body.extract(span.start..span.end).to_string(),
471+
FinalSymbolDefinition::PositionIndependent(block.location.into()),
472+
);
473473
}
474474
}
475475

assembler/src/asmlib/driver/tests.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,7 @@ fn test_super_hash_value() {
260260
#[test]
261261
fn test_sub_hash_value() {
262262
// Given a program which assembles at address 1 the value of # ("here"), when we assemble it
263-
let program =
264-
assemble_source(concat!("1| @sub_hash@\n",), Default::default()).expect("program is valid");
263+
let program = assemble_source("1| @sub_hash@\n", Default::default()).expect("program is valid");
265264

266265
// Then we should see that # evaluates as 1, the address of the
267266
// insruction containing it.

assembler/src/asmlib/manuscript.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,10 @@ impl ManuscriptBlock {
417417
if let Some(origin) = self.origin.as_ref() {
418418
origin.span()
419419
} else {
420-
if let Some(s) = self.sequences.first() {
421-
if let Some(first) = s.first() {
422-
return first.span();
423-
}
420+
if let Some(s) = self.sequences.first()
421+
&& let Some(first) = s.first()
422+
{
423+
return first.span();
424424
}
425425
Span::from(0..0)
426426
}

assembler/src/asmlib/span.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl Ord for OrderableSpan {
2828

2929
impl PartialOrd for OrderableSpan {
3030
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
31-
Some(self.0.start.cmp(&other.0.start))
31+
Some(self.cmp(other))
3232
}
3333
}
3434

assembler/src/asmlib/symbol.rs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::BTreeSet;
22
use std::error::Error;
3-
use std::fmt::{self, Debug, Display, Formatter, Write};
3+
use std::fmt::{self, Debug, Display, Formatter};
44
use std::hash::{Hash, Hasher};
55

66
use base::charset::Script;
@@ -54,32 +54,6 @@ impl Hash for SymbolName {
5454
}
5555
}
5656

57-
#[derive(Clone, Eq, PartialOrd, Ord, PartialEq, Debug)]
58-
pub(crate) enum SymbolOrHere {
59-
Named(SymbolName),
60-
Here,
61-
}
62-
63-
impl From<&str> for SymbolOrHere {
64-
fn from(value: &str) -> Self {
65-
match value {
66-
"#" => SymbolOrHere::Here,
67-
name => SymbolOrHere::Named(SymbolName {
68-
canonical: name.to_owned(),
69-
}),
70-
}
71-
}
72-
}
73-
74-
impl Display for SymbolOrHere {
75-
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
76-
match self {
77-
SymbolOrHere::Named(name) => write!(f, "{name}"),
78-
SymbolOrHere::Here => f.write_char('#'),
79-
}
80-
}
81-
}
82-
8357
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
8458
pub(crate) enum ConfigOrIndexUsage {
8559
Configuration,

assembler/src/asmlib/symtab.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -425,25 +425,25 @@ pub(super) fn assign_default_rc_word_tags<R: RcAllocator>(
425425
final_symbols: &mut FinalSymbolTable,
426426
) -> Result<(), RcWordAllocationFailure> {
427427
for (name, def) in implicit_symtab.definitions.iter_mut() {
428-
if let ImplicitDefinition::Undefined(context) = def {
429-
if context.requires_rc_word_allocation() {
430-
let span: Span = *context.any_span();
431-
let value = Unsigned36Bit::ZERO;
432-
let addr = rcblock.allocate(
433-
RcWordSource {
434-
span,
435-
kind: RcWordKind::DefaultAssignment,
436-
},
437-
value,
438-
)?;
439-
final_symbols.define(
440-
name.clone(),
441-
FinalSymbolType::Equality,
442-
value.to_string(),
443-
FinalSymbolDefinition::PositionIndependent(value),
444-
);
445-
*def = ImplicitDefinition::DefaultAssigned(addr.into(), context.clone());
446-
}
428+
if let ImplicitDefinition::Undefined(context) = def
429+
&& context.requires_rc_word_allocation()
430+
{
431+
let span: Span = *context.any_span();
432+
let value = Unsigned36Bit::ZERO;
433+
let addr = rcblock.allocate(
434+
RcWordSource {
435+
span,
436+
kind: RcWordKind::DefaultAssignment,
437+
},
438+
value,
439+
)?;
440+
final_symbols.define(
441+
name.clone(),
442+
FinalSymbolType::Equality,
443+
value.to_string(),
444+
FinalSymbolDefinition::PositionIndependent(value),
445+
);
446+
*def = ImplicitDefinition::DefaultAssigned(addr.into(), context.clone());
447447
}
448448
}
449449
Ok(())

assembler/src/tx2maketape/main.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,9 @@ fn read_binary(input_file: File) -> Result<Binary, Fail> {
145145
Some(expected) => expected != addr,
146146
};
147147

148-
if non_contiuguous {
149-
if let Some(old) = chunk.take() {
150-
assert!(!old.is_empty());
151-
binary.add_chunk(old);
152-
}
148+
if non_contiuguous && let Some(old) = chunk.take() {
149+
assert!(!old.is_empty());
150+
binary.add_chunk(old);
153151
}
154152
let ch: &mut BinaryChunk = chunk.get_or_insert_with(|| BinaryChunk {
155153
address: Address::from(addr),
@@ -158,10 +156,10 @@ fn read_binary(input_file: File) -> Result<Binary, Fail> {
158156
prev_addr = Some(addr);
159157
ch.push(word);
160158
}
161-
if let Some(current) = chunk.take() {
162-
if !current.is_empty() {
163-
binary.add_chunk(current);
164-
}
159+
if let Some(current) = chunk.take()
160+
&& !current.is_empty()
161+
{
162+
binary.add_chunk(current);
165163
}
166164
Ok(binary)
167165
}

cli/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,10 @@ fn run_simulator() -> Result<(), Box<dyn std::error::Error>> {
312312
};
313313
let initial_context = clk.make_fresh_context();
314314
let mut tx2 = Tx2::new(&initial_context, panic_on_unmasked_alarm, &mem_config);
315-
if let Some(tape) = tape_data {
316-
if let Err(e) = tx2.mount_tape(&initial_context, tape) {
317-
return Err(Box::new(e));
318-
}
315+
if let Some(tape) = tape_data
316+
&& let Err(e) = tx2.mount_tape(&initial_context, tape)
317+
{
318+
return Err(Box::new(e));
319319
}
320320
run(&mut tx2, &mut clk, sleep_multiplier)
321321
}

cpu/src/io/dev_petr.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -245,19 +245,19 @@ impl Petr {
245245
);
246246
match self.activity {
247247
Activity::Started => {
248-
if let Some(t) = self.time_of_next_read {
249-
if t > *system_time {
250-
// The next line has not yet appeared under the read
251-
// head.
252-
let to_wait = || t - *system_time;
253-
event!(
254-
Level::TRACE,
255-
"motor running ({}) but next line will not be read for {:?} yet",
256-
self.direction,
257-
to_wait()
258-
);
259-
return;
260-
}
248+
if let Some(t) = self.time_of_next_read
249+
&& t > *system_time
250+
{
251+
// The next line has not yet appeared under the read
252+
// head.
253+
let to_wait = || t - *system_time;
254+
event!(
255+
Level::TRACE,
256+
"motor running ({}) but next line will not be read for {:?} yet",
257+
self.direction,
258+
to_wait()
259+
);
260+
return;
261261
}
262262
match self.direction {
263263
Direction::Bin => {
@@ -304,21 +304,21 @@ fn compute_throughput(
304304
connect_time: Option<Duration>,
305305
now: Duration,
306306
) -> Option<Throughput> {
307-
if let Some(connected_at) = connect_time {
308-
if let Some(elapsed) = now.checked_sub(connected_at) {
309-
let elapsed = elapsed.as_secs_f64();
307+
if let Some(connected_at) = connect_time
308+
&& let Some(elapsed) = now.checked_sub(connected_at)
309+
{
310+
let elapsed = elapsed.as_secs_f64();
310311

311-
// It seems that in a WASM build, f64::value_from(usize)
312-
// is irrefutable. But clippy doesn't warn about it in
313-
// non-WASM builds because it's not always irrefutable.
314-
#[allow(irrefutable_let_patterns)]
315-
if let Ok(n) = f64::value_from(pos) {
316-
let throughput = n / elapsed;
317-
return Some(Throughput {
318-
lines_per_second: throughput,
319-
total_seconds: elapsed,
320-
});
321-
}
312+
// It seems that in a WASM build, f64::value_from(usize)
313+
// is irrefutable. But clippy doesn't warn about it in
314+
// non-WASM builds because it's not always irrefutable.
315+
#[allow(irrefutable_let_patterns)]
316+
if let Ok(n) = f64::value_from(pos) {
317+
let throughput = n / elapsed;
318+
return Some(Throughput {
319+
lines_per_second: throughput,
320+
total_seconds: elapsed,
321+
});
322322
}
323323
}
324324
None

0 commit comments

Comments
 (0)