chores: make clippy happy

This commit is contained in:
Krysztal Huang
2025-06-27 16:49:30 +08:00
parent d231109e86
commit f6737ff8bf
20 changed files with 58 additions and 58 deletions
+2 -2
View File
@@ -217,7 +217,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
print!("{}", construct_str(&mem_info));
}
Err(e) => {
eprintln!("free: failed to read memory info: {}", e);
eprintln!("free: failed to read memory info: {e}");
process::exit(1);
}
};
@@ -537,7 +537,7 @@ mod test {
);
}
Err(e) => {
eprintln!("free: failed to read memory info: {}", e);
eprintln!("free: failed to read memory info: {e}");
}
}
}
+1 -1
View File
@@ -64,7 +64,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
};
if !output.is_empty() {
println!("{}", output);
println!("{output}");
};
Ok(())
+4 -4
View File
@@ -27,9 +27,9 @@ pub enum Teletype {
impl Display for Teletype {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
Self::Tty(id) => write!(f, "/dev/pts/{}", id),
Self::TtyS(id) => write!(f, "/dev/tty{}", id),
Self::Pts(id) => write!(f, "/dev/ttyS{}", id),
Self::Tty(id) => write!(f, "/dev/pts/{id}"),
Self::TtyS(id) => write!(f, "/dev/tty{id}"),
Self::Pts(id) => write!(f, "/dev/ttyS{id}"),
Self::Unknown => write!(f, "?"),
}
}
@@ -290,7 +290,7 @@ impl ProcessInformation {
#[cfg(not(target_os = "linux"))]
let pid = 0; // dummy
ProcessInformation::try_new(PathBuf::from_str(&format!("/proc/{}", pid)).unwrap())
ProcessInformation::try_new(PathBuf::from_str(&format!("/proc/{pid}")).unwrap())
}
pub fn proc_status(&self) -> &str {
+5 -5
View File
@@ -191,7 +191,7 @@ fn try_get_pattern_from(matches: &ArgMatches) -> UResult<String> {
};
let pattern = if matches.get_flag("exact") {
&format!("^{}$", pattern)
&format!("^{pattern}$")
} else {
pattern
};
@@ -489,20 +489,20 @@ fn is_locked(_file: &std::fs::File) -> bool {
fn read_pidfile(filename: &str, check_locked: bool) -> UResult<i64> {
let file = std::fs::File::open(filename)
.map_err(|e| USimpleError::new(1, format!("Failed to open pidfile {}: {}", filename, e)))?;
.map_err(|e| USimpleError::new(1, format!("Failed to open pidfile {filename}: {e}")))?;
if check_locked && !is_locked(&file) {
return Err(USimpleError::new(
1,
format!("Pidfile {} is not locked", filename),
format!("Pidfile {filename} is not locked"),
));
}
let content = std::fs::read_to_string(filename)
.map_err(|e| USimpleError::new(1, format!("Failed to read pidfile {}: {}", filename, e)))?;
.map_err(|e| USimpleError::new(1, format!("Failed to read pidfile {filename}: {e}")))?;
let pid = parse_pidfile_content(&content)
.ok_or_else(|| USimpleError::new(1, format!("Pidfile {} not valid", filename)))?;
.ok_or_else(|| USimpleError::new(1, format!("Pidfile {filename} not valid")))?;
Ok(pid)
}
+1 -1
View File
@@ -33,7 +33,7 @@ fn is_running(pid: usize) -> bool {
use std::{path::PathBuf, str::FromStr};
use uu_pgrep::process::RunState;
let proc = PathBuf::from_str(&format!("/proc/{}", pid)).unwrap();
let proc = PathBuf::from_str(&format!("/proc/{pid}")).unwrap();
if !proc.exists() {
return false;
+1 -1
View File
@@ -80,7 +80,7 @@ fn handle_obsolete(args: &mut [String]) {
let opt_signal = signal_by_name_or_value(signal);
if opt_signal.is_some() {
// Replace with long option that clap can parse
args[1] = format!("--signal={}", signal);
args[1] = format!("--signal={signal}");
}
}
}
+1
View File
@@ -541,6 +541,7 @@ mod test {
use super::*;
use crate::maps_format_parser::Perms;
#[allow(clippy::too_many_arguments)]
fn create_smap_entry(
address: &str,
perms: Perms,
+5 -5
View File
@@ -110,9 +110,9 @@ fn sid(proc_info: RefCell<ProcessInformation>) -> String {
fn tty(proc_info: RefCell<ProcessInformation>) -> String {
match proc_info.borrow().tty() {
Teletype::Tty(tty) => format!("tty{}", tty),
Teletype::TtyS(ttys) => format!("ttyS{}", ttys),
Teletype::Pts(pts) => format!("pts/{}", pts),
Teletype::Tty(tty) => format!("tty{tty}"),
Teletype::TtyS(ttys) => format!("ttyS{ttys}"),
Teletype::Pts(pts) => format!("pts/{pts}"),
Teletype::Unknown => "?".to_owned(),
}
}
@@ -137,9 +137,9 @@ fn format_time(seconds: i64) -> String {
let second = seconds % 60;
if day != 0 {
format!("{:02}-{:02}:{:02}:{:02}", day, hour, minute, second)
format!("{day:02}-{hour:02}:{minute:02}:{second:02}")
} else {
format!("{:02}:{:02}:{:02}", hour, minute, second)
format!("{hour:02}:{minute:02}:{second:02}")
}
}
+1 -1
View File
@@ -88,7 +88,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
table.set_format(*FORMAT_CLEAN);
table.extend(rows);
print!("{}", table);
print!("{table}");
Ok(())
}
+1 -1
View File
@@ -348,7 +348,7 @@ mod tests {
#[test]
fn test_parse() {
let test = include_str!("../../../../tests/fixtures/slabtop/data.txt");
let result = SlabInfo::parse(test.into()).unwrap();
let result = SlabInfo::parse(test).unwrap();
assert_eq!(result.fetch("nf_conntrack_expect", "objsize").unwrap(), 208);
assert_eq!(
+4 -5
View File
@@ -97,7 +97,7 @@ fn output_list(info: &SlabInfo) {
"{:>6} {:>6} {:>4} {:>8} {:>6} {:>8} {:>10} {:<}",
"OBJS", "ACTIVE", "USE", "OBJ SIZE", "SLABS", "OBJ/SLAB", "CACHE SIZE", "NAME"
);
println!("{}", title);
println!("{title}");
for name in info.names() {
let objs = info.fetch(name, "num_objs").unwrap_or_default();
@@ -111,14 +111,13 @@ fn output_list(info: &SlabInfo) {
let obj_per_slab = info.fetch(name, "objperslab").unwrap_or_default();
let cache_size = (objsize * (objs as f64)) as u64;
let objsize = format!("{:.2}", objsize);
let objsize = format!("{objsize:.2}");
let content = format!(
"{:>6} {:>6} {:>4} {:>7}K {:>6} {:>8} {:>10} {:<}",
objs, active, used, objsize, slabs, obj_per_slab, cache_size, name
"{objs:>6} {active:>6} {used:>4} {objsize:>7}K {slabs:>6} {obj_per_slab:>8} {cache_size:>10} {name:<}"
);
println!("{}", content);
println!("{content}");
}
}
+1 -1
View File
@@ -59,7 +59,7 @@ impl SelectedTarget {
.iter()
.filter(|(pid, _)| {
let pid = pid.as_u32();
let path = PathBuf::from_str(&format!("/proc/{}/", pid)).unwrap();
let path = PathBuf::from_str(&format!("/proc/{pid}/")).unwrap();
ProcessInformation::try_new(path).unwrap().tty() == *tty
})
+2 -2
View File
@@ -183,7 +183,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
if settings.verbose {
let output = construct_verbose_result(&pids, &results).trim().to_owned();
println!("{}", output);
println!("{output}");
}
}
@@ -202,7 +202,7 @@ fn construct_verbose_result(pids: &[u32], action_results: &[Option<ActionResult>
let process = process_snapshot().process(Pid::from_u32(pid)).unwrap();
let tty =
ProcessInformation::try_new(PathBuf::from_str(&format!("/proc/{}", pid)).unwrap());
ProcessInformation::try_new(PathBuf::from_str(&format!("/proc/{pid}")).unwrap());
let user = process
.user_id()
+5 -5
View File
@@ -69,7 +69,7 @@ mod linux {
if let Some(value_to_set) = split.next() {
set_sysctl(&var, value_to_set)
.map_err(|e| e.map_err_context(|| format!("error writing key '{}'", var)))?;
.map_err(|e| e.map_err_context(|| format!("error writing key '{var}'")))?;
if quiet {
Ok(None)
} else {
@@ -77,7 +77,7 @@ mod linux {
}
} else {
let value = get_sysctl(&var)
.map_err(|e| e.map_err_context(|| format!("error reading key '{}'", var)))?;
.map_err(|e| e.map_err_context(|| format!("error reading key '{var}'")))?;
Ok(Some((var, value)))
}
}
@@ -105,11 +105,11 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Ok(Some((var, value_to_print))) => {
for line in value_to_print.split('\n') {
if matches.get_flag("names") {
println!("{}", var);
println!("{var}");
} else if matches.get_flag("values") {
println!("{}", line);
println!("{line}");
} else {
println!("{} = {}", var, line);
println!("{var} = {line}");
}
}
}
+1 -1
View File
@@ -75,7 +75,7 @@ impl ModernTui<'_> {
let label = {
let min = "0.0".to_owned();
let mid = format!("{:.1}", y_axis_upper_bound / 2.0);
let max = format!("{:.1}", y_axis_upper_bound);
let max = format!("{y_axis_upper_bound:.1}");
vec![min, mid, max]
};
let y_axis = Axis::default()
+4 -4
View File
@@ -55,7 +55,7 @@ fn cpu(pid: u32) -> String {
let usage = proc.cpu_usage();
format!("{:.2}", usage)
format!("{usage:.2}")
}
fn pid(pid: u32) -> String {
@@ -90,7 +90,7 @@ fn pr(pid: u32) -> String {
0
};
format!("{}", result)
format!("{result}")
}
// TODO: Implement this function for Windows
@@ -137,7 +137,7 @@ fn time_plus(pid: u32) -> String {
(hour, minute, second)
};
format!("{}:{:0>2}.{:0>2}", hour, min, sec)
format!("{hour}:{min:0>2}.{sec:0>2}")
}
fn mem(pid: u32) -> String {
@@ -165,7 +165,7 @@ fn command(pid: u32) -> String {
if cfg!(target_os = "linux") && result.is_empty() {
{
match PathBuf::from_str(&format!("/proc/{}/status", pid)) {
match PathBuf::from_str(&format!("/proc/{pid}/status")) {
Ok(path) => {
let file = File::open(path).unwrap();
let content = read_to_string(file).unwrap();
+3 -3
View File
@@ -119,7 +119,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.to_string()
.lines()
.map(cutter)
.for_each(|it| println!("{}", it));
.for_each(|it| println!("{it}"));
Ok(())
}
@@ -176,8 +176,8 @@ fn collect(settings: &Settings, fields: &[String]) -> Vec<Vec<String>> {
.read()
.unwrap()
.processes()
.iter()
.map(|(it, _)| it.as_u32())
.keys()
.map(|it| it.as_u32())
.collect::<Vec<_>>();
let filter = construct_filter(settings);
+9 -9
View File
@@ -110,7 +110,7 @@ fn concat_helper(
} else {
len - *data_len_excess
};
let formatted_value = format!("{:>width$}", value, width = len);
let formatted_value = format!("{value:>len$}");
*data_len_excess = formatted_value.len() - len;
data.push(formatted_value);
});
@@ -162,10 +162,10 @@ fn get_memory_info(
let inactive = with_unit(memory_info.inactive.as_u64(), matches);
let active = with_unit(memory_info.active.as_u64(), matches);
return vec![
(len, format!("{}", swap_used)),
(len, format!("{}", free)),
(len, format!("{}", inactive)),
(len, format!("{}", active)),
(len, format!("{swap_used}")),
(len, format!("{free}")),
(len, format!("{inactive}")),
(len, format!("{active}")),
];
}
@@ -173,10 +173,10 @@ fn get_memory_info(
let cache = with_unit(memory_info.cached.as_u64(), matches);
vec![
(len, format!("{}", swap_used)),
(len, format!("{}", free)),
(len, format!("{}", buffer)),
(len, format!("{}", cache)),
(len, format!("{swap_used}")),
(len, format!("{free}")),
(len, format!("{buffer}")),
(len, format!("{cache}")),
]
}
+6 -6
View File
@@ -171,7 +171,7 @@ fn fetch_user_info() -> Result<Vec<UserInfo>, std::io::Error> {
terminal: entry.tty_device(),
login_time: format_time(entry.login_time().to_string()).unwrap_or_default(),
idle_time: fetch_idle_time(entry.tty_device())?,
jcpu: format!("{:.2}", jcpu),
jcpu: format!("{jcpu:.2}"),
pcpu: fetch_pcpu_time(entry.pid()).unwrap_or_default().to_string(),
command: fetch_cmdline(entry.pid()).unwrap_or_default(),
};
@@ -199,26 +199,26 @@ pub fn format_uptime_procps(up_secs: i64) -> UResult<String> {
} else {
format!("{up_mins} min")
};
Ok(format!("{}{}", day_str, hour_min_str))
Ok(format!("{day_str}{hour_min_str}"))
}
#[inline]
pub fn get_formatted_uptime_procps() -> UResult<String> {
let time_str = format_uptime_procps(get_uptime(None)?)?;
Ok(format!("up {}", time_str))
Ok(format!("up {time_str}"))
}
fn print_uptime() {
print!(" {} ", get_formatted_time());
if let Ok(uptime) = get_formatted_uptime_procps() {
print!("{}, ", uptime);
print!("{uptime}, ");
} else {
print!("up ???? days ??:??, ");
}
print!(" {}", get_formatted_nusers());
if let Ok(loadavg) = get_formatted_loadavg() {
print!(", {}", loadavg);
print!(", {loadavg}");
}
println!();
}
@@ -273,7 +273,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}
}
Err(e) => {
eprintln!("w: failed to fetch user info: {}", e);
eprintln!("w: failed to fetch user info: {e}");
process::exit(1);
}
}
+1 -1
View File
@@ -711,7 +711,7 @@ fn test_env_key_match() {
#[cfg(target_os = "linux")]
fn test_env_key_value_match() {
let home = std::env::var("HOME").unwrap();
new_ucmd!().arg(format!("--env=HOME={}", home)).succeeds();
new_ucmd!().arg(format!("--env=HOME={home}")).succeeds();
}
#[test]