From 25c08ad2476e90af36ecf4e223f6961d71b53bec Mon Sep 17 00:00:00 2001 From: Maximiliano Sandoval Date: Tue, 4 Mar 2025 15:40:47 +0100 Subject: [PATCH] sys: add variable bindings for temporaries in unsafe blocks These will produce an error in edition 2024 otherwise. The reason this is needed is because the `unsafe` block has its own scope. The bytes were defined inside of the let-mut block to preserve the lifetime they had before this commit. Signed-off-by: Maximiliano Sandoval --- proxmox-sys/src/linux/procfs/mod.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/proxmox-sys/src/linux/procfs/mod.rs b/proxmox-sys/src/linux/procfs/mod.rs index 3b25ce70..a1758bc0 100644 --- a/proxmox-sys/src/linux/procfs/mod.rs +++ b/proxmox-sys/src/linux/procfs/mod.rs @@ -228,9 +228,10 @@ static PROC_LAST_STAT: LazyLock> = pub fn read_proc_stat() -> Result { let sample_time = Instant::now(); let update_duration; - let mut stat = - parse_proc_stat(unsafe { std::str::from_utf8_unchecked(&std::fs::read("/proc/stat")?) }) - .unwrap(); + let mut stat = { + let bytes = std::fs::read("/proc/stat")?; + parse_proc_stat(unsafe { std::str::from_utf8_unchecked(&bytes) }).unwrap() + }; { // read lock scope @@ -755,7 +756,8 @@ pub struct Loadavg(pub f64, pub f64, pub f64); impl Loadavg { /// Read the load avage from `/proc/loadavg`. pub fn read() -> Result { - Self::parse(unsafe { std::str::from_utf8_unchecked(&std::fs::read("/proc/loadavg")?) }) + let bytes = std::fs::read("/proc/loadavg")?; + Self::parse(unsafe { std::str::from_utf8_unchecked(&bytes) }) } /// Parse the value triplet.