From 982c6c63f70ce0b45ebc1fa375ba320a673f78ff Mon Sep 17 00:00:00 2001 From: Skyler Berg <skylertheberg@gmail.com> Date: Sun, 17 Jan 2016 20:04:05 -0800 Subject: [PATCH] Fix formating and cleanup compiler warnings --- src/builtin.rs | 5 +---- src/directory_stack.rs | 38 +++++++++++++++----------------------- src/main.rs | 1 - src/tokenizer.rs | 5 +---- 4 files changed, 17 insertions(+), 32 deletions(-) diff --git a/src/builtin.rs b/src/builtin.rs index 494822f4..60c9d8b4 100644 --- a/src/builtin.rs +++ b/src/builtin.rs @@ -1,11 +1,8 @@ use std::collections::HashMap; -use std::fs::{self, File}; -use std::io::{stdout, Read, Write}; +use std::io::{stdout, Write}; use std::env; use std::process; -use std::thread; -use super::to_num::ToNum; use super::set_var; use super::input_editor::readln; diff --git a/src/directory_stack.rs b/src/directory_stack.rs index ca144530..860e9fc3 100644 --- a/src/directory_stack.rs +++ b/src/directory_stack.rs @@ -1,34 +1,21 @@ -use std::env::{set_current_dir,current_dir}; -use std::path::{PathBuf,Path}; -use std::ops::Deref; +use std::env::{set_current_dir, current_dir}; +use std::path::PathBuf; pub struct DirectoryStack { - dirs: Vec<PathBuf>, // The top is + dirs: Vec<PathBuf>, // The top is always the current directory } -fn get_current_dir() -> PathBuf { // TODO STOP DOING THIS BAD STUFF - if let Ok(cur_dir) = current_dir() { - cur_dir - } else { - PathBuf::new() - } -} - - impl DirectoryStack { - pub fn new() -> Result<DirectoryStack, &'static str> { if let Ok(curr_dir) = current_dir() { - Ok(DirectoryStack { - dirs: vec![curr_dir], - }) + Ok(DirectoryStack { dirs: vec![curr_dir] }) } else { Err("Failed to get current directory when building directory stack") } } - pub fn popd(&mut self, args: &[String]) { - if (self.dirs.len() < 2) { + pub fn popd(&mut self, _: &[String]) { + if self.dirs.len() < 2 { println!("Directory stack is empty"); return; } @@ -36,7 +23,7 @@ impl DirectoryStack { if let Err(err) = set_current_dir(dir) { println!("{}: Failed to switch to directory {}", err, dir.display()); return; - } + } } self.dirs.pop(); self.print_dirs(); @@ -45,8 +32,13 @@ impl DirectoryStack { pub fn pushd(&mut self, args: &[String]) { if let Some(dir) = args.get(1) { match (set_current_dir(dir), current_dir()) { - (Ok(()), Ok(cur_dir)) => { self.dirs.push(cur_dir); }, - (Err(err), _) => { println!("{}: {}", err, dir); return; }, + (Ok(()), Ok(cur_dir)) => { + self.dirs.push(cur_dir); + } + (Err(err), _) => { + println!("{}: {}", err, dir); + return; + } (_, _) => (), } } else { @@ -56,7 +48,7 @@ impl DirectoryStack { self.print_dirs(); } - pub fn dirs(&self, args: &[String]) { + pub fn dirs(&self, _: &[String]) { self.print_dirs() } diff --git a/src/main.rs b/src/main.rs index 3460ed12..bf4038df 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,7 +31,6 @@ pub struct Shell { } impl Shell { - /// Panics if DirectoryStack construction fails pub fn new() -> Shell { Shell { diff --git a/src/tokenizer.rs b/src/tokenizer.rs index ecd632c8..b539c15c 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -38,10 +38,7 @@ fn process_character_single_quoted(_: &mut Vec<Token>, } } -fn process_character_comment(tokens: &mut Vec<Token>, - current_token: &mut String, - chr: char) - -> TokenizerState { +fn process_character_comment(tokens: &mut Vec<Token>, _: &mut String, chr: char) -> TokenizerState { match chr { '\n' | '\r' => { tokens.push(Token::End); -- GitLab