Skip to content

Commit 08b8923

Browse files
committed
[assembler] Clippy: enable, fix enum_glob_use.
1 parent 0fd9cd7 commit 08b8923

File tree

7 files changed

+47
-52
lines changed

7 files changed

+47
-52
lines changed

assembler/src/asmlib/ast.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,14 +1213,15 @@ impl InstructionFragment {
12131213
implicit_symtab: &mut ImplicitSymbolTable,
12141214
rc_allocator: &mut R,
12151215
) -> Result<(), RcWordAllocationFailure> {
1216-
use InstructionFragment::*;
12171216
match self {
1218-
Null(_) | DeferredAddressing(_) => Ok(()),
1219-
Arithmetic(expr) => {
1217+
InstructionFragment::Null(_) | InstructionFragment::DeferredAddressing(_) => Ok(()),
1218+
InstructionFragment::Arithmetic(expr) => {
12201219
expr.allocate_rc_words(explicit_symtab, implicit_symtab, rc_allocator)
12211220
}
1222-
Config(cfg) => cfg.allocate_rc_words(explicit_symtab, implicit_symtab, rc_allocator),
1223-
PipeConstruct {
1221+
InstructionFragment::Config(cfg) => {
1222+
cfg.allocate_rc_words(explicit_symtab, implicit_symtab, rc_allocator)
1223+
}
1224+
InstructionFragment::PipeConstruct {
12241225
index: _,
12251226
rc_word_span,
12261227
rc_word_value,

assembler/src/asmlib/eval.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ impl Spanned for EvaluationFailure {
7979

8080
impl Display for EvaluationFailure {
8181
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), fmt::Error> {
82-
use EvaluationFailure::*;
8382
match self {
84-
SymbolDefinitionLoop {
83+
EvaluationFailure::SymbolDefinitionLoop {
8584
deps_in_order,
8685
span: _,
8786
} => {
@@ -93,16 +92,19 @@ impl Display for EvaluationFailure {
9392
names.join("->")
9493
)
9594
}
96-
FailedToAssignIndexRegister(ExhaustedIndexRegisters { name, .. }) => {
95+
EvaluationFailure::FailedToAssignIndexRegister(ExhaustedIndexRegisters {
96+
name,
97+
..
98+
}) => {
9799
write!(
98100
f,
99101
"unable to assign index register as the default value for symbol {name} because there are not enough index registers"
100102
)
101103
}
102-
BlockTooLarge(_span, mle) => {
104+
EvaluationFailure::BlockTooLarge(_span, mle) => {
103105
write!(f, "program block too large: {mle}")
104106
}
105-
HereIsNotAllowedHere(_) => {
107+
EvaluationFailure::HereIsNotAllowedHere(_) => {
106108
f.write_str("'#' (representing the current address) is not allowed here")
107109
}
108110
}
@@ -164,8 +166,6 @@ fn assign_default_value(
164166
name: &SymbolName,
165167
contexts_used: &SymbolContext,
166168
) -> Result<Unsigned36Bit, ExhaustedIndexRegisters> {
167-
use ConfigUse::*;
168-
use IndexUse::*;
169169
event!(
170170
Level::DEBUG,
171171
"assigning default value for {name} used in contexts {contexts_used:?}"
@@ -178,7 +178,7 @@ fn assign_default_value(
178178
)
179179
}
180180
OriginUse::NotOrigin { config, index } => match (config, index) {
181-
(NotConfig, NotIndex) => {
181+
(ConfigUse::NotConfig, IndexUse::NotIndex) => {
182182
if contexts_used.is_address() {
183183
// Values which refer to addresses (and which
184184
// therefore should point to a zero-initialised
@@ -193,8 +193,8 @@ fn assign_default_value(
193193
)
194194
}
195195
}
196-
(IncludesConfig, _) => Ok(Unsigned36Bit::ZERO),
197-
(NotConfig, IncludesIndex) => {
196+
(ConfigUse::IncludesConfig, _) => Ok(Unsigned36Bit::ZERO),
197+
(ConfigUse::NotConfig, IndexUse::IncludesIndex) => {
198198
// Index but not also configuration. Assign the next
199199
// index register.
200200
match index_register_assigner.assign_index_register() {

assembler/src/asmlib/lexer/lower.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,11 @@ impl<'a> LowerLexer<'a> {
104104

105105
pub(super) fn next(&mut self) -> Lexeme<'a> {
106106
use super::Token;
107-
use Lexeme::*;
108107

109108
loop {
110109
let tok = match self.inner.next() {
111110
None => {
112-
return EndOfInput;
111+
return Lexeme::EndOfInput;
113112
}
114113
Some(Result::Err(())) => {
115114
if self.state.in_comment {
@@ -136,7 +135,7 @@ impl<'a> LowerLexer<'a> {
136135
// symbols across a space. Per section 6-2.3 of
137136
// the User Handbook, tab is not allowed inside a
138137
// symex.
139-
return Tok(Token::Tab);
138+
return Lexeme::Tok(Token::Tab);
140139
}
141140
InnerToken::CommentStart => {
142141
self.state.in_comment = true;
@@ -150,7 +149,7 @@ impl<'a> LowerLexer<'a> {
150149
self.state.lbrace_count = self.state.lbrace_count.checked_add(1).expect(
151150
"the number of '{' on one line should be countable without overflow",
152151
);
153-
return Tok(Token::LeftBrace(Script::Normal));
152+
return Lexeme::Tok(Token::LeftBrace(Script::Normal));
154153
}
155154
InnerToken::RightBrace => {
156155
match self.state.lbrace_count.checked_sub(1) {
@@ -163,26 +162,26 @@ impl<'a> LowerLexer<'a> {
163162
// the comment text.
164163
continue;
165164
}
166-
return Tok(Token::RightBrace(Script::Normal));
165+
return Lexeme::Tok(Token::RightBrace(Script::Normal));
167166
}
168167
Some(reduced_count) => {
169168
self.state.lbrace_count = reduced_count;
170169
self.state.in_comment = false;
171-
return Tok(Token::RightBrace(Script::Normal));
170+
return Lexeme::Tok(Token::RightBrace(Script::Normal));
172171
}
173172
}
174173
}
175174
InnerToken::Newline => {
176175
self.state.lbrace_count = 0;
177176
self.state.in_comment = false;
178177
self.state.check_set_up_for_start_of_line();
179-
return Tok(Token::Newline);
178+
return Lexeme::Tok(Token::Newline);
180179
}
181180
InnerToken::Text => {
182181
if self.state.in_comment {
183182
continue;
184183
}
185-
return Text(self.inner.slice());
184+
return Lexeme::Text(self.inner.slice());
186185
}
187186
}
188187
}

assembler/src/asmlib/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#![warn(clippy::redundant_closure_for_method_calls)]
1616
#![warn(clippy::pedantic)]
1717
#![allow(clippy::verbose_bit_mask)] // because many of our types don't have trailing_zeros().
18-
#![allow(clippy::enum_glob_use)] // fix later
1918
#![allow(clippy::too_many_lines)] // fix later
2019
#![allow(clippy::explicit_into_iter_loop)] // fix later
2120
#![allow(clippy::default_trait_access)] // fix later

assembler/src/asmlib/parser.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,6 @@ pub(crate) fn instructions_with_comma_counts<I>(it: I) -> Vec<CommaDelimitedFrag
791791
where
792792
I: Iterator<Item = CommasOrInstruction>,
793793
{
794-
use CommasOrInstruction::*;
795794
/// Fold operation which estabishes an alternating pattern of
796795
/// commas and instructions.
797796
///
@@ -834,11 +833,11 @@ where
834833
acc.push(CommasOrInstruction::C(None));
835834
}
836835
},
837-
Some(I(_)) => unreachable!("invariant was broken"),
836+
Some(CommasOrInstruction::I(_)) => unreachable!("invariant was broken"),
838837
None => unreachable!("invariant was not established"),
839838
}
840-
assert!(matches!(acc.first(), Some(C(_))));
841-
assert!(matches!(acc.last(), Some(C(_))));
839+
assert!(matches!(acc.first(), Some(CommasOrInstruction::C(_))));
840+
assert!(matches!(acc.last(), Some(CommasOrInstruction::C(_))));
842841
acc
843842
}
844843

@@ -849,8 +848,8 @@ where
849848
None => {
850849
return Vec::new();
851850
}
852-
Some(I(_)) => None,
853-
Some(C(maybe_commas)) => {
851+
Some(CommasOrInstruction::I(_)) => None,
852+
Some(CommasOrInstruction::C(maybe_commas)) => {
854853
let c = maybe_commas.clone();
855854
it.next();
856855
c
@@ -868,7 +867,7 @@ where
868867
(None, _) => {
869868
break;
870869
}
871-
(Some(C(before_commas)), Some(I(inst))) => {
870+
(Some(CommasOrInstruction::C(before_commas)), Some(CommasOrInstruction::I(inst))) => {
872871
let after_commas: Option<Commas> = match it.peek() {
873872
Some(CommasOrInstruction::C(commas)) => commas.clone(),
874873
None => None,
@@ -882,11 +881,12 @@ where
882881
after_commas,
883882
));
884883
}
885-
(Some(C(_)), None) => {
884+
(Some(CommasOrInstruction::C(_)), None) => {
886885
// No instructions in the input.
887886
break;
888887
}
889-
(Some(I(_)), _) | (Some(C(_)), Some(C(_))) => {
888+
(Some(CommasOrInstruction::I(_)), _)
889+
| (Some(CommasOrInstruction::C(_)), Some(CommasOrInstruction::C(_))) => {
890890
unreachable!("fold_step did not maintain its invariant");
891891
}
892892
}

assembler/src/asmlib/symtab.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,9 @@ impl ImplicitDefinition {
360360

361361
impl Display for ImplicitDefinition {
362362
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
363-
use ImplicitDefinition::*;
364363
match self {
365-
Undefined(_context) => f.write_str("undefined"),
366-
DefaultAssigned(value, _) => {
364+
ImplicitDefinition::Undefined(_context) => f.write_str("undefined"),
365+
ImplicitDefinition::DefaultAssigned(value, _) => {
367366
write!(f, "default-assigned as {value}")
368367
}
369368
}
@@ -470,9 +469,8 @@ pub(super) fn record_undefined_symbol_or_return_failure(
470469
e: EvaluationFailure,
471470
undefined_symbols: &mut BTreeMap<SymbolName, ProgramError>,
472471
) -> Result<(), AssemblerFailure> {
473-
use EvaluationFailure::*;
474472
match e {
475-
SymbolDefinitionLoop {
473+
EvaluationFailure::SymbolDefinitionLoop {
476474
span,
477475
deps_in_order,
478476
..

assembler/src/asmlib/types.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -147,38 +147,36 @@ pub enum ProgramError {
147147

148148
impl Spanned for ProgramError {
149149
fn span(&self) -> Span {
150-
use ProgramError::*;
151150
match self {
152-
RcBlockTooLong(RcWordSource { span, .. })
153-
| FailedToAssignIndexRegister(span, _)
154-
| BlockTooLong(span, _)
155-
| InconsistentTag { span, .. }
156-
| SymbolDefinitionLoop { span, .. }
157-
| SyntaxError { span, .. } => *span,
151+
ProgramError::RcBlockTooLong(RcWordSource { span, .. })
152+
| ProgramError::FailedToAssignIndexRegister(span, _)
153+
| ProgramError::BlockTooLong(span, _)
154+
| ProgramError::InconsistentTag { span, .. }
155+
| ProgramError::SymbolDefinitionLoop { span, .. }
156+
| ProgramError::SyntaxError { span, .. } => *span,
158157
}
159158
}
160159
}
161160

162161
impl Display for ProgramError {
163162
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), fmt::Error> {
164-
use ProgramError::*;
165163
match self {
166-
RcBlockTooLong(RcWordSource { kind, .. }) => {
164+
ProgramError::RcBlockTooLong(RcWordSource { kind, .. }) => {
167165
write!(f, "RC-word block grew too long to allocate {kind}")
168166
}
169-
FailedToAssignIndexRegister(_span, symbol_name) => {
167+
ProgramError::FailedToAssignIndexRegister(_span, symbol_name) => {
170168
write!(
171169
f,
172170
"there are not enough index registers available to assign one for {symbol_name}"
173171
)
174172
}
175-
BlockTooLong(_span, mle) => {
173+
ProgramError::BlockTooLong(_span, mle) => {
176174
write!(f, "program block contains too many machine words: {mle}")
177175
}
178-
InconsistentTag { name, span: _, msg } => {
176+
ProgramError::InconsistentTag { name, span: _, msg } => {
179177
write!(f, "inconsistent definitions for tag {name}: {msg}")
180178
}
181-
SymbolDefinitionLoop {
179+
ProgramError::SymbolDefinitionLoop {
182180
symbol_names,
183181
span: _,
184182
} => {
@@ -195,7 +193,7 @@ impl Display for ProgramError {
195193
}
196194
Ok(())
197195
}
198-
SyntaxError { span: _, msg } => {
196+
ProgramError::SyntaxError { span: _, msg } => {
199197
write!(f, "{msg}")
200198
}
201199
}

0 commit comments

Comments
 (0)