diff --git a/rust/pv_core/src/uvdevice.rs b/rust/pv_core/src/uvdevice.rs index 3e6529a8..023015e4 100644 --- a/rust/pv_core/src/uvdevice.rs +++ b/rust/pv_core/src/uvdevice.rs @@ -53,7 +53,7 @@ fn ioctl_raw(raw_fd: RawFd, cmd: u64, cb: &mut IoctlCb) -> Result<()> { // SAFETY: the passed pointer points to a valid memory region that // contains the expected C-struct. The struct outlives this function. unsafe { - rc = ioctl(raw_fd, cmd.try_into().unwrap(), cb.as_ptr_mut()); + rc = ioctl(raw_fd, cmd, cb.as_ptr_mut()); } // NOTE io::Error handles all errnos ioctl uses diff --git a/rust/pvapconfig/src/ap.rs b/rust/pvapconfig/src/ap.rs index 76798e26..23d2190b 100644 --- a/rust/pvapconfig/src/ap.rs +++ b/rust/pvapconfig/src/ap.rs @@ -174,7 +174,7 @@ impl ApqnList { /// Sort this Apqnlist by card generation: /// newest generation first, older generations last. pub fn sort_by_gen(&mut self) { - self.0.sort_unstable_by(|a, b| b.gen.cmp(&a.gen)); + self.0.sort_unstable_by_key(|b| std::cmp::Reverse(b.gen)); } /// Check MK restriction diff --git a/rust/pvapconfig/src/main.rs b/rust/pvapconfig/src/main.rs index f967e7b9..f0b2ca9f 100644 --- a/rust/pvapconfig/src/main.rs +++ b/rust/pvapconfig/src/main.rs @@ -51,8 +51,8 @@ macro_rules! println_and_exit_failure { /// returns with exit failure. macro_rules! on_error_print_and_exit { ($r:expr) => { - if $r.is_err() { - eprintln!("{}", $r.unwrap_err()); + if let Err(e) = $r { + eprintln!("{}", e); return ExitCode::FAILURE; } }; diff --git a/rust/pvimg/examples/create-sehdr/main.rs b/rust/pvimg/examples/create-sehdr/main.rs index 6bb170a1..abc13885 100644 --- a/rust/pvimg/examples/create-sehdr/main.rs +++ b/rust/pvimg/examples/create-sehdr/main.rs @@ -176,7 +176,7 @@ fn main() -> anyhow::Result<()> { let mut secure_comp_builer = SecuredComponentBuilder::new_v1(false)?; // Sort components by address in ascending order - args.components.sort_by(|a, b| a.addr.cmp(&b.addr)); + args.components.sort_by_key(|a| a.addr); for component_arg in args.components { info!("## Preparing {}", component_arg); let mut comp = Comp { diff --git a/rust/pvimg/src/se_img_comps/bootloader/ipl.rs b/rust/pvimg/src/se_img_comps/bootloader/ipl.rs index 66519681..584e83b2 100644 --- a/rust/pvimg/src/se_img_comps/bootloader/ipl.rs +++ b/rust/pvimg/src/se_img_comps/bootloader/ipl.rs @@ -92,9 +92,7 @@ use std::iter; impl ipl_parameter_block { pub fn size(num_comp: usize) -> Result { - let comps = iter::repeat(ipl_pb0_pv_comp::default()) - .take(num_comp) - .collect(); + let comps = std::iter::repeat_n(ipl_pb0_pv_comp::default(), num_comp).collect(); let ipib = Self { pv: ipl_pb0_pv { components: comps, @@ -110,7 +108,7 @@ impl ipl_parameter_block { impl ipl_pb0_pv { pub fn size(num_comp: usize) -> Result { let comp = ipl_pb0_pv_comp::default(); - let comps = iter::repeat(comp).take(num_comp).collect(); + let comps = std::iter::repeat_n(comp, num_comp).collect(); let ipl = Self { components: comps, ..Default::default() diff --git a/rust/utils/src/hostname.rs b/rust/utils/src/hostname.rs index 5bcb4658..1ff91dac 100644 --- a/rust/utils/src/hostname.rs +++ b/rust/utils/src/hostname.rs @@ -57,7 +57,7 @@ pub fn gethostname() -> io::Result { } } - assert!(isize::try_from(buf_len).unwrap() <= isize::MAX); + assert!(buf_len <= isize::MAX as usize); // SAFETY: We made sure that `buf` is: // 1. NUL-terminated