Skip to content

Commit

Permalink
refactor: bump 'msrv' to 1.81 and update deprecated code (#1615)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ClementTsang authored Nov 1, 2024
1 parent f2e329b commit 776f8cb
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[allow(dead_code)]
#[expect(dead_code)]
#[path = "src/options/args.rs"]
mod args;

Expand Down
6 changes: 4 additions & 2 deletions src/app/data_farmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Data>) {
let harvested_time = harvested_data.collection_time;
let mut new_entry = TimedData::default();
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type ColumnMappings = (u32, BTreeMap<LineSegment, ColumnRowMappings>);

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
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/components/data_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl<DataType: DataToCell<H>, H: ColumnHeader, S: SortType, C: DataTableColumn<H
}

/// 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) {
let new_index = new_index.clamp_upper(self.data.len().saturating_sub(1));
if self.state.current_index < new_index {
Expand Down
1 change: 0 additions & 1 deletion src/data_collection/disks/freebsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ struct FileSystem {
pub fn get_io_usage() -> CollectionResult<IoHarvest> {
// 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<String, Option<IoData>> =
get_disk_info().map(|storage_system_information| {
storage_system_information
Expand Down
2 changes: 1 addition & 1 deletion src/data_collection/disks/unix/file_systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/data_collection/disks/unix/linux/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<Partition>> {
const PROC_MOUNTS: &str = "/proc/mounts";
Expand Down
12 changes: 6 additions & 6 deletions src/data_collection/disks/unix/macos/io_kit/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/data_collection/disks/unix/other/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
pub(crate) fn partitions() -> anyhow::Result<Vec<Partition>> {
partitions_iter().map(|iter| iter.collect())
Expand Down
4 changes: 2 additions & 2 deletions src/data_collection/disks/unix/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/data_collection/processes/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
13 changes: 3 additions & 10 deletions src/data_collection/processes/macos/sysctl_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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],
Expand All @@ -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,
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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>() {
Expand Down
54 changes: 29 additions & 25 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,32 +811,34 @@ 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;
}
// 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;
}
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
}

#[cfg(feature = "gpu")]
fn get_enable_gpu(args: &BottomArgs, config: &Config) -> bool {
if args.gpu.disable_gpu {
Expand All @@ -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<IgnoreList>) -> OptionResult<Option<Filter>> {
if let Some(ignore_list) = ignore_list {
let list: Result<Vec<_>, _> = ignore_list
Expand Down

0 comments on commit 776f8cb

Please sign in to comment.