Skip to content

Commit 79efed8

Browse files
committed
remove wrapper functions that had no purpose
1 parent 5f0fe8f commit 79efed8

File tree

1 file changed

+37
-56
lines changed

1 file changed

+37
-56
lines changed

src/librustc/traits/select.rs

+37-56
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ use super::{
2929

3030
use dep_graph::{DepKind, DepNodeIndex};
3131
use hir::def_id::DefId;
32-
use infer;
33-
use infer::{InferCtxt, InferOk, TypeFreshener};
32+
use infer::{self, InferCtxt, InferOk, TypeFreshener};
3433
use middle::lang_items;
3534
use mir::interpret::GlobalId;
3635
use ty::fast_reject;
@@ -531,24 +530,6 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
531530
self.infcx
532531
}
533532

534-
/// Wraps the inference context's in_snapshot s.t. snapshot handling is only from the selection
535-
/// context's self.
536-
fn in_snapshot<R, F>(&mut self, f: F) -> R
537-
where
538-
F: FnOnce(&mut Self, &infer::CombinedSnapshot<'cx, 'tcx>) -> R,
539-
{
540-
self.infcx.in_snapshot(|snapshot| f(self, snapshot))
541-
}
542-
543-
/// Wraps a probe s.t. obligations collected during it are ignored and old obligations are
544-
/// retained.
545-
fn probe<R, F>(&mut self, f: F) -> R
546-
where
547-
F: FnOnce(&mut Self, &infer::CombinedSnapshot<'cx, 'tcx>) -> R,
548-
{
549-
self.infcx.probe(|snapshot| f(self, snapshot))
550-
}
551-
552533
///////////////////////////////////////////////////////////////////////////
553534
// Selection
554535
//
@@ -630,8 +611,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
630611
&mut self,
631612
obligation: &PredicateObligation<'tcx>,
632613
) -> Result<EvaluationResult, OverflowError> {
633-
self.probe(|this, _| {
634-
this.evaluate_predicate_recursively(TraitObligationStackList::empty(), obligation)
614+
self.infcx.probe(|_| {
615+
self.evaluate_predicate_recursively(TraitObligationStackList::empty(), obligation)
635616
})
636617
}
637618

@@ -1066,10 +1047,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
10661047
"evaluate_candidate: depth={} candidate={:?}",
10671048
stack.obligation.recursion_depth, candidate
10681049
);
1069-
let result = self.probe(|this, _| {
1050+
let result = self.infcx.probe(|_| {
10701051
let candidate = (*candidate).clone();
1071-
match this.confirm_candidate(stack.obligation, candidate) {
1072-
Ok(selection) => this.evaluate_predicates_recursively(
1052+
match self.confirm_candidate(stack.obligation, candidate) {
1053+
Ok(selection) => self.evaluate_predicates_recursively(
10731054
stack.list(),
10741055
selection.nested_obligations().iter(),
10751056
),
@@ -1697,8 +1678,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
16971678
_ => return,
16981679
}
16991680

1700-
let result = self.probe(|this, snapshot| {
1701-
this.match_projection_obligation_against_definition_bounds(obligation, snapshot)
1681+
let result = self.infcx.probe(|snapshot| {
1682+
self.match_projection_obligation_against_definition_bounds(obligation, snapshot)
17021683
});
17031684

17041685
if result {
@@ -1750,8 +1731,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
17501731
let matching_bound = util::elaborate_predicates(self.tcx(), bounds.predicates)
17511732
.filter_to_traits()
17521733
.find(|bound| {
1753-
self.probe(|this, _| {
1754-
this.match_projection(
1734+
self.infcx.probe(|_| {
1735+
self.match_projection(
17551736
obligation,
17561737
bound.clone(),
17571738
skol_trait_predicate.trait_ref.clone(),
@@ -1853,10 +1834,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
18531834
stack: &TraitObligationStack<'o, 'tcx>,
18541835
where_clause_trait_ref: ty::PolyTraitRef<'tcx>,
18551836
) -> Result<EvaluationResult, OverflowError> {
1856-
self.probe(move |this, _| {
1857-
match this.match_where_clause_trait_ref(stack.obligation, where_clause_trait_ref) {
1837+
self.infcx.probe(|_| {
1838+
match self.match_where_clause_trait_ref(stack.obligation, where_clause_trait_ref) {
18581839
Ok(obligations) => {
1859-
this.evaluate_predicates_recursively(stack.list(), obligations.iter())
1840+
self.evaluate_predicates_recursively(stack.list(), obligations.iter())
18601841
}
18611842
Err(()) => Ok(EvaluatedToErr),
18621843
}
@@ -2006,8 +1987,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
20061987
obligation.predicate.def_id(),
20071988
obligation.predicate.skip_binder().trait_ref.self_ty(),
20081989
|impl_def_id| {
2009-
self.probe(|this, snapshot| {
2010-
if let Ok(placeholder_map) = this.match_impl(impl_def_id, obligation, snapshot)
1990+
self.infcx.probe(|snapshot| {
1991+
if let Ok(placeholder_map) = self.match_impl(impl_def_id, obligation, snapshot)
20111992
{
20121993
candidates.vec.push(ImplCandidate(impl_def_id));
20131994

@@ -2084,11 +2065,11 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
20842065
obligation.self_ty().skip_binder()
20852066
);
20862067

2087-
self.probe(|this, _snapshot| {
2068+
self.infcx.probe(|_snapshot| {
20882069
// The code below doesn't care about regions, and the
20892070
// self-ty here doesn't escape this probe, so just erase
20902071
// any LBR.
2091-
let self_ty = this.tcx().erase_late_bound_regions(&obligation.self_ty());
2072+
let self_ty = self.tcx().erase_late_bound_regions(&obligation.self_ty());
20922073
let poly_trait_ref = match self_ty.sty {
20932074
ty::Dynamic(ref data, ..) => {
20942075
if data.auto_traits()
@@ -2102,7 +2083,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
21022083
return;
21032084
}
21042085

2105-
data.principal().with_self_ty(this.tcx(), self_ty)
2086+
data.principal().with_self_ty(self.tcx(), self_ty)
21062087
}
21072088
ty::Infer(ty::TyVar(_)) => {
21082089
debug!("assemble_candidates_from_object_ty: ambiguous");
@@ -2122,11 +2103,11 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
21222103
// correct trait, but also the correct type parameters.
21232104
// For example, we may be trying to upcast `Foo` to `Bar<i32>`,
21242105
// but `Foo` is declared as `trait Foo : Bar<u32>`.
2125-
let upcast_trait_refs = util::supertraits(this.tcx(), poly_trait_ref)
2106+
let upcast_trait_refs = util::supertraits(self.tcx(), poly_trait_ref)
21262107
.filter(|upcast_trait_ref| {
2127-
this.probe(|this, _| {
2108+
self.infcx.probe(|_| {
21282109
let upcast_trait_ref = upcast_trait_ref.clone();
2129-
this.match_poly_trait_ref(obligation, upcast_trait_ref)
2110+
self.match_poly_trait_ref(obligation, upcast_trait_ref)
21302111
.is_ok()
21312112
})
21322113
})
@@ -2671,20 +2652,20 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
26712652
// binder moved -\
26722653
let ty: ty::Binder<Ty<'tcx>> = ty::Binder::bind(ty); // <----/
26732654

2674-
self.in_snapshot(|this, snapshot| {
2675-
let (skol_ty, placeholder_map) = this.infcx()
2655+
self.infcx.in_snapshot(|snapshot| {
2656+
let (skol_ty, placeholder_map) = self.infcx
26762657
.replace_bound_vars_with_placeholders(&ty);
26772658
let Normalized {
26782659
value: normalized_ty,
26792660
mut obligations,
26802661
} = project::normalize_with_depth(
2681-
this,
2662+
self,
26822663
param_env,
26832664
cause.clone(),
26842665
recursion_depth,
26852666
&skol_ty,
26862667
);
2687-
let skol_obligation = this.tcx().predicate_for_trait_def(
2668+
let skol_obligation = self.tcx().predicate_for_trait_def(
26882669
param_env,
26892670
cause.clone(),
26902671
trait_def_id,
@@ -2693,7 +2674,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
26932674
&[],
26942675
);
26952676
obligations.push(skol_obligation);
2696-
this.infcx()
2677+
self.infcx
26972678
.plug_leaks(placeholder_map, snapshot, obligations)
26982679
})
26992680
})
@@ -2785,9 +2766,9 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
27852766
}
27862767

27872768
fn confirm_projection_candidate(&mut self, obligation: &TraitObligation<'tcx>) {
2788-
self.in_snapshot(|this, snapshot| {
2769+
self.infcx.in_snapshot(|snapshot| {
27892770
let result =
2790-
this.match_projection_obligation_against_definition_bounds(obligation, snapshot);
2771+
self.match_projection_obligation_against_definition_bounds(obligation, snapshot);
27912772
assert!(result);
27922773
})
27932774
}
@@ -2904,12 +2885,12 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
29042885
nested,
29052886
);
29062887

2907-
let trait_obligations: Vec<PredicateObligation<'_>> = self.in_snapshot(|this, snapshot| {
2888+
let trait_obligations: Vec<PredicateObligation<'_>> = self.infcx.in_snapshot(|snapshot| {
29082889
let poly_trait_ref = obligation.predicate.to_poly_trait_ref();
2909-
let (trait_ref, placeholder_map) = this.infcx()
2890+
let (trait_ref, placeholder_map) = self.infcx
29102891
.replace_bound_vars_with_placeholders(&poly_trait_ref);
29112892
let cause = obligation.derived_cause(ImplDerivedObligation);
2912-
this.impl_or_trait_obligations(
2893+
self.impl_or_trait_obligations(
29132894
cause,
29142895
obligation.recursion_depth + 1,
29152896
obligation.param_env,
@@ -2941,11 +2922,11 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
29412922

29422923
// First, create the substitutions by matching the impl again,
29432924
// this time not in a probe.
2944-
self.in_snapshot(|this, snapshot| {
2945-
let (substs, placeholder_map) = this.rematch_impl(impl_def_id, obligation, snapshot);
2925+
self.infcx.in_snapshot(|snapshot| {
2926+
let (substs, placeholder_map) = self.rematch_impl(impl_def_id, obligation, snapshot);
29462927
debug!("confirm_impl_candidate: substs={:?}", substs);
29472928
let cause = obligation.derived_cause(ImplDerivedObligation);
2948-
this.vtable_impl(
2929+
self.vtable_impl(
29492930
impl_def_id,
29502931
substs,
29512932
cause,
@@ -3108,14 +3089,14 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
31083089
obligation, alias_def_id
31093090
);
31103091

3111-
self.in_snapshot(|this, snapshot| {
3112-
let (predicate, placeholder_map) = this.infcx()
3092+
self.infcx.in_snapshot(|snapshot| {
3093+
let (predicate, placeholder_map) = self.infcx
31133094
.replace_bound_vars_with_placeholders(&obligation.predicate);
31143095
let trait_ref = predicate.trait_ref;
31153096
let trait_def_id = trait_ref.def_id;
31163097
let substs = trait_ref.substs;
31173098

3118-
let trait_obligations = this.impl_or_trait_obligations(
3099+
let trait_obligations = self.impl_or_trait_obligations(
31193100
obligation.cause.clone(),
31203101
obligation.recursion_depth,
31213102
obligation.param_env,

0 commit comments

Comments
 (0)