Skip to content

Commit 6388891

Browse files
Merge pull request RustPython#141 from OddBloke/clippy
Apply some clippy lints
2 parents 28d5855 + 5a27e34 commit 6388891

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

parser/src/python.lalrpop

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// See also: file:///usr/share/doc/python/html/reference/grammar.html?highlight=grammar
2+
#![allow(unknown_lints,clippy)]
3+
24
use super::ast;
35
use super::lexer;
46
use std::iter::FromIterator;

src/main.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,14 @@ fn main() {
5050
}
5151
}
5252

53-
fn _run_string(source: &String, source_path: Option<String>) {
53+
fn _run_string(source: &str, source_path: Option<String>) {
5454
let mut vm = VirtualMachine::new();
55-
let code_obj = compile::compile(&mut vm, &source, compile::Mode::Exec, source_path).unwrap();
55+
let code_obj = compile::compile(
56+
&mut vm,
57+
&source.to_string(),
58+
compile::Mode::Exec,
59+
source_path,
60+
).unwrap();
5661
debug!("Code object: {:?}", code_obj.borrow());
5762
let builtins = vm.get_builtin_scope();
5863
let vars = vm.context().new_scope(Some(builtins)); // Keep track of local variables
@@ -74,7 +79,7 @@ fn run_command(source: &mut String) {
7479
_run_string(source, None)
7580
}
7681

77-
fn run_script(script_file: &String) {
82+
fn run_script(script_file: &str) {
7883
debug!("Running file {}", script_file);
7984
// Parse an ast from it:
8085
let filepath = Path::new(script_file);
@@ -87,10 +92,10 @@ fn run_script(script_file: &String) {
8792
}
8893
}
8994

90-
fn shell_exec(vm: &mut VirtualMachine, source: &String, scope: PyObjectRef) -> bool {
91-
match compile::compile(vm, source, compile::Mode::Single, None) {
95+
fn shell_exec(vm: &mut VirtualMachine, source: &str, scope: PyObjectRef) -> bool {
96+
match compile::compile(vm, &source.to_string(), compile::Mode::Single, None) {
9297
Ok(code) => {
93-
match vm.run_code_obj(code, scope.clone()) {
98+
match vm.run_code_obj(code, scope) {
9499
Ok(_value) => {
95100
// Printed already.
96101
}
@@ -114,7 +119,7 @@ fn shell_exec(vm: &mut VirtualMachine, source: &String, scope: PyObjectRef) -> b
114119
fn read_until_empty_line(input: &mut String) -> Result<i32, std::io::Error> {
115120
loop {
116121
print!("..... ");
117-
io::stdout().flush().ok().expect("Could not flush stdout");
122+
io::stdout().flush().expect("Could not flush stdout");
118123
let mut line = String::new();
119124
match io::stdin().read_line(&mut line) {
120125
Ok(0) => {
@@ -146,7 +151,7 @@ fn run_shell() {
146151
let mut input = String::new();
147152
loop {
148153
print!(">>>>> "); // Use 5 items. pypy has 4, cpython has 3.
149-
io::stdout().flush().ok().expect("Could not flush stdout");
154+
io::stdout().flush().expect("Could not flush stdout");
150155
match io::stdin().read_line(&mut input) {
151156
Ok(0) => {
152157
break;

vm/src/vm.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl VirtualMachine {
193193
match block {
194194
Some(Block::TryExcept { handler }) => {
195195
self.push_value(exc);
196-
self.jump(&handler);
196+
self.jump(handler);
197197
return None;
198198
}
199199
Some(_) => {}
@@ -866,7 +866,7 @@ impl VirtualMachine {
866866
} else {
867867
panic!("Wrong block type")
868868
};
869-
self.jump(&end_label);
869+
self.jump(end_label);
870870
None
871871
} else {
872872
Some(Err(next_error))
@@ -939,15 +939,15 @@ impl VirtualMachine {
939939
}
940940
}
941941
bytecode::Instruction::Jump { target } => {
942-
self.jump(target);
942+
self.jump(*target);
943943
None
944944
}
945945
bytecode::Instruction::JumpIf { target } => {
946946
let obj = self.pop_value();
947947
match objbool::boolval(self, obj) {
948948
Ok(value) => {
949949
if value {
950-
self.jump(target);
950+
self.jump(*target);
951951
}
952952
None
953953
}
@@ -960,7 +960,7 @@ impl VirtualMachine {
960960
match objbool::boolval(self, obj) {
961961
Ok(value) => {
962962
if !value {
963-
self.jump(target);
963+
self.jump(*target);
964964
}
965965
None
966966
}
@@ -994,7 +994,7 @@ impl VirtualMachine {
994994
bytecode::Instruction::Break => {
995995
let block = self.unwind_loop();
996996
if let Block::Loop { start: _, end } = block {
997-
self.jump(&end);
997+
self.jump(end);
998998
}
999999
None
10001000
}
@@ -1005,7 +1005,7 @@ impl VirtualMachine {
10051005
bytecode::Instruction::Continue => {
10061006
let block = self.unwind_loop();
10071007
if let Block::Loop { start, end: _ } = block {
1008-
self.jump(&start);
1008+
self.jump(start);
10091009
} else {
10101010
assert!(false);
10111011
}
@@ -1065,9 +1065,9 @@ impl VirtualMachine {
10651065
}
10661066
}
10671067

1068-
fn jump(&mut self, label: &bytecode::Label) {
1068+
fn jump(&mut self, label: bytecode::Label) {
10691069
let current_frame = self.current_frame_mut();
1070-
let target_pc = current_frame.code.label_map[label];
1070+
let target_pc = current_frame.code.label_map[&label];
10711071
trace!(
10721072
"program counter from {:?} to {:?}",
10731073
current_frame.lasti,

0 commit comments

Comments
 (0)