From 8e0f54cb31d498c06f9bc0cb70541fed2ffcb197 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Fri, 11 Nov 2022 13:19:14 -0700 Subject: [PATCH] Clippy fixes --- clippy.sh | 11 +--------- src/acpi/madt.rs | 6 +++--- src/arch/aarch64/device/cpu/mod.rs | 12 +++++------ src/arch/x86/idt.rs | 2 +- src/arch/x86_64/idt.rs | 2 +- src/arch/x86_64/paging/mod.rs | 2 +- src/arch/x86_64/start.rs | 4 ++-- src/context/arch/x86_64.rs | 2 +- src/context/context.rs | 2 +- src/context/memory.rs | 2 +- src/devices/graphical_debug/debug.rs | 4 ++-- src/devices/graphical_debug/mod.rs | 2 +- src/event.rs | 2 +- src/log.rs | 2 +- src/memory/mod.rs | 2 +- src/ptrace.rs | 4 ++-- src/scheme/irq.rs | 30 ++++++++++++++-------------- src/scheme/pipe.rs | 4 ++-- src/scheme/proc.rs | 20 +++++++++---------- src/scheme/root.rs | 2 +- src/scheme/sys/mod.rs | 2 +- src/scheme/sys/syscall.rs | 2 +- src/scheme/user.rs | 18 ++++++++--------- src/sync/wait_condition.rs | 2 +- src/syscall/fs.rs | 14 ++++++------- src/syscall/futex.rs | 4 ++-- src/syscall/process.rs | 4 ++-- 27 files changed, 76 insertions(+), 87 deletions(-) diff --git a/clippy.sh b/clippy.sh index 67ab40db..655f1b89 100755 --- a/clippy.sh +++ b/clippy.sh @@ -2,15 +2,6 @@ set -e -# https://github.com/rust-lang/rust-clippy/issues/4579 -export RUSTUP_TOOLCHAIN="nightly-2019-07-19" -rustup update "${RUSTUP_TOOLCHAIN}" -rustup component add clippy --toolchain "${RUSTUP_TOOLCHAIN}" -rustup component add rust-src --toolchain "${RUSTUP_TOOLCHAIN}" - -# Cause recompilation -touch src/lib.rs - export RUST_TARGET_PATH="${PWD}/targets" export RUSTFLAGS="-C soft-float -C debuginfo=2" -xargo clippy --lib --release --target x86_64-unknown-none +cargo clippy --lib --release --target x86_64-unknown-none "$@" diff --git a/src/acpi/madt.rs b/src/acpi/madt.rs index 05931444..d1cd4b52 100644 --- a/src/acpi/madt.rs +++ b/src/acpi/madt.rs @@ -176,9 +176,9 @@ impl Madt { let flags = unsafe { *(sdt.data_address() as *const u32).offset(1) }; Some(Madt { - sdt: sdt, - local_address: local_address, - flags: flags + sdt, + local_address, + flags }) } else { None diff --git a/src/arch/aarch64/device/cpu/mod.rs b/src/arch/aarch64/device/cpu/mod.rs index 5ac491bf..6e88a9f2 100644 --- a/src/arch/aarch64/device/cpu/mod.rs +++ b/src/arch/aarch64/device/cpu/mod.rs @@ -194,12 +194,12 @@ impl CpuInfo { pub fn cpu_info(w: &mut W) -> Result { let cpuinfo = CpuInfo::new(); - write!(w, "Implementer: {}\n", cpuinfo.implementer)?; - write!(w, "Variant: {}\n", cpuinfo.variant)?; - write!(w, "Architecture version: {}\n", cpuinfo.architecture)?; - write!(w, "Part Number: {}\n", cpuinfo.part_number)?; - write!(w, "Revision: {}\n", cpuinfo.revision)?; - write!(w, "\n")?; + writeln!(w, "Implementer: {}", cpuinfo.implementer)?; + writeln!(w, "Variant: {}", cpuinfo.variant)?; + writeln!(w, "Architecture version: {}", cpuinfo.architecture)?; + writeln!(w, "Part Number: {}", cpuinfo.part_number)?; + writeln!(w, "Revision: {}", cpuinfo.revision)?; + writeln!(w)?; Ok(()) } diff --git a/src/arch/x86/idt.rs b/src/arch/x86/idt.rs index eaaabd25..bfca4d01 100644 --- a/src/arch/x86/idt.rs +++ b/src/arch/x86/idt.rs @@ -134,7 +134,7 @@ const fn new_idt_reservations() -> [AtomicU32; 8] { /// Initialize the IDT for a pub unsafe fn init_paging_post_heap(is_bsp: bool, cpu_id: usize) { let mut idts_guard = IDTS.write(); - let idts_btree = idts_guard.get_or_insert_with(|| BTreeMap::new()); + let idts_btree = idts_guard.get_or_insert_with(BTreeMap::new); if is_bsp { idts_btree.insert(cpu_id, &mut INIT_BSP_IDT); diff --git a/src/arch/x86_64/idt.rs b/src/arch/x86_64/idt.rs index dfaad136..1377ff75 100644 --- a/src/arch/x86_64/idt.rs +++ b/src/arch/x86_64/idt.rs @@ -131,7 +131,7 @@ const fn new_idt_reservations() -> [AtomicU64; 4] { /// Initialize the IDT for a pub unsafe fn init_paging_post_heap(is_bsp: bool, cpu_id: usize) { let mut idts_guard = IDTS.write(); - let idts_btree = idts_guard.get_or_insert_with(|| BTreeMap::new()); + let idts_btree = idts_guard.get_or_insert_with(BTreeMap::new); if is_bsp { idts_btree.insert(cpu_id, &mut INIT_BSP_IDT); diff --git a/src/arch/x86_64/paging/mod.rs b/src/arch/x86_64/paging/mod.rs index 13ba9892..31a74e21 100644 --- a/src/arch/x86_64/paging/mod.rs +++ b/src/arch/x86_64/paging/mod.rs @@ -160,7 +160,7 @@ pub unsafe fn init( let flush_all = map_percpu(cpu_id, KernelMapper::lock_manually(cpu_id).get_mut().expect("expected KernelMapper not to be locked re-entrant in paging::init")); flush_all.flush(); - return init_tcb(cpu_id); + init_tcb(cpu_id) } pub unsafe fn init_ap( diff --git a/src/arch/x86_64/start.rs b/src/arch/x86_64/start.rs index 24235cfc..92e3bbca 100644 --- a/src/arch/x86_64/start.rs +++ b/src/arch/x86_64/start.rs @@ -96,9 +96,9 @@ pub unsafe extern fn kstart(args_ptr: *const KernelArgs) -> ! { // Initialize logger log::init_logger(|r| { use core::fmt::Write; - let _ = write!( + let _ = writeln!( super::debug::Writer::new(), - "{}:{} -- {}\n", + "{}:{} -- {}", r.target(), r.level(), r.args() diff --git a/src/context/arch/x86_64.rs b/src/context/arch/x86_64.rs index 22fcaf11..b648674f 100644 --- a/src/context/arch/x86_64.rs +++ b/src/context/arch/x86_64.rs @@ -165,7 +165,7 @@ pub unsafe fn switch_to(prev: &mut super::Context, next: &mut super::Context) { // Since Arc is essentially just wraps a pointer, in this case a regular pointer (as // opposed to dyn or slice fat pointers), and NonNull optimization exists, map_or will // hopefully be optimized down to checking prev and next pointers, as next cannot be null. - Some(ref next_space) => if prev.addr_space.as_ref().map_or(true, |prev_space| !Arc::ptr_eq(&prev_space, &next_space)) { + Some(ref next_space) => if prev.addr_space.as_ref().map_or(true, |prev_space| !Arc::ptr_eq(prev_space, next_space)) { // Suppose we have two sibling threads A and B. A runs on CPU 0 and B on CPU 1. A // recently called yield and is now here about to switch back. Meanwhile, B is // currently creating a new mapping in their shared address space, for example a diff --git a/src/context/context.rs b/src/context/context.rs index 9f9517d7..b526065d 100644 --- a/src/context/context.rs +++ b/src/context/context.rs @@ -285,7 +285,7 @@ impl AlignedBox { Ok(unsafe { let ptr = crate::ALLOCATOR.alloc_zeroed(Self::LAYOUT); if ptr.is_null() { - return Err(Enomem)?; + return Err(Enomem); } Self { inner: Unique::new_unchecked(ptr.cast()), diff --git a/src/context/memory.rs b/src/context/memory.rs index b0462c2b..95251da5 100644 --- a/src/context/memory.rs +++ b/src/context/memory.rs @@ -97,7 +97,7 @@ impl AddrSpace { // TODO: Remove reborrow? In that case, physmapped memory will need to either be // remapped when cloning, or be backed by a file descriptor (like // `memory:physical`). - new_grant = Grant::reborrow(&grant, Page::containing_address(grant.start_address()), this_mapper, new_mapper, ())?; + new_grant = Grant::reborrow(grant, Page::containing_address(grant.start_address()), this_mapper, new_mapper, ())?; } new_guard.grants.insert(new_grant); diff --git a/src/devices/graphical_debug/debug.rs b/src/devices/graphical_debug/debug.rs index afa08dc4..427c997c 100644 --- a/src/devices/graphical_debug/debug.rs +++ b/src/devices/graphical_debug/debug.rs @@ -16,8 +16,8 @@ impl DebugDisplay { display, x: 0, y: 0, - w: w, - h: h, + w, + h, } } diff --git a/src/devices/graphical_debug/mod.rs b/src/devices/graphical_debug/mod.rs index 29468f8d..32ac85c0 100644 --- a/src/devices/graphical_debug/mod.rs +++ b/src/devices/graphical_debug/mod.rs @@ -7,7 +7,7 @@ use self::display::Display; pub mod debug; pub mod display; -pub static FONT: &'static [u8] = include_bytes!("../../../res/unifont.font"); +pub static FONT: &[u8] = include_bytes!("../../../res/unifont.font"); pub static DEBUG_DISPLAY: Mutex> = Mutex::new(None); diff --git a/src/event.rs b/src/event.rs index 73e2de1f..f55591cb 100644 --- a/src/event.rs +++ b/src/event.rs @@ -153,7 +153,7 @@ pub fn sync(reg_key: RegKey) -> Result { let scheme = { let schemes = scheme::schemes(); let scheme = schemes.get(reg_key.scheme).ok_or(Error::new(EBADF))?; - Arc::clone(&scheme) + Arc::clone(scheme) }; scheme.fevent(reg_key.number, flags) diff --git a/src/log.rs b/src/log.rs index e1dd1aa7..b5373376 100644 --- a/src/log.rs +++ b/src/log.rs @@ -45,7 +45,7 @@ impl ::log::Log for RedoxLogger { false } fn log(&self, record: &log::Record<'_>) { - (self.log_func)(&record) + (self.log_func)(record) } fn flush(&self) {} } diff --git a/src/memory/mod.rs b/src/memory/mod.rs index f8bd8b1f..86db6fd6 100644 --- a/src/memory/mod.rs +++ b/src/memory/mod.rs @@ -59,7 +59,7 @@ pub fn allocate_frames_complex(count: usize, flags: PhysallocFlags, strategy: Op strategy, min ); - return None; + None } /// Deallocate a range of frames frame diff --git a/src/ptrace.rs b/src/ptrace.rs index 81d06115..41263beb 100644 --- a/src/ptrace.rs +++ b/src/ptrace.rs @@ -242,7 +242,7 @@ pub fn wait(pid: ContextId) -> Result<()> { let sessions = sessions(); match sessions.get(&pid) { - Some(session) => Arc::clone(&session), + Some(session) => Arc::clone(session), _ => return Ok(()) } }; @@ -283,7 +283,7 @@ pub fn breakpoint_callback(match_flags: PtraceFlags, event: Option) let sessions = sessions(); let session = sessions.get(&context.id)?; - Arc::clone(&session) + Arc::clone(session) }; let mut data = session.data.lock(); diff --git a/src/scheme/irq.rs b/src/scheme/irq.rs index 3aec2134..2f46d297 100644 --- a/src/scheme/irq.rs +++ b/src/scheme/irq.rs @@ -189,7 +189,7 @@ impl Scheme for IrqScheme { } Handle::Avail(cpu_id, data.into_bytes(), AtomicUsize::new(0)) - } else if path_str.chars().next() == Some('/') { + } else if path_str.starts_with('/') { let path_str = &path_str[1..]; Self::open_ext_irq(flags, cpu_id, path_str)? } else { @@ -227,7 +227,7 @@ impl Scheme for IrqScheme { Ok(0) } } else { - return Err(Error::new(EINVAL)); + Err(Error::new(EINVAL)) } &Handle::Bsp => { if buffer.len() < mem::size_of::() { @@ -237,7 +237,7 @@ impl Scheme for IrqScheme { unsafe { *(buffer.as_mut_ptr() as *mut usize) = bsp_apic_id as usize; } Ok(mem::size_of::()) } else { - return Err(Error::new(EBADFD)); + Err(Error::new(EBADFD)) } } &Handle::Avail(_, ref buf, ref offset) | &Handle::TopLevel(ref buf, ref offset) => { @@ -262,7 +262,7 @@ impl Scheme for IrqScheme { offset.store(new_offset as usize, Ordering::SeqCst); Ok(new_offset) } - _ => return Err(Error::new(ESPIPE)), + _ => Err(Error::new(ESPIPE)), } } @@ -285,9 +285,9 @@ impl Scheme for IrqScheme { Ok(0) } } else { - return Err(Error::new(EINVAL)); + Err(Error::new(EINVAL)) } - _ => return Err(Error::new(EBADF)), + _ => Err(Error::new(EBADF)), } } @@ -295,8 +295,8 @@ impl Scheme for IrqScheme { let handles_guard = HANDLES.read(); let handle = handles_guard.as_ref().unwrap().get(&id).ok_or(Error::new(EBADF))?; - match handle { - &Handle::Irq { irq: handle_irq, .. } => { + match *handle { + Handle::Irq { irq: handle_irq, .. } => { stat.st_mode = MODE_CHR | 0o600; stat.st_size = mem::size_of::() as u64; stat.st_blocks = 1; @@ -304,7 +304,7 @@ impl Scheme for IrqScheme { stat.st_ino = handle_irq.into(); stat.st_nlink = 1; } - &Handle::Bsp => { + Handle::Bsp => { stat.st_mode = MODE_CHR | 0o400; stat.st_size = mem::size_of::() as u64; stat.st_blocks = 1; @@ -312,13 +312,13 @@ impl Scheme for IrqScheme { stat.st_ino = INO_BSP; stat.st_nlink = 1; } - &Handle::Avail(cpu_id, ref buf, _) => { + Handle::Avail(cpu_id, ref buf, _) => { stat.st_mode = MODE_DIR | 0o700; stat.st_size = buf.len() as u64; stat.st_ino = INO_AVAIL | u64::from(cpu_id) << 32; stat.st_nlink = 2; } - &Handle::TopLevel(ref buf, _) => { + Handle::TopLevel(ref buf, _) => { stat.st_mode = MODE_DIR | 0o500; stat.st_size = buf.len() as u64; stat.st_ino = INO_TOPLEVEL; @@ -341,10 +341,10 @@ impl Scheme for IrqScheme { let handle = handles_guard.as_ref().unwrap().get(&id).ok_or(Error::new(EBADF))?; let scheme_path = match handle { - &Handle::Irq { irq, .. } => format!("irq:{}", irq), - &Handle::Bsp => format!("irq:bsp"), - &Handle::Avail(cpu_id, _, _) => format!("irq:cpu-{:2x}", cpu_id), - &Handle::TopLevel(_, _) => format!("irq:"), + Handle::Irq { irq, .. } => format!("irq:{}", irq), + Handle::Bsp => format!("irq:bsp"), + Handle::Avail(cpu_id, _, _) => format!("irq:cpu-{:2x}", cpu_id), + Handle::TopLevel(_, _) => format!("irq:"), }.into_bytes(); let mut i = 0; diff --git a/src/scheme/pipe.rs b/src/scheme/pipe.rs index 4090e7e9..e9d6a7d1 100644 --- a/src/scheme/pipe.rs +++ b/src/scheme/pipe.rs @@ -53,7 +53,7 @@ impl Scheme for PipeScheme { // Clone to prevent deadlocks let pipe = { let pipes = PIPES.read(); - pipes.0.get(&id).map(|pipe| pipe.clone()).ok_or(Error::new(EBADF))? + pipes.0.get(&id).cloned().ok_or(Error::new(EBADF))? }; pipe.read(buf) @@ -63,7 +63,7 @@ impl Scheme for PipeScheme { // Clone to prevent deadlocks let pipe = { let pipes = PIPES.read(); - pipes.1.get(&id).map(|pipe| pipe.clone()).ok_or(Error::new(EBADF))? + pipes.1.get(&id).cloned().ok_or(Error::new(EBADF))? }; pipe.write(buf) diff --git a/src/scheme/proc.rs b/src/scheme/proc.rs index f7f735b1..d6f80a0a 100644 --- a/src/scheme/proc.rs +++ b/src/scheme/proc.rs @@ -366,7 +366,7 @@ impl ProcScheme { let mut data = String::new(); for index in target.files.read().iter().enumerate().filter_map(|(idx, val)| val.as_ref().map(|_| idx)) { - write!(data, "{}\n", index).unwrap(); + writeln!(data, "{}", index).unwrap(); } data.into_bytes().into_boxed_slice() })); @@ -624,8 +624,8 @@ impl Scheme for ProcScheme { // in that case, what scheme? b"empty" => (Operation::AddrSpace { addrspace: new_addrspace()? }, false), b"exclusive" => (Operation::AddrSpace { addrspace: addrspace.write().try_clone()? }, false), - b"mem" => (Operation::Memory { addrspace: Arc::clone(&addrspace) }, true), - b"mmap-min-addr" => (Operation::MmapMinAddr(Arc::clone(&addrspace)), false), + b"mem" => (Operation::Memory { addrspace: Arc::clone(addrspace) }, true), + b"mmap-min-addr" => (Operation::MmapMinAddr(Arc::clone(addrspace)), false), grant_handle if grant_handle.starts_with(b"grant-") => { let start_addr = usize::from_str_radix(core::str::from_utf8(&grant_handle[6..]).map_err(|_| Error::new(EINVAL))?, 16).map_err(|_| Error::new(EINVAL))?; @@ -742,7 +742,7 @@ impl Scheme for ProcScheme { Ok((Output { float: context.get_fx_regs() }, mem::size_of::())) })?, - RegsKind::Int => try_stop_context(info.pid, |context| match unsafe { ptrace::regs_for(&context) } { + RegsKind::Int => try_stop_context(info.pid, |context| match unsafe { ptrace::regs_for(context) } { None => { assert!(!context.running, "try_stop_context is broken, clearly"); println!("{}:{}: Couldn't read registers from stopped process", file!(), line!()); @@ -838,7 +838,7 @@ impl Scheme for ProcScheme { // TODO: Find a better way to switch address spaces, since they also require switching // the instruction and stack pointer. Maybe remove `/regs` altogether and replace it // with `/ctx` - _ => return Err(Error::new(EBADF)), + _ => Err(Error::new(EBADF)), } } @@ -1043,7 +1043,7 @@ impl Scheme for ProcScheme { } Ok(buf.len()) } - Operation::Filetable { .. } => return Err(Error::new(EBADF)), + Operation::Filetable { .. } => Err(Error::new(EBADF)), Operation::CurrentFiletable => { let filetable_fd = usize::from_ne_bytes(<[u8; mem::size_of::()]>::try_from(buf).map_err(|_| Error::new(EINVAL))?); @@ -1081,7 +1081,7 @@ impl Scheme for ProcScheme { addrspace.write().mmap_min = val; Ok(mem::size_of::()) } - _ => return Err(Error::new(EBADF)), + _ => Err(Error::new(EBADF)), } } @@ -1135,7 +1135,7 @@ impl Scheme for ProcScheme { _ => return Err(Error::new(EOPNOTSUPP)), }); - read_from(buf, &path.as_bytes(), &mut 0) + read_from(buf, path.as_bytes(), &mut 0) } fn fstat(&self, id: usize, stat: &mut Stat) -> Result { @@ -1328,14 +1328,14 @@ impl KernelScheme for ProcScheme { if let Some(before) = before { src_addr_space.grants.insert(before); } if let Some(after) = after { src_addr_space.grants.insert(after); } - dst_addr_space.mmap(requested_dst_page, grant_page_count, map.flags, |dst_page, _flags, dst_mapper, dst_flusher| Ok(Grant::transfer(middle, dst_page, src_mapper, dst_mapper, InactiveFlusher::new(), dst_flusher)?))? + dst_addr_space.mmap(requested_dst_page, grant_page_count, map.flags, |dst_page, _flags, dst_mapper, dst_flusher| Grant::transfer(middle, dst_page, src_mapper, dst_mapper, InactiveFlusher::new(), dst_flusher))? } else { dst_addr_space.mmap(requested_dst_page, grant_page_count, map.flags, |dst_page, flags, dst_mapper, flusher| Ok(Grant::borrow(Page::containing_address(src_grant_region.start_address()), dst_page, grant_page_count, flags, None, src_mapper, dst_mapper, flusher)?))? }; Ok(result_page.start_address().data()) } - _ => return Err(Error::new(EBADF)), + _ => Err(Error::new(EBADF)), } } } diff --git a/src/scheme/root.rs b/src/scheme/root.rs index ff2a13f7..f0932c98 100644 --- a/src/scheme/root.rs +++ b/src/scheme/root.rs @@ -79,7 +79,7 @@ impl Scheme for RootScheme { let context = { let contexts = context::contexts(); let context = contexts.current().ok_or(Error::new(ESRCH))?; - Arc::downgrade(&context) + Arc::downgrade(context) }; let id = self.next_id.fetch_add(1, Ordering::SeqCst); diff --git a/src/scheme/sys/mod.rs b/src/scheme/sys/mod.rs index 61f14b33..70b5399a 100644 --- a/src/scheme/sys/mod.rs +++ b/src/scheme/sys/mod.rs @@ -93,7 +93,7 @@ impl Scheme for SysScheme { let data = entry.1()?; self.handles.write().insert(id, Handle { path: entry.0, - data: data, + data, mode: MODE_FILE | 0o444, seek: 0 }); diff --git a/src/scheme/sys/syscall.rs b/src/scheme/sys/syscall.rs index a1999982..77f60959 100644 --- a/src/scheme/sys/syscall.rs +++ b/src/scheme/sys/syscall.rs @@ -15,7 +15,7 @@ pub fn resource() -> Result> { let contexts = context::contexts(); for (id, context_lock) in contexts.iter() { let context = context_lock.read(); - rows.push((*id, context.name.read().clone(), context.syscall.clone())); + rows.push((*id, context.name.read().clone(), context.syscall)); } } diff --git a/src/scheme/user.rs b/src/scheme/user.rs index 9511c545..31b29d44 100644 --- a/src/scheme/user.rs +++ b/src/scheme/user.rs @@ -298,16 +298,14 @@ impl UserInner { // TODO: Faster, cleaner mechanism to get descriptor let scheme = self.scheme_id.load(Ordering::SeqCst); let mut desc_res = Err(Error::new(EBADF)); - for context_file_opt in context.files.read().iter() { - if let Some(context_file) = context_file_opt { - let (context_scheme, context_number) = { - let desc = context_file.description.read(); - (desc.scheme, desc.number) - }; - if context_scheme == scheme && context_number == file { - desc_res = Ok(context_file.clone()); - break; - } + for context_file in context.files.read().iter().flatten() { + let (context_scheme, context_number) = { + let desc = context_file.description.read(); + (desc.scheme, desc.number) + }; + if context_scheme == scheme && context_number == file { + desc_res = Ok(context_file.clone()); + break; } } let desc = desc_res?; diff --git a/src/sync/wait_condition.rs b/src/sync/wait_condition.rs index 8f6566ec..b4f0e5ce 100644 --- a/src/sync/wait_condition.rs +++ b/src/sync/wait_condition.rs @@ -43,7 +43,7 @@ impl WaitCondition { let context_lock = { let contexts = context::contexts(); let context_lock = contexts.current().expect("WaitCondition::wait: no context"); - Arc::clone(&context_lock) + Arc::clone(context_lock) }; { diff --git a/src/syscall/fs.rs b/src/syscall/fs.rs index 71f085fd..100214a6 100644 --- a/src/syscall/fs.rs +++ b/src/syscall/fs.rs @@ -24,7 +24,7 @@ pub fn file_op(a: usize, fd: FileHandle, c: usize, d: usize) -> Result { let scheme = { let schemes = scheme::schemes(); let scheme = schemes.get(file.description.read().scheme).ok_or(Error::new(EBADF))?; - Arc::clone(&scheme) + Arc::clone(scheme) }; let mut packet = Packet { @@ -71,7 +71,7 @@ pub fn open(path: &str, flags: usize) -> Result { let (scheme_id, scheme) = { let schemes = scheme::schemes(); let (scheme_id, scheme) = schemes.get_name(scheme_ns, scheme_name).ok_or(Error::new(ENODEV))?; - (scheme_id, Arc::clone(&scheme)) + (scheme_id, Arc::clone(scheme)) }; (scheme_id, scheme.open(reference, flags, uid, gid)?) @@ -142,7 +142,7 @@ pub fn rmdir(path: &str) -> Result { let scheme = { let schemes = scheme::schemes(); let (_scheme_id, scheme) = schemes.get_name(scheme_ns, scheme_name).ok_or(Error::new(ENODEV))?; - Arc::clone(&scheme) + Arc::clone(scheme) }; scheme.rmdir(reference, uid, gid) } @@ -163,7 +163,7 @@ pub fn unlink(path: &str) -> Result { let scheme = { let schemes = scheme::schemes(); let (_scheme_id, scheme) = schemes.get_name(scheme_ns, scheme_name).ok_or(Error::new(ENODEV))?; - Arc::clone(&scheme) + Arc::clone(scheme) }; scheme.unlink(reference, uid, gid) } @@ -200,7 +200,7 @@ fn duplicate_file(fd: FileHandle, buf: &[u8]) -> Result { let scheme = { let schemes = scheme::schemes(); let scheme = schemes.get(description.scheme).ok_or(Error::new(EBADF))?; - Arc::clone(&scheme) + Arc::clone(scheme) }; scheme.dup(description.number, buf)? }; @@ -260,7 +260,7 @@ pub fn fcntl(fd: FileHandle, cmd: usize, arg: usize) -> Result { let scheme = { let schemes = scheme::schemes(); let scheme = schemes.get(description.scheme).ok_or(Error::new(EBADF))?; - Arc::clone(&scheme) + Arc::clone(scheme) }; scheme.fcntl(description.number, cmd, arg)?; }; @@ -354,7 +354,7 @@ pub fn fstat(fd: FileHandle, stat: &mut Stat) -> Result { let scheme = { let schemes = scheme::schemes(); let scheme = schemes.get(description.scheme).ok_or(Error::new(EBADF))?; - Arc::clone(&scheme) + Arc::clone(scheme) }; // Fill in scheme number as device number stat.st_dev = description.scheme.into() as u64; diff --git a/src/syscall/futex.rs b/src/syscall/futex.rs index 28bb0699..24464f3c 100644 --- a/src/syscall/futex.rs +++ b/src/syscall/futex.rs @@ -80,7 +80,7 @@ pub fn futex(addr: usize, op: usize, val: usize, val2: usize, addr2: usize) -> R let context_lock = { let contexts = context::contexts(); let context_lock = contexts.current().ok_or(Error::new(ESRCH))?; - Arc::clone(&context_lock) + Arc::clone(context_lock) }; // TODO: Is the implicit SeqCst ordering too strong here? @@ -127,7 +127,7 @@ pub fn futex(addr: usize, op: usize, val: usize, val2: usize, addr2: usize) -> R let context_lock = { let contexts = context::contexts(); let context_lock = contexts.current().ok_or(Error::new(ESRCH))?; - Arc::clone(&context_lock) + Arc::clone(context_lock) }; { diff --git a/src/syscall/process.rs b/src/syscall/process.rs index a8cf746e..fb572096 100644 --- a/src/syscall/process.rs +++ b/src/syscall/process.rs @@ -67,7 +67,7 @@ pub fn exit(status: usize) -> ! { { let context_lock = context::current().expect("exit failed to find context"); - let mut close_files; + let close_files; let pid = { let mut context = context_lock.write(); close_files = Arc::try_unwrap(mem::take(&mut context.files)).map_or_else(|_| Vec::new(), RwLock::into_inner); @@ -91,7 +91,7 @@ pub fn exit(status: usize) -> ! { } // Files must be closed while context is valid so that messages can be passed - for (_fd, file_opt) in close_files.drain(..).enumerate() { + for (_fd, file_opt) in close_files.into_iter().enumerate() { if let Some(file) = file_opt { let _ = file.close(); }