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
This commit is contained in:
Clement Tsang 2024-11-01 13:51:12 -04:00 committed by GitHub
parent f2e329b00a
commit 776f8cb3d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 57 additions and 59 deletions

View file

@ -38,7 +38,7 @@ exclude = [
"rustfmt.toml", "rustfmt.toml",
] ]
# The oldest version I've tested that should still build - note this is not an official MSRV! # 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]] [[bin]]
name = "btm" name = "btm"

View file

@ -1,4 +1,4 @@
#[allow(dead_code)] #[expect(dead_code)]
#[path = "src/options/args.rs"] #[path = "src/options/args.rs"]
mod args; mod args;

View file

@ -206,8 +206,10 @@ impl DataCollection {
self.timed_data_vec.shrink_to_fit(); self.timed_data_vec.shrink_to_fit();
} }
// Clippy allow to avoid warning on certain platforms (e.g. 32-bit). #[allow(
#[allow(clippy::boxed_local)] 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<Data>) { pub fn eat_data(&mut self, harvested_data: Box<Data>) {
let harvested_time = harvested_data.collection_time; let harvested_time = harvested_data.collection_time;
let mut new_entry = TimedData::default(); let mut new_entry = TimedData::default();

View file

@ -19,7 +19,7 @@ type ColumnMappings = (u32, BTreeMap<LineSegment, ColumnRowMappings>);
impl BottomLayout { impl BottomLayout {
pub fn get_movement_mappings(&mut self) { 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 { fn is_intersecting(a: LineSegment, b: LineSegment) -> bool {
a.0 >= b.0 && a.1 <= b.1 a.0 >= b.0 && a.1 <= b.1
|| a.1 >= b.1 && a.0 <= b.0 || a.1 >= b.1 && a.0 <= b.0

View file

@ -126,7 +126,7 @@ impl<DataType: DataToCell<H>, H: ColumnHeader, S: SortType, C: DataTableColumn<H
} }
/// Updates the scroll position to a selected index. /// Updates the scroll position to a selected index.
#[allow(clippy::comparison_chain)] #[expect(clippy::comparison_chain)]
pub fn set_position(&mut self, new_index: usize) { pub fn set_position(&mut self, new_index: usize) {
let new_index = new_index.clamp_upper(self.data.len().saturating_sub(1)); let new_index = new_index.clamp_upper(self.data.len().saturating_sub(1));
if self.state.current_index < new_index { if self.state.current_index < new_index {

View file

@ -29,7 +29,6 @@ struct FileSystem {
pub fn get_io_usage() -> CollectionResult<IoHarvest> { pub fn get_io_usage() -> CollectionResult<IoHarvest> {
// TODO: Should this (and other I/O collectors) fail fast? In general, should // TODO: Should this (and other I/O collectors) fail fast? In general, should
// collection ever fail fast? // collection ever fail fast?
#[allow(unused_mut)]
let mut io_harvest: HashMap<String, Option<IoData>> = let mut io_harvest: HashMap<String, Option<IoData>> =
get_disk_info().map(|storage_system_information| { get_disk_info().map(|storage_system_information| {
storage_system_information storage_system_information

View file

@ -88,7 +88,7 @@ impl FileSystem {
matches!(self, FileSystem::Other(..)) matches!(self, FileSystem::Other(..))
} }
#[allow(dead_code)] #[expect(dead_code)]
#[inline] #[inline]
/// Returns a string literal identifying this filesystem. /// Returns a string literal identifying this filesystem.
pub fn as_str(&self) -> &str { pub fn as_str(&self) -> &str {

View file

@ -138,7 +138,7 @@ impl FromStr for Partition {
} }
} }
#[allow(dead_code)] #[expect(dead_code)]
/// Returns a [`Vec`] containing all partitions. /// Returns a [`Vec`] containing all partitions.
pub(crate) fn partitions() -> anyhow::Result<Vec<Partition>> { pub(crate) fn partitions() -> anyhow::Result<Vec<Partition>> {
const PROC_MOUNTS: &str = "/proc/mounts"; const PROC_MOUNTS: &str = "/proc/mounts";

View file

@ -12,24 +12,24 @@ use core_foundation::{
use libc::c_char; use libc::c_char;
use mach2::{kern_return::kern_return_t, port::MACH_PORT_NULL}; 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; 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; 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 io_registry_entry_t = io_object_t;
pub type IOOptionBits = u32; pub type IOOptionBits = u32;
/// See https://github.com/1kc/librazermacos/pull/27#issuecomment-1042368531. /// 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; 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"; pub const kIOServicePlane: &str = "IOService\0";
#[allow(non_upper_case_globals)] #[expect(non_upper_case_globals)]
pub const kIOMediaClass: &str = "IOMedia\0"; pub const kIOMediaClass: &str = "IOMedia\0";
// See [here](https://developer.apple.com/documentation/iokit) for more details. // See [here](https://developer.apple.com/documentation/iokit) for more details.

View file

@ -84,7 +84,7 @@ fn partitions_iter() -> anyhow::Result<impl Iterator<Item = Partition>> {
})) }))
} }
#[allow(dead_code)] #[expect(dead_code)]
/// Returns a [`Vec`] containing all partitions. /// Returns a [`Vec`] containing all partitions.
pub(crate) fn partitions() -> anyhow::Result<Vec<Partition>> { pub(crate) fn partitions() -> anyhow::Result<Vec<Partition>> {
partitions_iter().map(|iter| iter.collect()) partitions_iter().map(|iter| iter.collect())

View file

@ -2,7 +2,7 @@ pub struct Usage(libc::statvfs);
// Note that x86 returns `u32` values while x86-64 returns `u64`s, so we convert // Note that x86 returns `u32` values while x86-64 returns `u64`s, so we convert
// everything to `u64` for consistency. // everything to `u64` for consistency.
#[allow(clippy::useless_conversion)] #[expect(clippy::useless_conversion)]
impl Usage { impl Usage {
pub(crate) fn new(vfs: libc::statvfs) -> Self { pub(crate) fn new(vfs: libc::statvfs) -> Self {
Self(vfs) Self(vfs)
@ -19,7 +19,7 @@ impl Usage {
u64::from(self.0.f_bfree) * u64::from(self.0.f_frsize) 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 /// Returns the total number of bytes used. Equal to `total - available` on
/// Unix. /// Unix.
pub fn used(&self) -> u64 { pub fn used(&self) -> u64 {

View file

@ -360,7 +360,7 @@ pub(crate) fn linux_process_data(
let pid = process.pid; let pid = process.pid;
let prev_proc_details = pid_mapping.entry(pid).or_default(); 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)) = if let Ok((mut process_harvest, new_process_times)) =
read_proc(prev_proc_details, process, args, user_table) read_proc(prev_proc_details, process, args, user_table)
{ {

View file

@ -12,14 +12,12 @@ use mach2::vm_types::user_addr_t;
use crate::data_collection::Pid; use crate::data_collection::Pid;
#[allow(non_camel_case_types)]
#[repr(C)] #[repr(C)]
pub(crate) struct kinfo_proc { pub(crate) struct kinfo_proc {
pub kp_proc: extern_proc, pub kp_proc: extern_proc,
pub kp_eproc: eproc, pub kp_eproc: eproc,
} }
#[allow(non_camel_case_types)]
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct p_st1 { pub struct p_st1 {
@ -28,7 +26,6 @@ pub struct p_st1 {
p_back: user_addr_t, p_back: user_addr_t,
} }
#[allow(non_camel_case_types)]
#[repr(C)] #[repr(C)]
pub union p_un { pub union p_un {
pub p_st1: p_st1, pub p_st1: p_st1,
@ -39,7 +36,6 @@ pub union p_un {
/// Exported fields for kern sysctl. See /// Exported fields for kern sysctl. See
/// [`proc.h`](https://opensource.apple.com/source/xnu/xnu-201/bsd/sys/proc.h) /// [`proc.h`](https://opensource.apple.com/source/xnu/xnu-201/bsd/sys/proc.h)
#[allow(non_camel_case_types)]
#[repr(C)] #[repr(C)]
pub(crate) struct extern_proc { pub(crate) struct extern_proc {
pub p_un: p_un, pub p_un: p_un,
@ -170,19 +166,18 @@ const WMESGLEN: usize = 7;
const COMAPT_MAXLOGNAME: usize = 12; const COMAPT_MAXLOGNAME: usize = 12;
/// See `_caddr_t.h`. /// See `_caddr_t.h`.
#[allow(non_camel_case_types)] #[expect(non_camel_case_types)]
type caddr_t = *const libc::c_char; type caddr_t = *const libc::c_char;
/// See `types.h`. /// See `types.h`.
#[allow(non_camel_case_types)] #[expect(non_camel_case_types)]
type segsz_t = i32; type segsz_t = i32;
/// See `types.h`. /// See `types.h`.
#[allow(non_camel_case_types)] #[expect(non_camel_case_types)]
type fixpt_t = u32; type fixpt_t = u32;
/// See [`proc.h`](https://opensource.apple.com/source/xnu/xnu-201/bsd/sys/proc.h) /// See [`proc.h`](https://opensource.apple.com/source/xnu/xnu-201/bsd/sys/proc.h)
#[allow(non_camel_case_types)]
#[repr(C)] #[repr(C)]
pub(crate) struct pcred { pub(crate) struct pcred {
pub pc_lock: [c_char; 72], pub pc_lock: [c_char; 72],
@ -195,7 +190,6 @@ pub(crate) struct pcred {
} }
/// See `vm.h`. /// See `vm.h`.
#[allow(non_camel_case_types)]
#[repr(C)] #[repr(C)]
pub(crate) struct vmspace { pub(crate) struct vmspace {
pub dummy: i32, 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). /// See [`sysctl.h`](https://opensource.apple.com/source/xnu/xnu-344/bsd/sys/sysctl.h).
#[allow(non_camel_case_types)]
#[repr(C)] #[repr(C)]
pub(crate) struct eproc { pub(crate) struct eproc {
/// Address of proc. We just cheat and use a c_void pointer since we aren't /// Address of proc. We just cheat and use a c_void pointer since we aren't

View file

@ -27,7 +27,7 @@ pub mod widgets;
use std::{ use std::{
boxed::Box, boxed::Box,
io::{stderr, stdout, Write}, io::{stderr, stdout, Write},
panic::{self, PanicInfo}, panic::{self, PanicHookInfo},
sync::{ sync::{
mpsc::{self, Receiver, Sender}, mpsc::{self, Receiver, Sender},
Arc, 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 options::{args, get_or_create_config, init_app};
use tui::{backend::CrosstermBackend, Terminal}; use tui::{backend::CrosstermBackend, Terminal};
use utils::cancellation_token::CancellationToken; use utils::cancellation_token::CancellationToken;
#[allow(unused_imports)] #[allow(unused_imports, reason = "this is needed if logging is enabled")]
use utils::logging::*; use utils::logging::*;
// Used for heap allocation debugging purposes. // 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. /// 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). /// 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 mut stdout = stdout();
let msg = match panic_info.payload().downcast_ref::<&'static str>() { let msg = match panic_info.payload().downcast_ref::<&'static str>() {

View file

@ -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 { 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?
// TODO: Move this so it's dynamic in the app itself and automatically hide if if let Ok(battery_manager) = Manager::new() {
// there are no batteries? if let Ok(batteries) = battery_manager.batteries() {
if let Ok(battery_manager) = Manager::new() { if batteries.count() == 0 {
if let Ok(batteries) = battery_manager.batteries() { return false;
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;
} }
} }
} }
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 false
} }
@ -855,22 +857,24 @@ fn get_enable_gpu(_: &BottomArgs, _: &Config) -> bool {
false false
} }
#[allow(unused_variables)] #[cfg(not(target_os = "windows"))]
fn get_enable_cache_memory(args: &BottomArgs, config: &Config) -> bool { fn get_enable_cache_memory(args: &BottomArgs, config: &Config) -> bool {
#[cfg(not(target_os = "windows"))] if args.memory.enable_cache_memory {
{ return true;
if args.memory.enable_cache_memory { } else if let Some(flags) = &config.flags {
return true; if let Some(enable_cache_memory) = flags.enable_cache_memory {
} else if let Some(flags) = &config.flags { return enable_cache_memory;
if let Some(enable_cache_memory) = flags.enable_cache_memory {
return enable_cache_memory;
}
} }
} }
false false
} }
#[cfg(target_os = "windows")]
fn get_enable_cache_memory(_args: &BottomArgs, _config: &Config) -> bool {
false
}
fn get_ignore_list(ignore_list: &Option<IgnoreList>) -> OptionResult<Option<Filter>> { fn get_ignore_list(ignore_list: &Option<IgnoreList>) -> OptionResult<Option<Filter>> {
if let Some(ignore_list) = ignore_list { if let Some(ignore_list) = ignore_list {
let list: Result<Vec<_>, _> = ignore_list let list: Result<Vec<_>, _> = ignore_list