From fbfe833a0dc369f18df66eadfcbbd19d992342df Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Sun, 7 Aug 2022 15:01:55 -0400 Subject: [PATCH] Drop use of unstable try_trait_v2 feature It seems like there's still a fair amount of discussion around what the Try API should look like in the tracking issue for try_trait_v2. This could lead to the API being changed in the nightly compiler, and breaking uefi-rs compilation (which is particularly annoying when using a released version rather than the latest git version). To avoid that possibility, just drop the feature as it is not much used in uefi-rs and can easily be replaced. As described in the changelog, most uses can be fixed by adding a call to `into()`. If the compiler needs a bit more help, `Result::from(status)` can be used. https://github.com/rust-osdev/uefi-rs/issues/452 --- CHANGELOG.md | 4 ++++ src/lib.rs | 1 - src/proto/shim/mod.rs | 6 +++--- src/result/status.rs | 45 +------------------------------------------ 4 files changed, 8 insertions(+), 48 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b3d7608b..6b337d490 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,10 @@ other than 1. A safe alternative is to use [`Vec::into_boxed_slice`](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.into_boxed_slice). - Removed `From` conversions from `ucs2::Error` to `Status` and `Error`. +- Removed use of the unstable `try_trait_v2` feature, which allowed `?` + to be used with `Status` in a function returning `uefi::Result`. This + can be replaced by calling `status.into()`, or `Result::from(status)` + in cases where the compiler needs a type hint. ## uefi-macros - [Unreleased] diff --git a/src/lib.rs b/src/lib.rs index 79f55fd13..510e63756 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,7 +23,6 @@ //! For example, a PC with no network card might not contain a network driver, //! therefore all the network protocols will be unavailable. -#![feature(try_trait_v2)] #![feature(abi_efiapi)] #![feature(maybe_uninit_slice)] #![feature(negative_impls)] diff --git a/src/proto/shim/mod.rs b/src/proto/shim/mod.rs index a7f0bc2d7..c2a52b604 100644 --- a/src/proto/shim/mod.rs +++ b/src/proto/shim/mod.rs @@ -108,14 +108,14 @@ impl ShimLock { .map_err(|_| Error::from(Status::BAD_BUFFER_SIZE))?; let mut context = MaybeUninit::::uninit(); - (self.context)(ptr, size, context.as_mut_ptr())?; + Result::from((self.context)(ptr, size, context.as_mut_ptr()))?; (self.hash)( ptr, size, context.as_mut_ptr(), &mut hashes.sha256, &mut hashes.sha1, - )?; - Ok(()) + ) + .into() } } diff --git a/src/result/status.rs b/src/result/status.rs index 45391e9c7..53c0f8117 100644 --- a/src/result/status.rs +++ b/src/result/status.rs @@ -1,9 +1,5 @@ use super::{Error, Result}; -use core::{ - convert::Infallible, - ops::{ControlFlow, FromResidual, Try}, -}; -use core::{fmt::Debug, num::NonZeroUsize}; +use core::fmt::Debug; /// Bit indicating that an UEFI status code is an error const ERROR_BIT: usize = 1 << (core::mem::size_of::() * 8 - 1); @@ -172,45 +168,6 @@ impl From for Result<(), ()> { } } -pub struct StatusResidual(NonZeroUsize); - -impl Try for Status { - type Output = (); - type Residual = StatusResidual; - - fn branch(self) -> ControlFlow { - match NonZeroUsize::new(self.0) { - Some(r) => ControlFlow::Break(StatusResidual(r)), - None => ControlFlow::Continue(()), - } - } - - fn from_output(_output: Self::Output) -> Self { - Self::SUCCESS - } -} - -impl FromResidual for Status { - fn from_residual(r: StatusResidual) -> Self { - Status(r.0.into()) - } -} - -impl FromResidual for Result { - fn from_residual(r: StatusResidual) -> Self { - Err(Status(r.0.into()).into()) - } -} - -impl FromResidual> for Status { - fn from_residual(r: core::result::Result) -> Self { - match r { - Err(err) => err.status(), - Ok(infallible) => match infallible {}, - } - } -} - #[cfg(test)] mod tests { use super::*;