Skip to content

Commit 0ada67f

Browse files
committed
Fix clippy warnings
1 parent 1fa8ec0 commit 0ada67f

File tree

20 files changed

+126
-91
lines changed

20 files changed

+126
-91
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ jobs:
2323
run: sudo apt-get install nasm
2424

2525
- name: Setup Rust
26-
run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
26+
run: |
27+
rustup update ${{ matrix.toolchain }}
28+
rustup default ${{ matrix.toolchain }}
29+
rustup component add clippy
2730
2831
- name: Compile
2932
run: |
@@ -34,3 +37,8 @@ jobs:
3437
run: |
3538
cd tiger
3639
cargo test
40+
41+
- name: Clippy
42+
run: |
43+
cd tiger
44+
cargo clippy --all-targets -- -D warnings

tiger/src/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use position::WithPos;
2323
use symbol::{Symbol, SymbolWithPos};
2424
use temp::Label;
2525

26+
#[allow(clippy::enum_variant_names)]
2627
#[derive(Clone, Debug, PartialEq)]
2728
pub enum Declaration {
2829
ClassDeclaration {

tiger/src/canon.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub fn basic_blocks(statements: Vec<Statement>) -> (Vec<Vec<Statement>>, Label)
101101

102102
pub fn trace_schedule(mut basic_blocks: Vec<Vec<Statement>>, done_label: Label) -> Vec<Statement> {
103103
let mut label_mapping = HashMap::new();
104-
label_mapping.insert(&done_label, usize::max_value());
104+
label_mapping.insert(&done_label, usize::MAX);
105105
for (index, basic_block) in basic_blocks.iter().enumerate() {
106106
match basic_block.first().expect("at least one statement in basic block").statement {
107107
_Statement::Label(ref label) => {
@@ -149,7 +149,7 @@ pub fn trace_schedule(mut basic_blocks: Vec<Vec<Statement>>, done_label: Label)
149149

150150
for trace in traces {
151151
for index in trace {
152-
let trace_statements = mem::replace(&mut basic_blocks[index], vec![]);
152+
let trace_statements = mem::take(&mut basic_blocks[index]);
153153
for statement in trace_statements {
154154
statements.push_back(statement);
155155
}
@@ -212,7 +212,7 @@ pub fn trace_schedule(mut basic_blocks: Vec<Vec<Statement>>, done_label: Label)
212212
match expr {
213213
Exp::Name(label) => {
214214
if labels.len() == 1 && labels[0] == label {
215-
if let Some(ref statement) = statements.front() {
215+
if let Some(statement) = statements.front() {
216216
if let _Statement::Label(ref next_label) = statement.statement {
217217
if next_label == &label {
218218
// Remove unconditional jumps to next statement.

tiger/src/escape.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl EscapeFinder {
128128
self.visit_exp(test, depth);
129129
self.visit_exp(then, depth);
130130
if let Some(ref else_) = *else_ {
131-
self.visit_exp(&else_, depth);
131+
self.visit_exp(else_, depth);
132132
}
133133
},
134134
Expr::Int { .. } => (),

tiger/src/flow.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ pub struct Node {
3333
pub stack_uses: BTreeSet<i64>,
3434
pub uses: BTreeSet<Temp>,
3535
pub return_label: Option<Label>,
36-
pub is_move: bool,
36+
// TODO: This field is unused. Check out if it's really not needed.
37+
//pub is_move: bool,
3738
}
3839

3940
pub struct FlowGraph {
@@ -53,6 +54,7 @@ struct GraphBuilder<'a> {
5354
visited: HashMap<usize, Entry>,
5455
}
5556

57+
#[allow(clippy::needless_lifetimes)]
5658
impl<'a> GraphBuilder<'a> {
5759
fn build(&mut self, current_index: usize, predecessor: Option<Entry>) {
5860
if let Some(&entry) = self.visited.get(&current_index) {
@@ -68,11 +70,12 @@ impl<'a> GraphBuilder<'a> {
6870
Instruction::Call { ref return_label, .. } => Some(return_label.clone()),
6971
_ => None,
7072
};
71-
let is_move =
73+
// TODO: This is unused. Check out if it's really not needed.
74+
/*let is_move =
7275
match *instruction {
7376
Instruction::Move { .. } => true,
7477
_ => false,
75-
};
78+
};*/
7679
let defines =
7780
match *instruction {
7881
Instruction::Call { ref destination, .. } | Instruction::Move { ref destination, .. } | Instruction::Operation { ref destination, .. } =>
@@ -104,7 +107,7 @@ impl<'a> GraphBuilder<'a> {
104107
stack_defines,
105108
stack_uses,
106109
uses,
107-
is_move,
110+
//is_move,
108111
};
109112
let entry = self.control_flow_graph.insert(node);
110113
self.visited.insert(current_index, entry);

tiger/src/frame/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ pub trait Frame: Clone {
5757
const WORD_SIZE: i64;
5858

5959
fn registers() -> Vec<Temp>;
60-
fn register_count() -> usize;
60+
// TODO: This is not used. Check if this is really not needed.
61+
//fn register_count() -> usize;
6162
fn temp_map() -> HashMap<Temp, &'static str>;
6263
fn special_name(temp: Temp) -> Option<&'static str>;
6364

tiger/src/frame/x86_64.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,10 @@ impl Frame for X86_64 {
232232
registers
233233
}
234234

235-
fn register_count() -> usize {
235+
// TODO: This is not used. Check if this is really not needed.
236+
/*fn register_count() -> usize {
236237
Self::registers().len() - [Self::rsp(), Self::rbp()].len()
237-
}
238+
}*/
238239

239240
fn temp_map() -> HashMap<Temp, &'static str> {
240241
let mut map = HashMap::new();

tiger/src/ir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
use temp::{Label, Temp};
2525

26+
#[allow(clippy::enum_variant_names)]
2627
#[derive(Clone, Debug, PartialEq)]
2728
pub enum Exp {
2829
Const(i64),

tiger/src/lexer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl<R: Read> Lexer<R> {
151151
't' => '\t',
152152
'\\' => '\\',
153153
'"' => '"',
154-
ch if ch.is_digit(10) => return self.escape_ascii_code(pos),
154+
ch if ch.is_ascii_digit() => return self.escape_ascii_code(pos),
155155
escape => {
156156
pos.length = 2;
157157
return Err(InvalidEscape {

0 commit comments

Comments
 (0)