Remove InferCtxt::in_snapshot()
.
It's the same as `InferCtxt::commit_unconditionally()` except that it is passed a snapshot and has a worse name. The commit also changes `commit_unconditionally()` to receive a snapshot, for consistency with `commit_if_ok()` and `probe()`.
This commit is contained in:
parent
3f9aea199c
commit
1b41f958c5
2 changed files with 23 additions and 34 deletions
|
@ -814,16 +814,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
/// Executes `f` and commit the bindings.
|
/// Executes `f` and commit the bindings.
|
||||||
pub fn commit_unconditionally<R, F>(&self, f: F) -> R
|
pub fn commit_unconditionally<R, F>(&self, f: F) -> R
|
||||||
where
|
where
|
||||||
F: FnOnce() -> R,
|
F: FnOnce(&CombinedSnapshot<'a, 'tcx>) -> R,
|
||||||
{
|
{
|
||||||
debug!("commit()");
|
debug!("commit_unconditionally()");
|
||||||
let snapshot = self.start_snapshot();
|
let snapshot = self.start_snapshot();
|
||||||
let r = f();
|
let r = f(&snapshot);
|
||||||
self.commit_from(snapshot);
|
self.commit_from(snapshot);
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Executes `f` and commit the bindings if closure `f` returns `Ok(_)`.
|
/// Execute `f` and commit the bindings if closure `f` returns `Ok(_)`.
|
||||||
pub fn commit_if_ok<T, E, F>(&self, f: F) -> Result<T, E>
|
pub fn commit_if_ok<T, E, F>(&self, f: F) -> Result<T, E>
|
||||||
where
|
where
|
||||||
F: FnOnce(&CombinedSnapshot<'a, 'tcx>) -> Result<T, E>,
|
F: FnOnce(&CombinedSnapshot<'a, 'tcx>) -> Result<T, E>,
|
||||||
|
@ -843,19 +843,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Execute `f` in a snapshot, and commit the bindings it creates.
|
/// Execute `f` then unroll any bindings it creates.
|
||||||
pub fn in_snapshot<T, F>(&self, f: F) -> T
|
|
||||||
where
|
|
||||||
F: FnOnce(&CombinedSnapshot<'a, 'tcx>) -> T,
|
|
||||||
{
|
|
||||||
debug!("in_snapshot()");
|
|
||||||
let snapshot = self.start_snapshot();
|
|
||||||
let r = f(&snapshot);
|
|
||||||
self.commit_from(snapshot);
|
|
||||||
r
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Executes `f` then unroll any bindings it creates.
|
|
||||||
pub fn probe<R, F>(&self, f: F) -> R
|
pub fn probe<R, F>(&self, f: F) -> R
|
||||||
where
|
where
|
||||||
F: FnOnce(&CombinedSnapshot<'a, 'tcx>) -> R,
|
F: FnOnce(&CombinedSnapshot<'a, 'tcx>) -> R,
|
||||||
|
|
|
@ -2819,7 +2819,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
// binder moved -\
|
// binder moved -\
|
||||||
let ty: ty::Binder<Ty<'tcx>> = ty::Binder::bind(ty); // <----/
|
let ty: ty::Binder<Ty<'tcx>> = ty::Binder::bind(ty); // <----/
|
||||||
|
|
||||||
self.infcx.in_snapshot(|_| {
|
self.infcx.commit_unconditionally(|_| {
|
||||||
let (skol_ty, _) = self.infcx
|
let (skol_ty, _) = self.infcx
|
||||||
.replace_bound_vars_with_placeholders(&ty);
|
.replace_bound_vars_with_placeholders(&ty);
|
||||||
let Normalized {
|
let Normalized {
|
||||||
|
@ -2932,7 +2932,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn confirm_projection_candidate(&mut self, obligation: &TraitObligation<'tcx>) {
|
fn confirm_projection_candidate(&mut self, obligation: &TraitObligation<'tcx>) {
|
||||||
self.infcx.in_snapshot(|snapshot| {
|
self.infcx.commit_unconditionally(|snapshot| {
|
||||||
let result =
|
let result =
|
||||||
self.match_projection_obligation_against_definition_bounds(
|
self.match_projection_obligation_against_definition_bounds(
|
||||||
obligation,
|
obligation,
|
||||||
|
@ -3054,19 +3054,20 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
nested,
|
nested,
|
||||||
);
|
);
|
||||||
|
|
||||||
let trait_obligations: Vec<PredicateObligation<'_>> = self.infcx.in_snapshot(|_| {
|
let trait_obligations: Vec<PredicateObligation<'_>> =
|
||||||
let poly_trait_ref = obligation.predicate.to_poly_trait_ref();
|
self.infcx.commit_unconditionally(|_| {
|
||||||
let (trait_ref, _) = self.infcx
|
let poly_trait_ref = obligation.predicate.to_poly_trait_ref();
|
||||||
.replace_bound_vars_with_placeholders(&poly_trait_ref);
|
let (trait_ref, _) = self.infcx
|
||||||
let cause = obligation.derived_cause(ImplDerivedObligation);
|
.replace_bound_vars_with_placeholders(&poly_trait_ref);
|
||||||
self.impl_or_trait_obligations(
|
let cause = obligation.derived_cause(ImplDerivedObligation);
|
||||||
cause,
|
self.impl_or_trait_obligations(
|
||||||
obligation.recursion_depth + 1,
|
cause,
|
||||||
obligation.param_env,
|
obligation.recursion_depth + 1,
|
||||||
trait_def_id,
|
obligation.param_env,
|
||||||
&trait_ref.substs,
|
trait_def_id,
|
||||||
)
|
&trait_ref.substs,
|
||||||
});
|
)
|
||||||
|
});
|
||||||
|
|
||||||
// Adds the predicates from the trait. Note that this contains a `Self: Trait`
|
// Adds the predicates from the trait. Note that this contains a `Self: Trait`
|
||||||
// predicate as usual. It won't have any effect since auto traits are coinductive.
|
// predicate as usual. It won't have any effect since auto traits are coinductive.
|
||||||
|
@ -3089,7 +3090,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
|
|
||||||
// First, create the substitutions by matching the impl again,
|
// First, create the substitutions by matching the impl again,
|
||||||
// this time not in a probe.
|
// this time not in a probe.
|
||||||
self.infcx.in_snapshot(|snapshot| {
|
self.infcx.commit_unconditionally(|snapshot| {
|
||||||
let substs = self.rematch_impl(impl_def_id, obligation, snapshot);
|
let substs = self.rematch_impl(impl_def_id, obligation, snapshot);
|
||||||
debug!("confirm_impl_candidate: substs={:?}", substs);
|
debug!("confirm_impl_candidate: substs={:?}", substs);
|
||||||
let cause = obligation.derived_cause(ImplDerivedObligation);
|
let cause = obligation.derived_cause(ImplDerivedObligation);
|
||||||
|
@ -3253,7 +3254,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
obligation, alias_def_id
|
obligation, alias_def_id
|
||||||
);
|
);
|
||||||
|
|
||||||
self.infcx.in_snapshot(|_| {
|
self.infcx.commit_unconditionally(|_| {
|
||||||
let (predicate, _) = self.infcx()
|
let (predicate, _) = self.infcx()
|
||||||
.replace_bound_vars_with_placeholders(&obligation.predicate);
|
.replace_bound_vars_with_placeholders(&obligation.predicate);
|
||||||
let trait_ref = predicate.trait_ref;
|
let trait_ref = predicate.trait_ref;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue