1
Fork 0

Reduce boilerplate around infallible folders

This commit is contained in:
Alan Egerton 2021-12-01 00:55:57 +00:00
parent db7295fa96
commit bfc434b6d0
No known key found for this signature in database
GPG key ID: 07CAC3CCA7E0643F
41 changed files with 898 additions and 727 deletions

View file

@ -1,7 +1,7 @@
use crate::traits;
use crate::traits::project::Normalized;
use rustc_middle::ty;
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
use rustc_middle::ty::fold::{TypeFoldable, TypeFolderFallible, TypeVisitor};
use std::fmt;
use std::ops::ControlFlow;
@ -60,12 +60,15 @@ impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> {
// TypeFoldable implementations.
impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx, O> {
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
fn try_super_fold_with<F: TypeFolderFallible<'tcx>>(
self,
folder: &mut F,
) -> Result<Self, F::Error> {
Ok(traits::Obligation {
cause: self.cause,
recursion_depth: self.recursion_depth,
predicate: self.predicate.fold_with(folder)?,
param_env: self.param_env.fold_with(folder)?,
predicate: self.predicate.try_fold_with(folder)?,
param_env: self.param_env.try_fold_with(folder)?,
})
}