From 776f8cb3d37ca6ef50bf63dfd26508d130a3dfec Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Fri, 1 Nov 2024 13:51:12 -0400 Subject: [PATCH] refactor: bump 'msrv' to 1.81 and update deprecated code (#1615) * refactor: ignore warning for deprecated panic hook from Rust 1.82.0 * refactor: bump 'msrv' to 1.81 and update deprecated code * some more cleanup * even more cleanup --- Cargo.toml | 2 +- build.rs | 2 +- src/app/data_farmer.rs | 6 +- src/app/layout_manager.rs | 2 +- src/canvas/components/data_table.rs | 2 +- src/data_collection/disks/freebsd.rs | 1 - .../disks/unix/file_systems.rs | 2 +- .../disks/unix/linux/partition.rs | 2 +- .../disks/unix/macos/io_kit/bindings.rs | 12 ++-- .../disks/unix/other/partition.rs | 2 +- src/data_collection/disks/unix/usage.rs | 4 +- src/data_collection/processes/linux.rs | 2 +- .../processes/macos/sysctl_bindings.rs | 13 +---- src/main.rs | 6 +- src/options.rs | 58 ++++++++++--------- 15 files changed, 57 insertions(+), 59 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1807136b..522d234b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ exclude = [ "rustfmt.toml", ] # The oldest version I've tested that should still build - note this is not an official MSRV! -rust-version = "1.74.0" +rust-version = "1.81.0" [[bin]] name = "btm" diff --git a/build.rs b/build.rs index df820396..b13858b6 100644 --- a/build.rs +++ b/build.rs @@ -1,4 +1,4 @@ -#[allow(dead_code)] +#[expect(dead_code)] #[path = "src/options/args.rs"] mod args; diff --git a/src/app/data_farmer.rs b/src/app/data_farmer.rs index b1f49f23..47d97ba8 100644 --- a/src/app/data_farmer.rs +++ b/src/app/data_farmer.rs @@ -206,8 +206,10 @@ impl DataCollection { self.timed_data_vec.shrink_to_fit(); } - // Clippy allow to avoid warning on certain platforms (e.g. 32-bit). - #[allow(clippy::boxed_local)] + #[allow( + clippy::boxed_local, + reason = "Clippy allow to avoid warning on certain platforms (e.g. 32-bit)." + )] pub fn eat_data(&mut self, harvested_data: Box) { let harvested_time = harvested_data.collection_time; let mut new_entry = TimedData::default(); diff --git a/src/app/layout_manager.rs b/src/app/layout_manager.rs index e125726f..012bab40 100644 --- a/src/app/layout_manager.rs +++ b/src/app/layout_manager.rs @@ -19,7 +19,7 @@ type ColumnMappings = (u32, BTreeMap); impl BottomLayout { pub fn get_movement_mappings(&mut self) { - #[allow(clippy::suspicious_operation_groupings)] // Have to enable this, clippy really doesn't like me doing this with tuples... + #[expect(clippy::suspicious_operation_groupings)] // Have to enable this, clippy really doesn't like me doing this with tuples... fn is_intersecting(a: LineSegment, b: LineSegment) -> bool { a.0 >= b.0 && a.1 <= b.1 || a.1 >= b.1 && a.0 <= b.0 diff --git a/src/canvas/components/data_table.rs b/src/canvas/components/data_table.rs index ba92e077..f517de77 100644 --- a/src/canvas/components/data_table.rs +++ b/src/canvas/components/data_table.rs @@ -126,7 +126,7 @@ impl, H: ColumnHeader, S: SortType, C: DataTableColumn CollectionResult { // TODO: Should this (and other I/O collectors) fail fast? In general, should // collection ever fail fast? - #[allow(unused_mut)] let mut io_harvest: HashMap> = get_disk_info().map(|storage_system_information| { storage_system_information diff --git a/src/data_collection/disks/unix/file_systems.rs b/src/data_collection/disks/unix/file_systems.rs index c700fd6f..b268aee2 100644 --- a/src/data_collection/disks/unix/file_systems.rs +++ b/src/data_collection/disks/unix/file_systems.rs @@ -88,7 +88,7 @@ impl FileSystem { matches!(self, FileSystem::Other(..)) } - #[allow(dead_code)] + #[expect(dead_code)] #[inline] /// Returns a string literal identifying this filesystem. pub fn as_str(&self) -> &str { diff --git a/src/data_collection/disks/unix/linux/partition.rs b/src/data_collection/disks/unix/linux/partition.rs index 5da832a0..ad73d436 100644 --- a/src/data_collection/disks/unix/linux/partition.rs +++ b/src/data_collection/disks/unix/linux/partition.rs @@ -138,7 +138,7 @@ impl FromStr for Partition { } } -#[allow(dead_code)] +#[expect(dead_code)] /// Returns a [`Vec`] containing all partitions. pub(crate) fn partitions() -> anyhow::Result> { const PROC_MOUNTS: &str = "/proc/mounts"; diff --git a/src/data_collection/disks/unix/macos/io_kit/bindings.rs b/src/data_collection/disks/unix/macos/io_kit/bindings.rs index 93aaf9b8..8e5180d5 100644 --- a/src/data_collection/disks/unix/macos/io_kit/bindings.rs +++ b/src/data_collection/disks/unix/macos/io_kit/bindings.rs @@ -12,24 +12,24 @@ use core_foundation::{ use libc::c_char; use mach2::{kern_return::kern_return_t, port::MACH_PORT_NULL}; -#[allow(non_camel_case_types)] +#[expect(non_camel_case_types)] pub type io_object_t = mach_port_t; -#[allow(non_camel_case_types)] +#[expect(non_camel_case_types)] pub type io_iterator_t = io_object_t; -#[allow(non_camel_case_types)] +#[expect(non_camel_case_types)] pub type io_registry_entry_t = io_object_t; pub type IOOptionBits = u32; /// See https://github.com/1kc/librazermacos/pull/27#issuecomment-1042368531. -#[allow(non_upper_case_globals)] +#[expect(non_upper_case_globals)] pub const kIOMasterPortDefault: mach_port_t = MACH_PORT_NULL; -#[allow(non_upper_case_globals)] +#[expect(non_upper_case_globals)] pub const kIOServicePlane: &str = "IOService\0"; -#[allow(non_upper_case_globals)] +#[expect(non_upper_case_globals)] pub const kIOMediaClass: &str = "IOMedia\0"; // See [here](https://developer.apple.com/documentation/iokit) for more details. diff --git a/src/data_collection/disks/unix/other/partition.rs b/src/data_collection/disks/unix/other/partition.rs index ad97bdb4..e56181b8 100644 --- a/src/data_collection/disks/unix/other/partition.rs +++ b/src/data_collection/disks/unix/other/partition.rs @@ -84,7 +84,7 @@ fn partitions_iter() -> anyhow::Result> { })) } -#[allow(dead_code)] +#[expect(dead_code)] /// Returns a [`Vec`] containing all partitions. pub(crate) fn partitions() -> anyhow::Result> { partitions_iter().map(|iter| iter.collect()) diff --git a/src/data_collection/disks/unix/usage.rs b/src/data_collection/disks/unix/usage.rs index 8b78edb2..522bf032 100644 --- a/src/data_collection/disks/unix/usage.rs +++ b/src/data_collection/disks/unix/usage.rs @@ -2,7 +2,7 @@ pub struct Usage(libc::statvfs); // Note that x86 returns `u32` values while x86-64 returns `u64`s, so we convert // everything to `u64` for consistency. -#[allow(clippy::useless_conversion)] +#[expect(clippy::useless_conversion)] impl Usage { pub(crate) fn new(vfs: libc::statvfs) -> Self { Self(vfs) @@ -19,7 +19,7 @@ impl Usage { u64::from(self.0.f_bfree) * u64::from(self.0.f_frsize) } - #[allow(dead_code)] + #[expect(dead_code)] /// Returns the total number of bytes used. Equal to `total - available` on /// Unix. pub fn used(&self) -> u64 { diff --git a/src/data_collection/processes/linux.rs b/src/data_collection/processes/linux.rs index 6de841f1..2403f1fe 100644 --- a/src/data_collection/processes/linux.rs +++ b/src/data_collection/processes/linux.rs @@ -360,7 +360,7 @@ pub(crate) fn linux_process_data( let pid = process.pid; let prev_proc_details = pid_mapping.entry(pid).or_default(); - #[allow(unused_mut)] + #[cfg_attr(not(feature = "gpu"), expect(unused_mut))] if let Ok((mut process_harvest, new_process_times)) = read_proc(prev_proc_details, process, args, user_table) { diff --git a/src/data_collection/processes/macos/sysctl_bindings.rs b/src/data_collection/processes/macos/sysctl_bindings.rs index 53a7f3de..190e093c 100644 --- a/src/data_collection/processes/macos/sysctl_bindings.rs +++ b/src/data_collection/processes/macos/sysctl_bindings.rs @@ -12,14 +12,12 @@ use mach2::vm_types::user_addr_t; use crate::data_collection::Pid; -#[allow(non_camel_case_types)] #[repr(C)] pub(crate) struct kinfo_proc { pub kp_proc: extern_proc, pub kp_eproc: eproc, } -#[allow(non_camel_case_types)] #[repr(C)] #[derive(Copy, Clone)] pub struct p_st1 { @@ -28,7 +26,6 @@ pub struct p_st1 { p_back: user_addr_t, } -#[allow(non_camel_case_types)] #[repr(C)] pub union p_un { pub p_st1: p_st1, @@ -39,7 +36,6 @@ pub union p_un { /// Exported fields for kern sysctl. See /// [`proc.h`](https://opensource.apple.com/source/xnu/xnu-201/bsd/sys/proc.h) -#[allow(non_camel_case_types)] #[repr(C)] pub(crate) struct extern_proc { pub p_un: p_un, @@ -170,19 +166,18 @@ const WMESGLEN: usize = 7; const COMAPT_MAXLOGNAME: usize = 12; /// See `_caddr_t.h`. -#[allow(non_camel_case_types)] +#[expect(non_camel_case_types)] type caddr_t = *const libc::c_char; /// See `types.h`. -#[allow(non_camel_case_types)] +#[expect(non_camel_case_types)] type segsz_t = i32; /// See `types.h`. -#[allow(non_camel_case_types)] +#[expect(non_camel_case_types)] type fixpt_t = u32; /// See [`proc.h`](https://opensource.apple.com/source/xnu/xnu-201/bsd/sys/proc.h) -#[allow(non_camel_case_types)] #[repr(C)] pub(crate) struct pcred { pub pc_lock: [c_char; 72], @@ -195,7 +190,6 @@ pub(crate) struct pcred { } /// See `vm.h`. -#[allow(non_camel_case_types)] #[repr(C)] pub(crate) struct vmspace { pub dummy: i32, @@ -205,7 +199,6 @@ pub(crate) struct vmspace { } /// See [`sysctl.h`](https://opensource.apple.com/source/xnu/xnu-344/bsd/sys/sysctl.h). -#[allow(non_camel_case_types)] #[repr(C)] pub(crate) struct eproc { /// Address of proc. We just cheat and use a c_void pointer since we aren't diff --git a/src/main.rs b/src/main.rs index be079976..8dc2159e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ pub mod widgets; use std::{ boxed::Box, io::{stderr, stdout, Write}, - panic::{self, PanicInfo}, + panic::{self, PanicHookInfo}, sync::{ mpsc::{self, Receiver, Sender}, Arc, @@ -51,7 +51,7 @@ use event::{handle_key_event_or_break, handle_mouse_event, BottomEvent, Collecti use options::{args, get_or_create_config, init_app}; use tui::{backend::CrosstermBackend, Terminal}; use utils::cancellation_token::CancellationToken; -#[allow(unused_imports)] +#[allow(unused_imports, reason = "this is needed if logging is enabled")] use utils::logging::*; // Used for heap allocation debugging purposes. @@ -103,7 +103,7 @@ fn check_if_terminal() { /// A panic hook to properly restore the terminal in the case of a panic. /// Originally based on [spotify-tui's implementation](https://github.com/Rigellute/spotify-tui/blob/master/src/main.rs). -fn panic_hook(panic_info: &PanicInfo<'_>) { +fn panic_hook(panic_info: &PanicHookInfo<'_>) { let mut stdout = stdout(); let msg = match panic_info.payload().downcast_ref::<&'static str>() { diff --git a/src/options.rs b/src/options.rs index f051fca4..9ec5cd5d 100644 --- a/src/options.rs +++ b/src/options.rs @@ -811,29 +811,31 @@ fn get_default_widget_and_count( } } -#[allow(unused_variables)] +#[cfg(feature = "battery")] fn get_use_battery(args: &BottomArgs, config: &Config) -> bool { - #[cfg(feature = "battery")] - { - // TODO: Move this so it's dynamic in the app itself and automatically hide if - // there are no batteries? - if let Ok(battery_manager) = Manager::new() { - if let Ok(batteries) = battery_manager.batteries() { - if batteries.count() == 0 { - return false; - } - } - } - - if args.battery.battery { - return true; - } else if let Some(flags) = &config.flags { - if let Some(battery) = flags.battery { - return battery; + // TODO: Move this so it's dynamic in the app itself and automatically hide if + // there are no batteries? + if let Ok(battery_manager) = Manager::new() { + if let Ok(batteries) = battery_manager.batteries() { + if batteries.count() == 0 { + return false; } } } + if args.battery.battery { + return true; + } else if let Some(flags) = &config.flags { + if let Some(battery) = flags.battery { + return battery; + } + } + + false +} + +#[cfg(not(feature = "battery"))] +fn get_use_battery(_args: &BottomArgs, _config: &Config) -> bool { false } @@ -855,22 +857,24 @@ fn get_enable_gpu(_: &BottomArgs, _: &Config) -> bool { false } -#[allow(unused_variables)] +#[cfg(not(target_os = "windows"))] fn get_enable_cache_memory(args: &BottomArgs, config: &Config) -> bool { - #[cfg(not(target_os = "windows"))] - { - if args.memory.enable_cache_memory { - return true; - } else if let Some(flags) = &config.flags { - if let Some(enable_cache_memory) = flags.enable_cache_memory { - return enable_cache_memory; - } + if args.memory.enable_cache_memory { + return true; + } else if let Some(flags) = &config.flags { + if let Some(enable_cache_memory) = flags.enable_cache_memory { + return enable_cache_memory; } } false } +#[cfg(target_os = "windows")] +fn get_enable_cache_memory(_args: &BottomArgs, _config: &Config) -> bool { + false +} + fn get_ignore_list(ignore_list: &Option) -> OptionResult> { if let Some(ignore_list) = ignore_list { let list: Result, _> = ignore_list