Skip to content

Drop use of unstable try_trait_v2 feature #479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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