Safe Transmute: Refactor error handling and Answer type

- Create `Answer` type that is not just a type alias of `Result`
- Remove a usage of `map_layouts` to make the code easier to read
- Don't hide errors related to Unknown Layout when computing transmutability
This commit is contained in:
Bryan Garza
2023-06-12 16:35:23 -07:00
parent 64a54df86f
commit f4cf8f65a5
9 changed files with 166 additions and 126 deletions

View File

@@ -668,6 +668,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
scope: Ty<'tcx>,
assume: rustc_transmute::Assume,
) -> Result<Certainty, NoSolution> {
use rustc_transmute::Answer;
// FIXME(transmutability): This really should be returning nested goals for `Answer::If*`
match rustc_transmute::TransmuteTypeEnv::new(self.infcx).is_transmutable(
ObligationCause::dummy(),
@@ -675,11 +676,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
scope,
assume,
) {
Ok(None) => Ok(Certainty::Yes),
Err(_)
| Ok(Some(rustc_transmute::Condition::IfTransmutable { .. }))
| Ok(Some(rustc_transmute::Condition::IfAll(_)))
| Ok(Some(rustc_transmute::Condition::IfAny(_))) => Err(NoSolution),
Answer::Yes => Ok(Certainty::Yes),
Answer::No(_) | Answer::If(_) => Err(NoSolution),
}
}
}