mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-09-06 08:18:58 +00:00
Enable cast_possible_wrap clippy lint and fix violations
Replaces 14 unsigned-to-signed `as` casts with try_from().unwrap() to panic on overflow instead of silently wrapping. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
4901e0ec8f
commit
ef70bc1596
10 changed files with 16 additions and 15 deletions
|
|
@ -88,7 +88,6 @@ too_many_arguments = "allow"
|
|||
too_many_lines = "allow"
|
||||
used_underscore_binding = "allow"
|
||||
if_not_else = "allow"
|
||||
cast_possible_wrap = "allow"
|
||||
cast_precision_loss = "allow"
|
||||
doc_markdown = "allow"
|
||||
# Disallowed restriction lints
|
||||
|
|
|
|||
|
|
@ -501,7 +501,7 @@ fn compute_queue_positions(runs: &HashMap<String, ManagedRun>) -> HashMap<String
|
|||
queued
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(i, (id, _))| (id.clone(), (i + 1) as i64))
|
||||
.map(|(i, (id, _))| (id.clone(), i64::try_from(i + 1).unwrap()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -462,7 +462,7 @@ fn determine_exit_code(conclusion_path: &Path, status_record: Option<RunStatusRe
|
|||
|
||||
#[allow(unsafe_code)]
|
||||
fn kill_engine(run_dir: &Path) {
|
||||
if let Some(pid) = read_launcher_pid(run_dir).map(|pid| pid as i32) {
|
||||
if let Some(pid) = read_launcher_pid(run_dir).map(|pid| i32::try_from(pid).unwrap()) {
|
||||
#[cfg(unix)]
|
||||
unsafe {
|
||||
libc::kill(pid, libc::SIGTERM);
|
||||
|
|
@ -475,7 +475,7 @@ fn kill_engine(run_dir: &Path) {
|
|||
fn process_alive(pid: u32) -> bool {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
unsafe { libc::kill(pid as i32, 0) == 0 }
|
||||
unsafe { libc::kill(i32::try_from(pid).unwrap(), 0) == 0 }
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
{
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ pub(crate) fn launcher_record_is_running(record: &LauncherRecord) -> bool {
|
|||
#[cfg(unix)]
|
||||
#[allow(unsafe_code)]
|
||||
fn process_alive(pid: u32) -> bool {
|
||||
unsafe { libc::kill(pid as i32, 0) == 0 }
|
||||
unsafe { libc::kill(i32::try_from(pid).unwrap(), 0) == 0 }
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
|
|
|
|||
|
|
@ -128,10 +128,10 @@ fn try_parse_relative_duration(s: &str) -> Option<chrono::Duration> {
|
|||
let (num_str, unit) = s.split_at(s.len() - 1);
|
||||
let num: u64 = num_str.parse().ok()?;
|
||||
match unit {
|
||||
"s" => Some(chrono::Duration::seconds(num as i64)),
|
||||
"m" => Some(chrono::Duration::minutes(num as i64)),
|
||||
"h" => Some(chrono::Duration::hours(num as i64)),
|
||||
"d" => Some(chrono::Duration::days(num as i64)),
|
||||
"s" => Some(chrono::Duration::seconds(i64::try_from(num).unwrap())),
|
||||
"m" => Some(chrono::Duration::minutes(i64::try_from(num).unwrap())),
|
||||
"h" => Some(chrono::Duration::hours(i64::try_from(num).unwrap())),
|
||||
"d" => Some(chrono::Duration::days(i64::try_from(num).unwrap())),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ mod tests {
|
|||
fn process_alive(pid: u32) -> bool {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
unsafe { libc::kill(pid as i32, 0) == 0 }
|
||||
unsafe { libc::kill(i32::try_from(pid).unwrap(), 0) == 0 }
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ pub(crate) fn parse_duration(s: &str) -> Result<chrono::Duration> {
|
|||
.parse()
|
||||
.with_context(|| format!("invalid duration: {s}"))?;
|
||||
match unit {
|
||||
"h" => Ok(chrono::Duration::hours(num as i64)),
|
||||
"d" => Ok(chrono::Duration::days(num as i64)),
|
||||
"h" => Ok(chrono::Duration::hours(i64::try_from(num).unwrap())),
|
||||
"d" => Ok(chrono::Duration::days(i64::try_from(num).unwrap())),
|
||||
_ => bail!("invalid duration unit '{unit}' in '{s}' (expected 'h' or 'd')"),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ fn estimate_reasoning_tokens(content_parts: &[ContentPart]) -> Option<i64> {
|
|||
})
|
||||
.sum();
|
||||
if total_chars > 0 {
|
||||
Some((total_chars / 4).max(1) as i64)
|
||||
Some(i64::try_from((total_chars / 4).max(1)).unwrap())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
|
|||
|
|
@ -488,7 +488,7 @@ async fn sigterm_then_kill(child: &mut Child) {
|
|||
// SAFETY: kill with a negative pid signals the entire process group.
|
||||
// The pid is valid because we just obtained it from child.id().
|
||||
unsafe {
|
||||
libc::kill(-(pid as i32), libc::SIGTERM);
|
||||
libc::kill(-i32::try_from(pid).unwrap(), libc::SIGTERM);
|
||||
}
|
||||
if time::timeout(std::time::Duration::from_secs(2), child.wait())
|
||||
.await
|
||||
|
|
|
|||
|
|
@ -23,7 +23,9 @@ impl Default for BackoffPolicy {
|
|||
|
||||
impl BackoffPolicy {
|
||||
pub fn delay_for_attempt(&self, attempt: u32) -> Duration {
|
||||
let multiplier = self.factor.powi(attempt.saturating_sub(1) as i32);
|
||||
let multiplier = self
|
||||
.factor
|
||||
.powi(i32::try_from(attempt.saturating_sub(1)).unwrap());
|
||||
let base_delay = self.initial_delay.mul_f64(multiplier);
|
||||
let capped = if base_delay > self.max_delay {
|
||||
self.max_delay
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue