Commit 6206685d authored by Fletcher Haynes's avatar Fletcher Haynes

Fixed up clippy warnings

parent eee41a00
Pipeline #32696454 passed with stages
in 13 minutes and 27 seconds
......@@ -355,13 +355,13 @@ impl Assembler {
ref mut starting_instruction,
} => {
debug!("Code section starts at: {}", self.current_instruction);
*starting_instruction = Some(self.current_instruction.clone())
*starting_instruction = Some(self.current_instruction)
}
AssemblerSection::Data {
ref mut starting_instruction,
} => {
debug!("Data section starts at: {}", self.current_instruction);
*starting_instruction = Some(self.current_instruction.clone())
*starting_instruction = Some(self.current_instruction)
}
AssemblerSection::Unknown => {
error!("Found a section header that is unknown: {:?}", new_section)
......
......@@ -35,7 +35,7 @@ impl ClusterClient {
pub fn send_hello(&mut self) {
let alias = self.alias.clone();
let alias = alias.unwrap();
if let Ok(_) = self.raw_stream.write(&alias.as_bytes()) {
if self.raw_stream.write(&alias.as_bytes()).is_ok() {
trace!("Hello sent!");
} else {
error!("Error sending hello");
......
......@@ -25,13 +25,13 @@ impl Manager {
true
}
pub fn del_client(&mut self, alias: NodeAlias) {
self.clients.remove(&alias);
pub fn del_client(&mut self, alias: &NodeAlias) {
self.clients.remove(alias);
}
pub fn get_client_names(&self) -> Vec<String> {
let mut results = vec![];
for (alias, _) in &self.clients {
for alias in self.clients.keys() {
results.push(alias.to_owned());
}
results
......@@ -42,7 +42,8 @@ impl Manager {
mod test {
use super::Manager;
#[allow(dead_code)]
fn test_create_manager() {
let test_manager = Manager::new();
let _test_manager = Manager::new();
}
}
......@@ -40,7 +40,7 @@ impl REPL {
pub fn new(vm: VM) -> REPL {
let (tx, rx): (Sender<String>, Receiver<String>) = mpsc::channel();
REPL {
vm: vm,
vm,
command_buffer: vec![],
asm: Assembler::new(),
scheduler: Scheduler::new(),
......@@ -316,17 +316,17 @@ impl REPL {
}
fn start_cluster(&mut self, _args: &[&str]) {
self.send_message(format!("Started cluster server!"));
self.send_message("Started cluster server!".to_string());
self.vm.bind_cluster_server();
}
fn join_cluster(&mut self, args: &[&str]) {
self.send_message(format!("Attempting to join cluster..."));
self.send_message("Attempting to join cluster...".to_string());
let ip = args[0];
let port = args[1];
let addr = ip.to_owned() + ":" + port;
if let Ok(stream) = TcpStream::connect(addr) {
self.send_message(format!("Connected to cluster!"));
self.send_message("Connected to cluster!".to_string());
let mut cc = cluster::client::ClusterClient::new(stream);
cc.send_hello();
if let Some(ref a) = self.vm.alias {
......@@ -335,12 +335,12 @@ impl REPL {
}
}
} else {
self.send_message(format!("Could not connect to cluster!"));
self.send_message("Could not connect to cluster!".to_string());
}
}
fn cluster_members(&mut self, _args: &[&str]) {
self.send_message(format!("Listing Known Nodes:"));
self.send_message("Listing Known Nodes:".to_string());
let cluster_members = self
.vm
.connection_manager
......
......@@ -25,9 +25,9 @@ pub enum VMEventType {
impl VMEventType {
pub fn stop_code(&self) -> u32 {
match &self {
&VMEventType::Start => 0,
&VMEventType::GracefulStop { code } => *code,
&VMEventType::Crash { code } => *code,
VMEventType::Start => 0,
VMEventType::GracefulStop { code } => *code,
VMEventType::Crash { code } => *code,
}
}
}
......@@ -420,8 +420,8 @@ impl VM {
Opcode::LUI => {
let register = self.next_8_bits() as usize;
let value = self.registers[register];
let uv1 = self.next_8_bits() as i32;
let uv2 = self.next_8_bits() as i32;
let uv1 = i32::from(self.next_8_bits());
let uv2 = i32::from(self.next_8_bits());
let value = value.checked_shl(8).unwrap();
let value = value | uv1;
let value = value.checked_shl(8).unwrap();
......@@ -461,7 +461,7 @@ impl VM {
Opcode::PUSH => {
let data = self.registers[self.next_8_bits() as usize];
let mut buf: [u8; 4] = [0, 0, 0, 0];
if let Ok(_) = buf.as_mut().write_i32::<LittleEndian>(data) {
if buf.as_mut().write_i32::<LittleEndian>(data).is_ok() {
for b in &buf {
self.stack.push(*b);
}
......@@ -473,10 +473,9 @@ impl VM {
let target_register = self.next_8_bits() as usize;
let mut buf: [u8; 4] = [0, 0, 0, 0];
let new_len = self.stack.len() - 4;
let mut c = 0;
for removed_element in self.stack.drain(new_len..) {
//for removed_element in self.stack.drain(new_len..) {
for (c, removed_element) in self.stack.drain(new_len..).enumerate() {
buf[c] = removed_element;
c += 1;
}
let data = LittleEndian::read_i32(&buf);
self.registers[target_register] = data;
......@@ -491,10 +490,8 @@ impl VM {
Opcode::RET => {
let mut buf: [u8; 4] = [0, 0, 0, 0];
let new_len = self.stack.len() - 4;
let mut c = 0;
for removed_element in self.stack.drain(new_len..) {
for (c, removed_element) in self.stack.drain(new_len..).enumerate() {
buf[c] = removed_element;
c += 1;
}
let data = LittleEndian::read_i32(&buf);
self.pc = data as usize;
......@@ -553,8 +550,7 @@ impl VM {
fn get_starting_offset(&self) -> usize {
let mut rdr = Cursor::new(&self.program[64..68]);
let starting_offset = rdr.read_u32::<LittleEndian>().unwrap() as usize;
starting_offset
rdr.read_u32::<LittleEndian>().unwrap() as usize
}
// Attempts to decode the byte the VM's program counter is pointing at into an opcode
......
......@@ -5,7 +5,7 @@ mod commons;
#[test]
fn create_vm() {
commons::setup();
let mut vm = iridium::vm::VM::new();
let vm = iridium::vm::VM::new();
assert_eq!(vm.registers.len(), 32);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment