Skip to content

Commit 1b41f95

Browse files
committed
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()`.
1 parent 3f9aea1 commit 1b41f95

File tree

2 files changed

+23
-34
lines changed

2 files changed

+23
-34
lines changed

src/librustc/infer/mod.rs

+5-17
Original file line numberDiff line numberDiff line change
@@ -814,16 +814,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
814814
/// Executes `f` and commit the bindings.
815815
pub fn commit_unconditionally<R, F>(&self, f: F) -> R
816816
where
817-
F: FnOnce() -> R,
817+
F: FnOnce(&CombinedSnapshot<'a, 'tcx>) -> R,
818818
{
819-
debug!("commit()");
819+
debug!("commit_unconditionally()");
820820
let snapshot = self.start_snapshot();
821-
let r = f();
821+
let r = f(&snapshot);
822822
self.commit_from(snapshot);
823823
r
824824
}
825825

826-
/// Executes `f` and commit the bindings if closure `f` returns `Ok(_)`.
826+
/// Execute `f` and commit the bindings if closure `f` returns `Ok(_)`.
827827
pub fn commit_if_ok<T, E, F>(&self, f: F) -> Result<T, E>
828828
where
829829
F: FnOnce(&CombinedSnapshot<'a, 'tcx>) -> Result<T, E>,
@@ -843,19 +843,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
843843
r
844844
}
845845

846-
/// Execute `f` in a snapshot, and commit the bindings it creates.
847-
pub fn in_snapshot<T, F>(&self, f: F) -> T
848-
where
849-
F: FnOnce(&CombinedSnapshot<'a, 'tcx>) -> T,
850-
{
851-
debug!("in_snapshot()");
852-
let snapshot = self.start_snapshot();
853-
let r = f(&snapshot);
854-
self.commit_from(snapshot);
855-
r
856-
}
857-
858-
/// Executes `f` then unroll any bindings it creates.
846+
/// Execute `f` then unroll any bindings it creates.
859847
pub fn probe<R, F>(&self, f: F) -> R
860848
where
861849
F: FnOnce(&CombinedSnapshot<'a, 'tcx>) -> R,

src/librustc/traits/select.rs

+18-17
Original file line numberDiff line numberDiff line change
@@ -2819,7 +2819,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
28192819
// binder moved -\
28202820
let ty: ty::Binder<Ty<'tcx>> = ty::Binder::bind(ty); // <----/
28212821

2822-
self.infcx.in_snapshot(|_| {
2822+
self.infcx.commit_unconditionally(|_| {
28232823
let (skol_ty, _) = self.infcx
28242824
.replace_bound_vars_with_placeholders(&ty);
28252825
let Normalized {
@@ -2932,7 +2932,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
29322932
}
29332933

29342934
fn confirm_projection_candidate(&mut self, obligation: &TraitObligation<'tcx>) {
2935-
self.infcx.in_snapshot(|snapshot| {
2935+
self.infcx.commit_unconditionally(|snapshot| {
29362936
let result =
29372937
self.match_projection_obligation_against_definition_bounds(
29382938
obligation,
@@ -3054,19 +3054,20 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
30543054
nested,
30553055
);
30563056

3057-
let trait_obligations: Vec<PredicateObligation<'_>> = self.infcx.in_snapshot(|_| {
3058-
let poly_trait_ref = obligation.predicate.to_poly_trait_ref();
3059-
let (trait_ref, _) = self.infcx
3060-
.replace_bound_vars_with_placeholders(&poly_trait_ref);
3061-
let cause = obligation.derived_cause(ImplDerivedObligation);
3062-
self.impl_or_trait_obligations(
3063-
cause,
3064-
obligation.recursion_depth + 1,
3065-
obligation.param_env,
3066-
trait_def_id,
3067-
&trait_ref.substs,
3068-
)
3069-
});
3057+
let trait_obligations: Vec<PredicateObligation<'_>> =
3058+
self.infcx.commit_unconditionally(|_| {
3059+
let poly_trait_ref = obligation.predicate.to_poly_trait_ref();
3060+
let (trait_ref, _) = self.infcx
3061+
.replace_bound_vars_with_placeholders(&poly_trait_ref);
3062+
let cause = obligation.derived_cause(ImplDerivedObligation);
3063+
self.impl_or_trait_obligations(
3064+
cause,
3065+
obligation.recursion_depth + 1,
3066+
obligation.param_env,
3067+
trait_def_id,
3068+
&trait_ref.substs,
3069+
)
3070+
});
30703071

30713072
// Adds the predicates from the trait. Note that this contains a `Self: Trait`
30723073
// predicate as usual. It won't have any effect since auto traits are coinductive.
@@ -3089,7 +3090,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
30893090

30903091
// First, create the substitutions by matching the impl again,
30913092
// this time not in a probe.
3092-
self.infcx.in_snapshot(|snapshot| {
3093+
self.infcx.commit_unconditionally(|snapshot| {
30933094
let substs = self.rematch_impl(impl_def_id, obligation, snapshot);
30943095
debug!("confirm_impl_candidate: substs={:?}", substs);
30953096
let cause = obligation.derived_cause(ImplDerivedObligation);
@@ -3253,7 +3254,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
32533254
obligation, alias_def_id
32543255
);
32553256

3256-
self.infcx.in_snapshot(|_| {
3257+
self.infcx.commit_unconditionally(|_| {
32573258
let (predicate, _) = self.infcx()
32583259
.replace_bound_vars_with_placeholders(&obligation.predicate);
32593260
let trait_ref = predicate.trait_ref;

0 commit comments

Comments
 (0)