Skip to content

Commit fbfe833

Browse files
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. rust-osdev#452
1 parent 02e02d4 commit fbfe833

File tree

4 files changed

+8
-48
lines changed

4 files changed

+8
-48
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
other than 1. A safe alternative is to use
4444
[`Vec::into_boxed_slice`](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.into_boxed_slice).
4545
- Removed `From` conversions from `ucs2::Error` to `Status` and `Error`.
46+
- Removed use of the unstable `try_trait_v2` feature, which allowed `?`
47+
to be used with `Status` in a function returning `uefi::Result`. This
48+
can be replaced by calling `status.into()`, or `Result::from(status)`
49+
in cases where the compiler needs a type hint.
4650

4751
## uefi-macros - [Unreleased]
4852

src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
//! For example, a PC with no network card might not contain a network driver,
2424
//! therefore all the network protocols will be unavailable.
2525
26-
#![feature(try_trait_v2)]
2726
#![feature(abi_efiapi)]
2827
#![feature(maybe_uninit_slice)]
2928
#![feature(negative_impls)]

src/proto/shim/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ impl ShimLock {
108108
.map_err(|_| Error::from(Status::BAD_BUFFER_SIZE))?;
109109

110110
let mut context = MaybeUninit::<Context>::uninit();
111-
(self.context)(ptr, size, context.as_mut_ptr())?;
111+
Result::from((self.context)(ptr, size, context.as_mut_ptr()))?;
112112
(self.hash)(
113113
ptr,
114114
size,
115115
context.as_mut_ptr(),
116116
&mut hashes.sha256,
117117
&mut hashes.sha1,
118-
)?;
119-
Ok(())
118+
)
119+
.into()
120120
}
121121
}

src/result/status.rs

+1-44
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
use super::{Error, Result};
2-
use core::{
3-
convert::Infallible,
4-
ops::{ControlFlow, FromResidual, Try},
5-
};
6-
use core::{fmt::Debug, num::NonZeroUsize};
2+
use core::fmt::Debug;
73

84
/// Bit indicating that an UEFI status code is an error
95
const ERROR_BIT: usize = 1 << (core::mem::size_of::<usize>() * 8 - 1);
@@ -172,45 +168,6 @@ impl From<Status> for Result<(), ()> {
172168
}
173169
}
174170

175-
pub struct StatusResidual(NonZeroUsize);
176-
177-
impl Try for Status {
178-
type Output = ();
179-
type Residual = StatusResidual;
180-
181-
fn branch(self) -> ControlFlow<Self::Residual, Self::Output> {
182-
match NonZeroUsize::new(self.0) {
183-
Some(r) => ControlFlow::Break(StatusResidual(r)),
184-
None => ControlFlow::Continue(()),
185-
}
186-
}
187-
188-
fn from_output(_output: Self::Output) -> Self {
189-
Self::SUCCESS
190-
}
191-
}
192-
193-
impl FromResidual for Status {
194-
fn from_residual(r: StatusResidual) -> Self {
195-
Status(r.0.into())
196-
}
197-
}
198-
199-
impl<T> FromResidual<StatusResidual> for Result<T, ()> {
200-
fn from_residual(r: StatusResidual) -> Self {
201-
Err(Status(r.0.into()).into())
202-
}
203-
}
204-
205-
impl FromResidual<core::result::Result<Infallible, Error>> for Status {
206-
fn from_residual(r: core::result::Result<Infallible, Error>) -> Self {
207-
match r {
208-
Err(err) => err.status(),
209-
Ok(infallible) => match infallible {},
210-
}
211-
}
212-
}
213-
214171
#[cfg(test)]
215172
mod tests {
216173
use super::*;

0 commit comments

Comments
 (0)