Skip to content

Commit

Permalink
fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Nugine committed Oct 9, 2022
1 parent 0c77385 commit 79f7212
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
1 change: 1 addition & 0 deletions scripts/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def emit_cfg(cfgs: List[Dict[str, List[str]]], indent: int) -> str:
]

print("#![allow(clippy::cast_possible_truncation)]\n")
print("#![allow(clippy::unnecessary_cast)]\n")

resource_cfgs = []
for resource in resources:
Expand Down
1 change: 1 addition & 0 deletions src/bindings.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(clippy::cast_possible_truncation)]
#![allow(clippy::unnecessary_cast)]

#[cfg(any(
target_os = "fuchsia",
Expand Down
36 changes: 13 additions & 23 deletions src/proc_limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl ProcLimits {
"ProcLimits: pid must be non-negative",
));
}
Self::read_proc_fs(format!("/proc/{}/limits", pid))
Self::read_proc_fs(format!("/proc/{pid}/limits"))
}

fn read_proc_fs(limits_path: impl AsRef<Path>) -> io::Result<Self> {
Expand All @@ -108,31 +108,21 @@ impl ProcLimits {
}
}

fn error_missing_table_head() -> io::Error {
io::Error::new(io::ErrorKind::Other, "ProcLimits: missing table head")
fn io_error_other(s: impl Into<String>) -> io::Error {
io::Error::new(io::ErrorKind::Other, s.into())
}

fn error_invalid_table_head() -> io::Error {
io::Error::new(io::ErrorKind::Other, "ProcLimits: invalid table head")
}
let error_missing_table_head = || io_error_other("ProcLimits: missing table head");

fn error_invalid_limit_number(e: &ParseIntError) -> io::Error {
io::Error::new(
io::ErrorKind::Other,
format!("ProcLimits: invalid limit number: {}", e),
)
}
let error_invalid_table_head = || io_error_other("ProcLimits: invalid table head");

fn error_duplicate_limit_field() -> io::Error {
io::Error::new(io::ErrorKind::Other, "ProcLimits: duplicate limit field")
}
let error_invalid_limit_number =
|e| io_error_other(format!("ProcLimits: invalid limit number: {e}"));

fn error_unknown_limit_field(s: &str) -> io::Error {
io::Error::new(
io::ErrorKind::Other,
format!("ProcLimits: unknown limit field: {:?}", s),
)
}
let error_duplicate_limit_field = || io_error_other("ProcLimits: duplicate limit field");

let error_unknown_limit_field =
|s: &str| io_error_other(format!("ProcLimits: unknown limit field: {s:?}"));

let reader = io::BufReader::new(fs::File::open(limits_path)?);
let mut lines = reader.lines();
Expand Down Expand Up @@ -171,8 +161,8 @@ impl ProcLimits {
let (hard, _) = line.split_at(hard_len);

let name = name.trim().to_lowercase();
let soft_limit = parse_limit_number(soft.trim()).map_err(|e|error_invalid_limit_number(&e))?;
let hard_limit = parse_limit_number(hard.trim()).map_err(|e|error_invalid_limit_number(&e))?;
let soft_limit = parse_limit_number(soft.trim()).map_err(error_invalid_limit_number)?;
let hard_limit = parse_limit_number(hard.trim()).map_err(error_invalid_limit_number)?;
let limit = ProcLimit {
soft_limit,
hard_limit,
Expand Down
4 changes: 4 additions & 0 deletions src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::resource::Resource;
use std::{io, mem};

/// A value indicating no limit.
#[allow(clippy::unnecessary_cast)]
pub const INFINITY: u64 = C::RLIM_INFINITY as u64;

fn check_supported(resource: Resource) -> io::Result<()> {
Expand Down Expand Up @@ -42,6 +43,8 @@ pub fn getrlimit(resource: Resource) -> io::Result<(u64, u64)> {
let mut rlim = unsafe { mem::zeroed() };
#[allow(clippy::cast_lossless)]
let ret = unsafe { C::getrlimit(resource.as_raw() as _, &mut rlim) };

#[allow(clippy::unnecessary_cast)]
if ret == 0 {
let soft = (rlim.rlim_cur as u64).min(INFINITY);
let hard = (rlim.rlim_max as u64).min(INFINITY);
Expand Down Expand Up @@ -103,6 +106,7 @@ pub fn prlimit(
let ret = unsafe { prlimit64(pid, resource.as_raw() as _, new_rlimit_ptr, old_rlimit_ptr) };

if ret == 0 {
#[allow(clippy::unnecessary_cast)]
if let Some((soft, hard)) = old_limit {
*soft = (old_rlim.rlim_cur as u64).min(INFINITY);
*hard = (old_rlim.rlim_max as u64).min(INFINITY);
Expand Down

0 comments on commit 79f7212

Please sign in to comment.