1
Fork 0

Make TypeFoldable implementors short-circuit on error

Co-authored-by: Alan Egerton <eggyal@gmail.com>
This commit is contained in:
LeSeulArtichaut 2021-05-19 13:34:54 +02:00 committed by Alan Egerton
parent c5f0d0ebb4
commit 6e3fa20b00
No known key found for this signature in database
GPG key ID: 07CAC3CCA7E0643F
11 changed files with 299 additions and 204 deletions

View file

@ -55,8 +55,8 @@ macro_rules! TrivialTypeFoldableImpls {
fn super_fold_with<F: $crate::ty::fold::TypeFolder<$tcx>>(
self,
_: &mut F
) -> $ty {
self
) -> ::std::result::Result<$ty, F::Error> {
Ok(self)
}
fn super_visit_with<F: $crate::ty::fold::TypeVisitor<$tcx>>(
@ -98,7 +98,7 @@ macro_rules! EnumTypeFoldableImpl {
fn super_fold_with<V: $crate::ty::fold::TypeFolder<$tcx>>(
self,
folder: &mut V,
) -> Self {
) -> ::std::result::Result<Self, V::Error> {
EnumTypeFoldableImpl!(@FoldVariants(self, folder) input($($variants)*) output())
}
@ -112,9 +112,9 @@ macro_rules! EnumTypeFoldableImpl {
};
(@FoldVariants($this:expr, $folder:expr) input() output($($output:tt)*)) => {
match $this {
Ok(match $this {
$($output)*
}
})
};
(@FoldVariants($this:expr, $folder:expr)
@ -126,7 +126,7 @@ macro_rules! EnumTypeFoldableImpl {
output(
$variant ( $($variant_arg),* ) => {
$variant (
$($crate::ty::fold::TypeFoldable::fold_with($variant_arg, $folder)),*
$($crate::ty::fold::TypeFoldable::fold_with($variant_arg, $folder)?),*
)
}
$($output)*
@ -145,7 +145,7 @@ macro_rules! EnumTypeFoldableImpl {
$variant {
$($variant_arg: $crate::ty::fold::TypeFoldable::fold_with(
$variant_arg, $folder
)),* }
)?),* }
}
$($output)*
)