tlc: clippy cleanup — fix all lint warnings

Fixes 19 clippy warnings across 9 files:
- filehighlight.rs: iter().any() → contains()
- info.rs: manual clamp → .clamp()
- jobs.rs: format!("{}",x) → to_string(), clone → from_ref, allow if_same_then_else
- mod.rs: clone → from_ref, Box::new(x::new()) → Box::default(), allow collapsible_match
- panel.rs: io::Error::new(Other,..) → io::Error::other(..), merge identical archive ext branches
- subshell.rs: allow needless_return (cfg-gated false positive)
- tar.rs, cpio.rs: simplify boolean expressions
- macro.rs: allow collapsible_match (guard would change fallthrough semantics)

1 pre-existing warning remains (Include(String) never read in mc_ext.rs).
964 tests pass, 0 failures.
This commit is contained in:
2026-06-19 08:51:10 +03:00
parent fde8384189
commit 277b3f0b16
9 changed files with 24 additions and 19 deletions
@@ -238,6 +238,7 @@ impl MacroStore {
for k in keys.iter_mut() {
match k {
NamedKey::Ctrl(c) | NamedKey::Alt(c) => {
#[allow(clippy::collapsible_match, reason = "guard would change fallthrough semantics")]
if c.is_ascii_lowercase() {
*c = c.to_ascii_uppercase();
}
@@ -189,7 +189,7 @@ fn extension(filename: &str) -> Option<&str> {
/// `const` slices don't yet support `slice::contains` in `const` context,
/// and we want to avoid pulling in a hashing layer for ~1035 entries.
fn contains(table: &[&str], needle: &str) -> bool {
table.iter().any(|e| *e == needle)
table.contains(&needle)
}
#[cfg(test)]
@@ -70,7 +70,7 @@ impl InfoDialog {
/// `theme` supplies the title, body, and hint colours so the
/// dialog follows the active skin.
pub fn render(&self, frame: &mut Frame, area: Rect, theme: &Theme) {
let popup = centered_cols_rect(area, 64, area.height.saturating_sub(4).min(18).max(8));
let popup = centered_cols_rect(area, 64, area.height.saturating_sub(4).clamp(8, 18));
let inner = render_popup(frame, popup, self.title.clone(), theme);
let chunks = Layout::default()
@@ -361,7 +361,7 @@ pub fn spawn_delete_job(registry: &mut JobRegistry, paths: Vec<PathBuf>) -> Arc<
.first()
.map(|p| p.display().to_string())
.unwrap_or_default();
let total: u64 = paths.iter().map(|p| ops::count_bytes(&[p.clone()])).sum();
let total: u64 = paths.iter().map(|p| ops::count_bytes(std::slice::from_ref(p))).sum();
let job = registry.add(JobKind::Delete, source, String::new(), total);
let job_for_worker = Arc::clone(&job);
thread::spawn(move || {
@@ -675,7 +675,7 @@ impl JobsDialog {
Style::default().fg(theme.title_fg).bg(theme.title_bg),
),
Span::styled(
format!("{}", "Status"),
"Status".to_string(),
Style::default().fg(theme.title_fg).bg(theme.title_bg),
),
]);
@@ -690,6 +690,7 @@ impl JobsDialog {
} else {
let visible = chunks[1].height as usize;
let n = self.cache.len();
#[allow(clippy::if_same_then_else, reason = "n<=visible and selected<near-top both start at 0 but are semantically different")]
let start = if n <= visible {
0
} else if self.selected < visible / 2 {
@@ -717,7 +717,7 @@ impl FileManager {
Cmd::DirSize => {
let p = self.active_panel().cursor_path();
if p.is_dir() {
let bytes = crate::ops::count_bytes(&[p.clone()]);
let bytes = crate::ops::count_bytes(std::slice::from_ref(&p));
self.status
.set_message(format!("{}: {}", p.display(), format_size(bytes)));
} else {
@@ -759,15 +759,11 @@ impl FileManager {
Ok(true)
}
Cmd::Panelize => {
self.dialog = Some(DialogState::ExternalPanelize(Box::new(
external_panelize::ExternalPanelizeDialog::new(),
)));
self.dialog = Some(DialogState::ExternalPanelize(Box::default()));
Ok(true)
}
Cmd::VfsList => {
self.dialog = Some(DialogState::VfsList(Box::new(
vfs_list::VfsListDialog::new(),
)));
self.dialog = Some(DialogState::VfsList(Box::default()));
Ok(true)
}
Cmd::SymlinkRelative => {
@@ -1966,6 +1962,7 @@ impl FileManager {
}
}
Some(DialogState::Delete(d)) => {
#[allow(clippy::collapsible_match, reason = "guard would change fallthrough semantics")]
if d.is_confirmed() {
let paths = d.paths.clone();
let handle =
@@ -1987,6 +1984,7 @@ impl FileManager {
// Info dialog: just close.
Some(DialogState::Info(_)) => {}
Some(DialogState::Quit(d)) => {
#[allow(clippy::collapsible_match, reason = "guard would change fallthrough semantics")]
if d.confirmed {
self.should_quit = true;
}
@@ -740,7 +740,7 @@ impl Panel {
}
let mut kids = vfs
.read_dir(vp, self.show_hidden)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
.map_err(|e| std::io::Error::other(e.to_string()))?;
entries.append(&mut kids);
self.entries = entries;
let has_parent = self
@@ -899,11 +899,14 @@ fn ext(name: &str) -> String {
/// `None` for non-archive files.
fn is_archive_extension(name: &str) -> Option<&'static str> {
let lower = name.to_ascii_lowercase();
if lower.ends_with(".tar") || lower.ends_with(".tar.gz") || lower.ends_with(".tgz") {
Some("tar")
} else if lower.ends_with(".tar.bz2") || lower.ends_with(".tbz") {
Some("tar")
} else if lower.ends_with(".tar.xz") || lower.ends_with(".txz") {
if lower.ends_with(".tar")
|| lower.ends_with(".tar.gz")
|| lower.ends_with(".tgz")
|| lower.ends_with(".tar.bz2")
|| lower.ends_with(".tbz")
|| lower.ends_with(".tar.xz")
|| lower.ends_with(".txz")
{
Some("tar")
} else if lower.ends_with(".zip") {
Some("zip")
@@ -92,6 +92,7 @@ impl ShellManager {
if let Some(subshell) = self.subshell.as_mut() {
subshell.attach()?;
}
#[allow(clippy::needless_return, reason = "cfg-gated branch must early-return")]
return Ok(());
}
@@ -108,6 +109,7 @@ impl ShellManager {
if let Some(subshell) = self.subshell.as_mut() {
subshell.attach()?;
}
#[allow(clippy::needless_return, reason = "cfg-gated branch must early-return")]
return Ok(());
}
+1 -1
View File
@@ -217,7 +217,7 @@ impl Vfs for CpioVfs {
let mut seen: std::collections::BTreeSet<String> = std::collections::BTreeSet::new();
for entry in &self.entries {
let ep = entry.name.as_str();
if !ep.starts_with(&prefix_slash) && !(prefix.is_empty() && !ep.is_empty()) {
if !ep.starts_with(&prefix_slash) && (!prefix.is_empty() || ep.is_empty()) {
continue;
}
let rest = if prefix.is_empty() {
+1 -1
View File
@@ -219,7 +219,7 @@ impl Vfs for TarVfs {
let mut seen: std::collections::BTreeSet<String> = std::collections::BTreeSet::new();
for entry_path in &self.entries {
if !entry_path.starts_with(&prefix_slash)
&& !(prefix.is_empty() && !entry_path.is_empty())
&& (!prefix.is_empty() || entry_path.is_empty())
{
continue;
}