Skip to content

Commit

Permalink
Drop use of unstable try_trait_v2 feature
Browse files Browse the repository at this point in the history
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.

#452
  • Loading branch information
nicholasbishop committed Sep 1, 2022
1 parent 02e02d4 commit ab13149
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 48 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
6 changes: 3 additions & 3 deletions src/proto/shim/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ impl ShimLock {
.map_err(|_| Error::from(Status::BAD_BUFFER_SIZE))?;

let mut context = MaybeUninit::<Context>::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()
}
}
45 changes: 1 addition & 44 deletions src/result/status.rs
Original file line number Diff line number Diff line change
@@ -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::<usize>() * 8 - 1);
Expand Down Expand Up @@ -172,45 +168,6 @@ impl From<Status> for Result<(), ()> {
}
}

pub struct StatusResidual(NonZeroUsize);

impl Try for Status {
type Output = ();
type Residual = StatusResidual;

fn branch(self) -> ControlFlow<Self::Residual, Self::Output> {
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<T> FromResidual<StatusResidual> for Result<T, ()> {
fn from_residual(r: StatusResidual) -> Self {
Err(Status(r.0.into()).into())
}
}

impl FromResidual<core::result::Result<Infallible, Error>> for Status {
fn from_residual(r: core::result::Result<Infallible, Error>) -> Self {
match r {
Err(err) => err.status(),
Ok(infallible) => match infallible {},
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit ab13149

Please sign in to comment.