mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-19 20:42:46 +08:00
Address clippy lints
This commit is contained in:
parent
0d6b53bc3e
commit
5394ca1f96
|
@ -165,10 +165,7 @@ pub fn random(
|
|||
};
|
||||
|
||||
// Safe because end was a valid i64 and the result here is in the range start..=end.
|
||||
let result: i64 = start
|
||||
.checked_add_unsigned(rand * step)
|
||||
.and_then(|x| x.try_into().ok())
|
||||
.unwrap();
|
||||
let result: i64 = start.checked_add_unsigned(rand * step).unwrap();
|
||||
|
||||
streams.out.append(sprintf!(L!("%d\n"), result));
|
||||
return STATUS_CMD_OK;
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::sync::atomic::{AtomicU64, Ordering};
|
|||
use std::sync::{Arc, Mutex};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use self::fd_monitor::{new_fd_event_signaller, FdEventSignaller, ItemWakeReason};
|
||||
use self::fd_monitor_ffi::{new_fd_event_signaller, FdEventSignaller, ItemWakeReason};
|
||||
use crate::fd_readable_set::FdReadableSet;
|
||||
use crate::fds::AutoCloseFd;
|
||||
use crate::ffi::void_ptr;
|
||||
|
@ -13,7 +13,7 @@ use crate::wutil::perror;
|
|||
use cxx::SharedPtr;
|
||||
|
||||
#[cxx::bridge]
|
||||
mod fd_monitor {
|
||||
mod fd_monitor_ffi {
|
||||
/// Reason for waking an item
|
||||
#[repr(u8)]
|
||||
#[cxx_name = "item_wake_reason_t"]
|
||||
|
@ -106,6 +106,7 @@ type FfiCallback = extern "C" fn(*mut AutoCloseFd, u8, void_ptr);
|
|||
/// only `src/io.cpp`) is ported to rust
|
||||
enum FdMonitorCallback {
|
||||
None,
|
||||
#[allow(clippy::type_complexity)]
|
||||
Native(Box<dyn Fn(&mut AutoCloseFd, ItemWakeReason) + Send + Sync>),
|
||||
Ffi(FfiCallback /* fn ptr */, void_ptr /* param */),
|
||||
}
|
||||
|
@ -300,6 +301,7 @@ struct BackgroundFdMonitor {
|
|||
}
|
||||
|
||||
impl FdMonitor {
|
||||
#[allow(clippy::boxed_local)]
|
||||
pub fn add_ffi(&self, item: Box<FdMonitorItem>) -> u64 {
|
||||
self.add(*item).0
|
||||
}
|
||||
|
@ -364,8 +366,7 @@ impl FdMonitor {
|
|||
if timeout_usecs != FdReadableSet::kNoTimeout {
|
||||
item.timeout = Some(Duration::from_micros(timeout_usecs));
|
||||
}
|
||||
let item_id = self.add(item).0;
|
||||
item_id
|
||||
self.add(item).0
|
||||
}
|
||||
|
||||
/// Mark that the item with the given ID needs to be woken up explicitly.
|
||||
|
@ -416,7 +417,7 @@ impl BackgroundFdMonitor {
|
|||
loop {
|
||||
// Poke any items that need it
|
||||
if !pokelist.is_empty() {
|
||||
self.poke(&mut pokelist);
|
||||
self.poke(&pokelist);
|
||||
pokelist.clear();
|
||||
}
|
||||
fds.clear();
|
||||
|
@ -431,7 +432,7 @@ impl BackgroundFdMonitor {
|
|||
|
||||
for item in &mut self.items {
|
||||
fds.add(item.fd.as_raw_fd());
|
||||
if !item.last_time.is_some() {
|
||||
if item.last_time.is_none() {
|
||||
item.last_time = Some(now);
|
||||
}
|
||||
timeout = timeout.min(item.timeout.unwrap_or(Duration::MAX));
|
||||
|
@ -530,7 +531,7 @@ impl BackgroundFdMonitor {
|
|||
/// poke list is consumed after this. This is only called from the background thread.
|
||||
fn poke(&mut self, pokelist: &[FdMonitorItemId]) {
|
||||
self.items.retain_mut(|item| {
|
||||
let action = item.maybe_poke_item(&*pokelist);
|
||||
let action = item.maybe_poke_item(pokelist);
|
||||
if action == ItemAction::Remove {
|
||||
FLOG!(fd_monitor, "Removing fd", item.fd.as_raw_fd());
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ pub fn spawn<F: FnOnce() + Send + 'static>(callback: F) -> bool {
|
|||
// We don't have to port the PTHREAD_CREATE_DETACHED logic. Rust threads are detached
|
||||
// automatically if the returned join handle is dropped.
|
||||
|
||||
let result = match std::thread::Builder::new().spawn(|| callback()) {
|
||||
let result = match std::thread::Builder::new().spawn(callback) {
|
||||
Ok(handle) => {
|
||||
let id = handle.thread().id();
|
||||
FLOG!(iothread, "rust thread", id, "spawned");
|
||||
|
|
|
@ -55,6 +55,7 @@ pub fn push_timer(enabled: bool) -> Option<PrintElapsedOnDrop> {
|
|||
/// cxx bridge does not support UniquePtr<NativeRustType> so we can't use a null UniquePtr to
|
||||
/// represent a None, and cxx bridge does not support Box<Option<NativeRustType>> so we need to make
|
||||
/// our own wrapper type that incorporates the Some/None states directly into it.
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
enum PrintElapsedOnDropFfi {
|
||||
Some(PrintElapsedOnDrop),
|
||||
None,
|
||||
|
|
|
@ -1136,10 +1136,7 @@ fn parse_fd(s: &wstr) -> RawFd {
|
|||
})
|
||||
.collect();
|
||||
let s = std::str::from_utf8(chars.as_slice()).unwrap();
|
||||
match s.parse() {
|
||||
Ok(val) => val,
|
||||
Err(_) => -1,
|
||||
}
|
||||
s.parse().unwrap_or(-1)
|
||||
}
|
||||
|
||||
fn new_move_word_state_machine(syl: MoveWordStyle) -> Box<MoveWordStateMachine> {
|
||||
|
|
|
@ -76,7 +76,7 @@ where
|
|||
return Ok(ParseResult {
|
||||
result: 0,
|
||||
negative: false,
|
||||
consumed_all: chars.peek() == None,
|
||||
consumed_all: chars.peek().is_none(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ where
|
|||
if result == 0 {
|
||||
negative = false;
|
||||
}
|
||||
let consumed_all = chars.peek() == None;
|
||||
let consumed_all = chars.peek().is_none();
|
||||
Ok(ParseResult {
|
||||
result,
|
||||
negative,
|
||||
|
|
Loading…
Reference in New Issue
Block a user