1
Fork 0

Safe Transmute: Change Answer type to Result

This patch updates the `Answer` type from `rustc_transmute` so that it just a
type alias to `Result`. This makes it so that the standard methods for `Result`
can be used to process the `Answer` tree, including being able to make use of
the `?` operator on `Answer`s.

Also, remove some unused functions
This commit is contained in:
Bryan Garza 2023-04-27 14:38:32 -07:00
parent 8f1cec8d84
commit 263a4f2cb6
6 changed files with 113 additions and 140 deletions

View file

@ -19,15 +19,12 @@ pub struct Assume {
pub validity: bool,
}
/// The type encodes answers to the question: "Are these types transmutable?"
#[derive(Debug, Hash, Eq, PartialEq, PartialOrd, Ord, Clone)]
pub enum Answer<R> {
/// `Src` is transmutable into `Dst`.
Yes,
/// `Src` is NOT transmutable into `Dst`.
No(Reason),
/// Either we have an error, or we have an optional Condition that must hold.
pub type Answer<R> = Result<Option<Condition<R>>, Reason>;
/// A condition which must hold for safe transmutation to be possible
#[derive(Debug, Hash, Eq, PartialEq, Clone)]
pub enum Condition<R> {
/// `Src` is transmutable into `Dst`, if `src` is transmutable into `dst`.
IfTransmutable { src: R, dst: R },