diff --git a/src/api/syscall.rs b/src/api/syscall.rs index f96350840..6d2faa4cd 100644 --- a/src/api/syscall.rs +++ b/src/api/syscall.rs @@ -13,7 +13,7 @@ pub fn sleep(seconds: f64) { pub fn delete(path: &str) -> Result<(), ()> { let path_ptr = path.as_ptr() as usize; - let path_len = path.len() as usize; + let path_len = path.len(); let res = unsafe { syscall!(DELETE, path_ptr, path_len) } as isize; if res >= 0 { Ok(()) @@ -24,7 +24,7 @@ pub fn delete(path: &str) -> Result<(), ()> { pub fn info(path: &str) -> Option { let path_ptr = path.as_ptr() as usize; - let path_len = path.len() as usize; + let path_len = path.len(); let mut info = FileInfo::new(); let stat_ptr = &mut info as *mut FileInfo as usize; let res = unsafe { syscall!(INFO, path_ptr, path_len, stat_ptr) } as isize; @@ -37,7 +37,7 @@ pub fn info(path: &str) -> Option { pub fn open(path: &str, flags: usize) -> Option { let ptr = path.as_ptr() as usize; - let len = path.len() as usize; + let len = path.len(); let res = unsafe { syscall!(OPEN, ptr, len, flags) } as isize; if res >= 0 { Some(res as usize) @@ -57,7 +57,7 @@ pub fn dup(old_handle: usize, new_handle: usize) -> Option { pub fn read(handle: usize, buf: &mut [u8]) -> Option { let ptr = buf.as_ptr() as usize; - let len = buf.len() as usize; + let len = buf.len(); let res = unsafe { syscall!(READ, handle, ptr, len) } as isize; if res >= 0 { Some(res as usize) @@ -68,7 +68,7 @@ pub fn read(handle: usize, buf: &mut [u8]) -> Option { pub fn write(handle: usize, buf: &[u8]) -> Option { let ptr = buf.as_ptr() as usize; - let len = buf.len() as usize; + let len = buf.len(); let res = unsafe { syscall!(WRITE, handle, ptr, len) } as isize; if res >= 0 { Some(res as usize) @@ -78,14 +78,14 @@ pub fn write(handle: usize, buf: &[u8]) -> Option { } pub fn close(handle: usize) { - unsafe { syscall!(CLOSE, handle as usize) }; + unsafe { syscall!(CLOSE, handle) }; } pub fn spawn(path: &str, args: &[&str]) -> Result<(), ExitCode> { let path_ptr = path.as_ptr() as usize; - let path_len = path.len() as usize; let args_ptr = args.as_ptr() as usize; - let args_len = args.len() as usize; + let path_len = path.len(); + let args_len = args.len(); let res = unsafe { syscall!(SPAWN, path_ptr, path_len, args_ptr, args_len) }; if res == 0 { Ok(()) diff --git a/src/bin/sleep.rs b/src/bin/sleep.rs index 32ed6aca5..42feb9497 100644 --- a/src/bin/sleep.rs +++ b/src/bin/sleep.rs @@ -11,7 +11,6 @@ fn main(args: &[&str]) { if args.len() == 2 { if let Ok(duration) = args[1].parse::() { syscall::sleep(duration); - return; } else { syscall::exit(ExitCode::DataError); } diff --git a/src/sys/clock.rs b/src/sys/clock.rs index 6775c3b69..3edad8b0b 100644 --- a/src/sys/clock.rs +++ b/src/sys/clock.rs @@ -95,7 +95,7 @@ fn days_before_year(year: u64) -> u64 { fn days_before_month(year: u64, month: u64) -> u64 { let leap_day = is_leap_year(year) && month > 2; - DAYS_BEFORE_MONTH[(month as usize) - 1] + if leap_day { 1 } else { 0 } + DAYS_BEFORE_MONTH[(month as usize) - 1] + (leap_day as u64) } fn is_leap_year(year: u64) -> bool { diff --git a/src/sys/fs/block_device.rs b/src/sys/fs/block_device.rs index 32ea35d56..13f883817 100644 --- a/src/sys/fs/block_device.rs +++ b/src/sys/fs/block_device.rs @@ -39,15 +39,15 @@ impl BlockDeviceIO for BlockDevice { fn block_size(&self) -> usize { match self { - BlockDevice::Mem(dev) => dev.block_size() as usize, - BlockDevice::Ata(dev) => dev.block_size() as usize, + BlockDevice::Mem(dev) => dev.block_size(), + BlockDevice::Ata(dev) => dev.block_size(), } } fn block_count(&self) -> usize { match self { - BlockDevice::Mem(dev) => dev.block_count() as usize, - BlockDevice::Ata(dev) => dev.block_count() as usize, + BlockDevice::Mem(dev) => dev.block_count(), + BlockDevice::Ata(dev) => dev.block_count(), } } } diff --git a/src/sys/fs/dir.rs b/src/sys/fs/dir.rs index a69d74f44..6d7f4f977 100644 --- a/src/sys/fs/dir.rs +++ b/src/sys/fs/dir.rs @@ -85,12 +85,7 @@ impl Dir { } pub fn find(&self, name: &str) -> Option { - for entry in self.entries() { - if entry.name() == name { - return Some(entry); - } - } - None + self.entries().find(|entry| entry.name() == name) } // TODO: return a Result diff --git a/src/sys/vga.rs b/src/sys/vga.rs index e2d6c1c1f..d78b18da9 100644 --- a/src/sys/vga.rs +++ b/src/sys/vga.rs @@ -258,7 +258,7 @@ impl Writer { let mut data: Port = Port::new(DAC_DATA_REG); for (i, (r, g, b)) in palette.colors.iter().enumerate() { if i < 16 { - let reg = color::from_index(i as usize).to_vga_reg(); + let reg = color::from_index(i).to_vga_reg(); unsafe { addr.write(reg); data.write(vga_color(*r)); diff --git a/src/usr/httpd.rs b/src/usr/httpd.rs index 617bb4bcf..4e03c721d 100644 --- a/src/usr/httpd.rs +++ b/src/usr/httpd.rs @@ -146,7 +146,7 @@ impl Response { return false; } } - return true; + true } } @@ -301,7 +301,7 @@ pub fn main(args: &[&str]) -> Result<(), ExitCode> { let real_path = real_path.trim_end_matches('/'); if fs::exists(real_path) { res.code = 403; - } else if let Some(handle) = fs::create_dir(&real_path) { + } else if let Some(handle) = fs::create_dir(real_path) { syscall::close(handle); res.code = 200; } else { diff --git a/src/usr/lisp/env.rs b/src/usr/lisp/env.rs index 802d315fb..fb04fa0eb 100644 --- a/src/usr/lisp/env.rs +++ b/src/usr/lisp/env.rs @@ -297,7 +297,7 @@ pub fn default_env() -> Rc> { let mut res = vec![]; for arg in args { if let Exp::List(list) = arg { - res.extend_from_slice(&list); + res.extend_from_slice(list); } else { return Err(Err::Reason("Expected arg to be a list".to_string())) }