Unwrap the results of type folders

Co-authored-by: Alan Egerton <eggyal@gmail.com>
This commit is contained in:
LeSeulArtichaut 2021-05-19 15:03:43 +02:00 committed by Alan Egerton
parent 6dc3dae46f
commit 30bf20a692
No known key found for this signature in database
GPG key ID: 07CAC3CCA7E0643F
34 changed files with 191 additions and 167 deletions

View file

@ -22,6 +22,7 @@
#![feature(never_type)]
#![feature(crate_visibility_modifier)]
#![feature(control_flow_enum)]
#![feature(unwrap_infallible)]
#![recursion_limit = "512"] // For rustdoc
#[macro_use]

View file

@ -65,14 +65,16 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
// Convert the type from the function into a type valid outside
// the function, by replacing invalid regions with 'static,
// after producing an error for each of them.
let definition_ty = instantiated_ty.fold_with(&mut ReverseMapper::new(
self.tcx,
self.is_tainted_by_errors(),
def_id,
map,
instantiated_ty,
span,
));
let definition_ty = instantiated_ty
.fold_with(&mut ReverseMapper::new(
self.tcx,
self.is_tainted_by_errors(),
def_id,
map,
instantiated_ty,
span,
))
.into_ok();
debug!(?definition_ty);
definition_ty
@ -123,14 +125,14 @@ impl ReverseMapper<'tcx> {
) -> GenericArg<'tcx> {
assert!(!self.map_missing_regions_to_empty);
self.map_missing_regions_to_empty = true;
let kind = kind.fold_with(self);
let kind = kind.fold_with(self).into_ok();
self.map_missing_regions_to_empty = false;
kind
}
fn fold_kind_normally(&mut self, kind: GenericArg<'tcx>) -> GenericArg<'tcx> {
assert!(!self.map_missing_regions_to_empty);
kind.fold_with(self)
kind.fold_with(self).into_ok()
}
}

View file

@ -1916,8 +1916,9 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
self.probe(|_| {
let mut selcx = SelectionContext::new(self);
let cleaned_pred =
pred.fold_with(&mut ParamToVarFolder { infcx: self, var_map: Default::default() });
let cleaned_pred = pred
.fold_with(&mut ParamToVarFolder { infcx: self, var_map: Default::default() })
.into_ok();
let cleaned_pred = super::project::normalize(
&mut selcx,

View file

@ -339,7 +339,7 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
if !needs_normalization(&value, self.param_env.reveal()) {
value
} else {
value.fold_with(self)
value.fold_with(self).into_ok()
}
}
}
@ -555,7 +555,7 @@ impl<'me, 'tcx> BoundVarReplacer<'me, 'tcx> {
universe_indices,
};
let value = value.super_fold_with(&mut replacer);
let value = value.super_fold_with(&mut replacer).into_ok();
(value, replacer.mapped_regions, replacer.mapped_types, replacer.mapped_consts)
}
@ -681,7 +681,7 @@ impl<'me, 'tcx> PlaceholderReplacer<'me, 'tcx> {
universe_indices,
current_index: ty::INNERMOST,
};
value.super_fold_with(&mut replacer)
value.super_fold_with(&mut replacer).into_ok()
}
}
@ -1546,7 +1546,8 @@ fn confirm_candidate<'cx, 'tcx>(
// when possible for this to work. See `auto-trait-projection-recursion.rs`
// for a case where this matters.
if progress.ty.has_infer_regions() {
progress.ty = OpportunisticRegionResolver::new(selcx.infcx()).fold_ty(progress.ty);
progress.ty =
OpportunisticRegionResolver::new(selcx.infcx()).fold_ty(progress.ty).into_ok();
}
progress
}

View file

@ -88,7 +88,7 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> {
normalizer.universes.extend((0..max_visitor.escaping).map(|_| None));
}
}
let result = value.fold_with(&mut normalizer);
let result = value.fold_with(&mut normalizer).into_ok();
info!(
"normalize::<{}>: result={:?} with {} obligations",
std::any::type_name::<T>(),

View file

@ -2222,6 +2222,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
.predicate
.to_poly_trait_ref()
.fold_with(&mut self.freshener)
.into_ok()
.with_constness(obligation.predicate.skip_binder().constness);
let dfn = previous_stack.cache.next_dfn();