Remove SelectionContext::infcx() in favor of field access

This commit is contained in:
Michael Goulet 2022-11-25 23:31:28 +00:00
parent 8681d4cffc
commit 6436c348db
8 changed files with 75 additions and 92 deletions

View file

@ -599,17 +599,17 @@ impl<'tcx> AutoTraitFinder<'tcx> {
computed_preds: &mut FxIndexSet<ty::Predicate<'tcx>>, computed_preds: &mut FxIndexSet<ty::Predicate<'tcx>>,
fresh_preds: &mut FxHashSet<ty::Predicate<'tcx>>, fresh_preds: &mut FxHashSet<ty::Predicate<'tcx>>,
predicates: &mut VecDeque<ty::PolyTraitPredicate<'tcx>>, predicates: &mut VecDeque<ty::PolyTraitPredicate<'tcx>>,
select: &mut SelectionContext<'_, 'tcx>, selcx: &mut SelectionContext<'_, 'tcx>,
only_projections: bool, only_projections: bool,
) -> bool { ) -> bool {
let dummy_cause = ObligationCause::dummy(); let dummy_cause = ObligationCause::dummy();
for obligation in nested { for obligation in nested {
let is_new_pred = let is_new_pred =
fresh_preds.insert(self.clean_pred(select.infcx(), obligation.predicate)); fresh_preds.insert(self.clean_pred(selcx.infcx, obligation.predicate));
// Resolve any inference variables that we can, to help selection succeed // Resolve any inference variables that we can, to help selection succeed
let predicate = select.infcx().resolve_vars_if_possible(obligation.predicate); let predicate = selcx.infcx.resolve_vars_if_possible(obligation.predicate);
// We only add a predicate as a user-displayable bound if // We only add a predicate as a user-displayable bound if
// it involves a generic parameter, and doesn't contain // it involves a generic parameter, and doesn't contain
@ -717,10 +717,8 @@ impl<'tcx> AutoTraitFinder<'tcx> {
// and turn them into an explicit negative impl for our type. // and turn them into an explicit negative impl for our type.
debug!("Projecting and unifying projection predicate {:?}", predicate); debug!("Projecting and unifying projection predicate {:?}", predicate);
match project::poly_project_and_unify_type( match project::poly_project_and_unify_type(selcx, &obligation.with(self.tcx, p))
select, {
&obligation.with(self.tcx, p),
) {
ProjectAndUnifyResult::MismatchedProjectionTypes(e) => { ProjectAndUnifyResult::MismatchedProjectionTypes(e) => {
debug!( debug!(
"evaluate_nested_obligations: Unable to unify predicate \ "evaluate_nested_obligations: Unable to unify predicate \
@ -745,7 +743,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
computed_preds, computed_preds,
fresh_preds, fresh_preds,
predicates, predicates,
select, selcx,
only_projections, only_projections,
) { ) {
return false; return false;
@ -768,7 +766,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
} }
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(binder)) => { ty::PredicateKind::Clause(ty::Clause::RegionOutlives(binder)) => {
let binder = bound_predicate.rebind(binder); let binder = bound_predicate.rebind(binder);
select.infcx().region_outlives_predicate(&dummy_cause, binder) selcx.infcx.region_outlives_predicate(&dummy_cause, binder)
} }
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(binder)) => { ty::PredicateKind::Clause(ty::Clause::TypeOutlives(binder)) => {
let binder = bound_predicate.rebind(binder); let binder = bound_predicate.rebind(binder);
@ -777,14 +775,14 @@ impl<'tcx> AutoTraitFinder<'tcx> {
binder.map_bound_ref(|pred| pred.0).no_bound_vars(), binder.map_bound_ref(|pred| pred.0).no_bound_vars(),
) { ) {
(None, Some(t_a)) => { (None, Some(t_a)) => {
select.infcx().register_region_obligation_with_cause( selcx.infcx.register_region_obligation_with_cause(
t_a, t_a,
select.infcx().tcx.lifetimes.re_static, selcx.infcx.tcx.lifetimes.re_static,
&dummy_cause, &dummy_cause,
); );
} }
(Some(ty::OutlivesPredicate(t_a, r_b)), _) => { (Some(ty::OutlivesPredicate(t_a, r_b)), _) => {
select.infcx().register_region_obligation_with_cause( selcx.infcx.register_region_obligation_with_cause(
t_a, t_a,
r_b, r_b,
&dummy_cause, &dummy_cause,
@ -796,13 +794,13 @@ impl<'tcx> AutoTraitFinder<'tcx> {
ty::PredicateKind::ConstEquate(c1, c2) => { ty::PredicateKind::ConstEquate(c1, c2) => {
let evaluate = |c: ty::Const<'tcx>| { let evaluate = |c: ty::Const<'tcx>| {
if let ty::ConstKind::Unevaluated(unevaluated) = c.kind() { if let ty::ConstKind::Unevaluated(unevaluated) = c.kind() {
match select.infcx().const_eval_resolve( match selcx.infcx.const_eval_resolve(
obligation.param_env, obligation.param_env,
unevaluated, unevaluated,
Some(obligation.cause.span), Some(obligation.cause.span),
) { ) {
Ok(Some(valtree)) => { Ok(Some(valtree)) => {
Ok(ty::Const::from_value(select.tcx(), valtree, c.ty())) Ok(ty::Const::from_value(selcx.tcx(), valtree, c.ty()))
} }
Ok(None) => { Ok(None) => {
let tcx = self.tcx; let tcx = self.tcx;
@ -823,10 +821,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
match (evaluate(c1), evaluate(c2)) { match (evaluate(c1), evaluate(c2)) {
(Ok(c1), Ok(c2)) => { (Ok(c1), Ok(c2)) => {
match select match selcx.infcx.at(&obligation.cause, obligation.param_env).eq(c1, c2)
.infcx()
.at(&obligation.cause, obligation.param_env)
.eq(c1, c2)
{ {
Ok(_) => (), Ok(_) => (),
Err(_) => return false, Err(_) => return false,

View file

@ -119,7 +119,7 @@ fn with_fresh_ty_vars<'cx, 'tcx>(
impl_def_id: DefId, impl_def_id: DefId,
) -> ty::ImplHeader<'tcx> { ) -> ty::ImplHeader<'tcx> {
let tcx = selcx.tcx(); let tcx = selcx.tcx();
let impl_substs = selcx.infcx().fresh_substs_for_item(DUMMY_SP, impl_def_id); let impl_substs = selcx.infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id);
let header = ty::ImplHeader { let header = ty::ImplHeader {
impl_def_id, impl_def_id,
@ -149,7 +149,7 @@ fn overlap<'cx, 'tcx>(
impl1_def_id, impl2_def_id, overlap_mode impl1_def_id, impl2_def_id, overlap_mode
); );
selcx.infcx().probe_maybe_skip_leak_check(skip_leak_check.is_yes(), |snapshot| { selcx.infcx.probe_maybe_skip_leak_check(skip_leak_check.is_yes(), |snapshot| {
overlap_within_probe(selcx, impl1_def_id, impl2_def_id, overlap_mode, snapshot) overlap_within_probe(selcx, impl1_def_id, impl2_def_id, overlap_mode, snapshot)
}) })
} }
@ -161,7 +161,7 @@ fn overlap_within_probe<'cx, 'tcx>(
overlap_mode: OverlapMode, overlap_mode: OverlapMode,
snapshot: &CombinedSnapshot<'tcx>, snapshot: &CombinedSnapshot<'tcx>,
) -> Option<OverlapResult<'tcx>> { ) -> Option<OverlapResult<'tcx>> {
let infcx = selcx.infcx(); let infcx = selcx.infcx;
if overlap_mode.use_negative_impl() { if overlap_mode.use_negative_impl() {
if negative_impl(infcx.tcx, impl1_def_id, impl2_def_id) if negative_impl(infcx.tcx, impl1_def_id, impl2_def_id)
@ -200,9 +200,9 @@ fn overlap_within_probe<'cx, 'tcx>(
debug!("overlap: intercrate_ambiguity_causes={:#?}", intercrate_ambiguity_causes); debug!("overlap: intercrate_ambiguity_causes={:#?}", intercrate_ambiguity_causes);
let involves_placeholder = let involves_placeholder =
matches!(selcx.infcx().region_constraints_added_in_snapshot(snapshot), Some(true)); matches!(selcx.infcx.region_constraints_added_in_snapshot(snapshot), Some(true));
let impl_header = selcx.infcx().resolve_vars_if_possible(impl1_header); let impl_header = selcx.infcx.resolve_vars_if_possible(impl1_header);
Some(OverlapResult { impl_header, intercrate_ambiguity_causes, involves_placeholder }) Some(OverlapResult { impl_header, intercrate_ambiguity_causes, involves_placeholder })
} }
@ -214,7 +214,7 @@ fn equate_impl_headers<'cx, 'tcx>(
// Do `a` and `b` unify? If not, no overlap. // Do `a` and `b` unify? If not, no overlap.
debug!("equate_impl_headers(impl1_header={:?}, impl2_header={:?}", impl1_header, impl2_header); debug!("equate_impl_headers(impl1_header={:?}, impl2_header={:?}", impl1_header, impl2_header);
selcx selcx
.infcx() .infcx
.at(&ObligationCause::dummy(), ty::ParamEnv::empty()) .at(&ObligationCause::dummy(), ty::ParamEnv::empty())
.eq_impl_headers(impl1_header, impl2_header) .eq_impl_headers(impl1_header, impl2_header)
.map(|infer_ok| infer_ok.obligations) .map(|infer_ok| infer_ok.obligations)
@ -255,7 +255,7 @@ fn implicit_negative<'cx, 'tcx>(
"implicit_negative(impl1_header={:?}, impl2_header={:?}, obligations={:?})", "implicit_negative(impl1_header={:?}, impl2_header={:?}, obligations={:?})",
impl1_header, impl2_header, obligations impl1_header, impl2_header, obligations
); );
let infcx = selcx.infcx(); let infcx = selcx.infcx;
let opt_failing_obligation = impl1_header let opt_failing_obligation = impl1_header
.predicates .predicates
.iter() .iter()

View file

@ -199,7 +199,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
// code is so hot. 1 and 0 dominate; 2+ is fairly rare. // code is so hot. 1 and 0 dominate; 2+ is fairly rare.
1 => { 1 => {
let infer_var = pending_obligation.stalled_on[0]; let infer_var = pending_obligation.stalled_on[0];
self.selcx.infcx().ty_or_const_infer_var_changed(infer_var) self.selcx.infcx.ty_or_const_infer_var_changed(infer_var)
} }
0 => { 0 => {
// In this case we haven't changed, but wish to make a change. // In this case we haven't changed, but wish to make a change.
@ -210,7 +210,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
// form was a perf win. See #64545 for details. // form was a perf win. See #64545 for details.
(|| { (|| {
for &infer_var in &pending_obligation.stalled_on { for &infer_var in &pending_obligation.stalled_on {
if self.selcx.infcx().ty_or_const_infer_var_changed(infer_var) { if self.selcx.infcx.ty_or_const_infer_var_changed(infer_var) {
return true; return true;
} }
} }
@ -240,13 +240,12 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
debug!(?obligation, "pre-resolve"); debug!(?obligation, "pre-resolve");
if obligation.predicate.has_non_region_infer() { if obligation.predicate.has_non_region_infer() {
obligation.predicate = obligation.predicate = self.selcx.infcx.resolve_vars_if_possible(obligation.predicate);
self.selcx.infcx().resolve_vars_if_possible(obligation.predicate);
} }
let obligation = &pending_obligation.obligation; let obligation = &pending_obligation.obligation;
let infcx = self.selcx.infcx(); let infcx = self.selcx.infcx;
if obligation.predicate.has_projections() { if obligation.predicate.has_projections() {
let mut obligations = Vec::new(); let mut obligations = Vec::new();
@ -353,7 +352,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
} }
ty::PredicateKind::ClosureKind(_, closure_substs, kind) => { ty::PredicateKind::ClosureKind(_, closure_substs, kind) => {
match self.selcx.infcx().closure_kind(closure_substs) { match self.selcx.infcx.closure_kind(closure_substs) {
Some(closure_kind) => { Some(closure_kind) => {
if closure_kind.extends(kind) { if closure_kind.extends(kind) {
ProcessResult::Changed(vec![]) ProcessResult::Changed(vec![])
@ -367,7 +366,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
ty::PredicateKind::WellFormed(arg) => { ty::PredicateKind::WellFormed(arg) => {
match wf::obligations( match wf::obligations(
self.selcx.infcx(), self.selcx.infcx,
obligation.param_env, obligation.param_env,
obligation.cause.body_id, obligation.cause.body_id,
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
@ -384,7 +383,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
} }
ty::PredicateKind::Subtype(subtype) => { ty::PredicateKind::Subtype(subtype) => {
match self.selcx.infcx().subtype_predicate( match self.selcx.infcx.subtype_predicate(
&obligation.cause, &obligation.cause,
obligation.param_env, obligation.param_env,
Binder::dummy(subtype), Binder::dummy(subtype),
@ -408,7 +407,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
} }
ty::PredicateKind::Coerce(coerce) => { ty::PredicateKind::Coerce(coerce) => {
match self.selcx.infcx().coerce_predicate( match self.selcx.infcx.coerce_predicate(
&obligation.cause, &obligation.cause,
obligation.param_env, obligation.param_env,
Binder::dummy(coerce), Binder::dummy(coerce),
@ -432,7 +431,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
ty::PredicateKind::ConstEvaluatable(uv) => { ty::PredicateKind::ConstEvaluatable(uv) => {
match const_evaluatable::is_const_evaluatable( match const_evaluatable::is_const_evaluatable(
self.selcx.infcx(), self.selcx.infcx,
uv, uv,
obligation.param_env, obligation.param_env,
obligation.cause.span, obligation.cause.span,
@ -476,7 +475,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
let mut evaluate = |c: Const<'tcx>| { let mut evaluate = |c: Const<'tcx>| {
if let ty::ConstKind::Unevaluated(unevaluated) = c.kind() { if let ty::ConstKind::Unevaluated(unevaluated) = c.kind() {
match self.selcx.infcx().try_const_eval_resolve( match self.selcx.infcx.try_const_eval_resolve(
obligation.param_env, obligation.param_env,
unevaluated, unevaluated,
c.ty(), c.ty(),
@ -504,7 +503,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
(Ok(c1), Ok(c2)) => { (Ok(c1), Ok(c2)) => {
match self match self
.selcx .selcx
.infcx() .infcx
.at(&obligation.cause, obligation.param_env) .at(&obligation.cause, obligation.param_env)
.eq(c1, c2) .eq(c1, c2)
{ {
@ -572,7 +571,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
trait_obligation: TraitObligation<'tcx>, trait_obligation: TraitObligation<'tcx>,
stalled_on: &mut Vec<TyOrConstInferVar<'tcx>>, stalled_on: &mut Vec<TyOrConstInferVar<'tcx>>,
) -> ProcessResult<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>> { ) -> ProcessResult<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>> {
let infcx = self.selcx.infcx(); let infcx = self.selcx.infcx;
if obligation.predicate.is_global() { if obligation.predicate.is_global() {
// no type variables present, can use evaluation for better caching. // no type variables present, can use evaluation for better caching.
// FIXME: consider caching errors too. // FIXME: consider caching errors too.
@ -630,7 +629,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
if obligation.predicate.is_global() { if obligation.predicate.is_global() {
// no type variables present, can use evaluation for better caching. // no type variables present, can use evaluation for better caching.
// FIXME: consider caching errors too. // FIXME: consider caching errors too.
if self.selcx.infcx().predicate_must_hold_considering_regions(obligation) { if self.selcx.infcx.predicate_must_hold_considering_regions(obligation) {
if let Some(key) = ProjectionCacheKey::from_poly_projection_predicate( if let Some(key) = ProjectionCacheKey::from_poly_projection_predicate(
&mut self.selcx, &mut self.selcx,
project_obligation.predicate, project_obligation.predicate,
@ -639,7 +638,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
// evaluated all sub-obligations. We can therefore mark the 'root' // evaluated all sub-obligations. We can therefore mark the 'root'
// obligation as complete, and skip evaluating sub-obligations. // obligation as complete, and skip evaluating sub-obligations.
self.selcx self.selcx
.infcx() .infcx
.inner .inner
.borrow_mut() .borrow_mut()
.projection_cache() .projection_cache()
@ -678,7 +677,7 @@ fn substs_infer_vars<'a, 'tcx>(
substs: ty::Binder<'tcx, SubstsRef<'tcx>>, substs: ty::Binder<'tcx, SubstsRef<'tcx>>,
) -> impl Iterator<Item = TyOrConstInferVar<'tcx>> { ) -> impl Iterator<Item = TyOrConstInferVar<'tcx>> {
selcx selcx
.infcx() .infcx
.resolve_vars_if_possible(substs) .resolve_vars_if_possible(substs)
.skip_binder() // ok because this check doesn't care about regions .skip_binder() // ok because this check doesn't care about regions
.iter() .iter()

View file

@ -194,7 +194,7 @@ pub(super) fn poly_project_and_unify_type<'cx, 'tcx>(
selcx: &mut SelectionContext<'cx, 'tcx>, selcx: &mut SelectionContext<'cx, 'tcx>,
obligation: &PolyProjectionObligation<'tcx>, obligation: &PolyProjectionObligation<'tcx>,
) -> ProjectAndUnifyResult<'tcx> { ) -> ProjectAndUnifyResult<'tcx> {
let infcx = selcx.infcx(); let infcx = selcx.infcx;
let r = infcx.commit_if_ok(|_snapshot| { let r = infcx.commit_if_ok(|_snapshot| {
let old_universe = infcx.universe(); let old_universe = infcx.universe();
let placeholder_predicate = let placeholder_predicate =
@ -250,7 +250,7 @@ fn project_and_unify_type<'cx, 'tcx>(
) -> ProjectAndUnifyResult<'tcx> { ) -> ProjectAndUnifyResult<'tcx> {
let mut obligations = vec![]; let mut obligations = vec![];
let infcx = selcx.infcx(); let infcx = selcx.infcx;
let normalized = match opt_normalize_projection_type( let normalized = match opt_normalize_projection_type(
selcx, selcx,
obligation.param_env, obligation.param_env,
@ -269,7 +269,7 @@ fn project_and_unify_type<'cx, 'tcx>(
// This allows users to omit re-mentioning all bounds on an associated type and just use an // This allows users to omit re-mentioning all bounds on an associated type and just use an
// `impl Trait` for the assoc type to add more bounds. // `impl Trait` for the assoc type to add more bounds.
let InferOk { value: actual, obligations: new } = let InferOk { value: actual, obligations: new } =
selcx.infcx().replace_opaque_types_with_inference_vars( selcx.infcx.replace_opaque_types_with_inference_vars(
actual, actual,
obligation.cause.body_id, obligation.cause.body_id,
obligation.cause.span, obligation.cause.span,
@ -445,7 +445,7 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
} }
fn fold<T: TypeFoldable<'tcx>>(&mut self, value: T) -> T { fn fold<T: TypeFoldable<'tcx>>(&mut self, value: T) -> T {
let value = self.selcx.infcx().resolve_vars_if_possible(value); let value = self.selcx.infcx.resolve_vars_if_possible(value);
debug!(?value); debug!(?value);
assert!( assert!(
@ -524,7 +524,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
self.param_env, self.param_env,
ty, ty,
); );
self.selcx.infcx().err_ctxt().report_overflow_error(&obligation, true); self.selcx.infcx.err_ctxt().report_overflow_error(&obligation, true);
} }
let substs = substs.fold_with(self); let substs = substs.fold_with(self);
@ -590,7 +590,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
// want to figure out how to register obligations with escaping vars // want to figure out how to register obligations with escaping vars
// or handle this some other way. // or handle this some other way.
let infcx = self.selcx.infcx(); let infcx = self.selcx.infcx;
let (data, mapped_regions, mapped_types, mapped_consts) = let (data, mapped_regions, mapped_types, mapped_consts) =
BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, data); BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, data);
let data = data.fold_with(self); let data = data.fold_with(self);
@ -640,7 +640,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
let constant = constant.super_fold_with(self); let constant = constant.super_fold_with(self);
debug!(?constant, ?self.param_env); debug!(?constant, ?self.param_env);
with_replaced_escaping_bound_vars( with_replaced_escaping_bound_vars(
self.selcx.infcx(), self.selcx.infcx,
&mut self.universes, &mut self.universes,
constant, constant,
|constant| constant.eval(tcx, self.param_env), |constant| constant.eval(tcx, self.param_env),
@ -992,10 +992,7 @@ pub fn normalize_projection_type<'a, 'b, 'tcx>(
// and a deferred predicate to resolve this when more type // and a deferred predicate to resolve this when more type
// information is available. // information is available.
selcx selcx.infcx.infer_projection(param_env, projection_ty, cause, depth + 1, obligations).into()
.infcx()
.infer_projection(param_env, projection_ty, cause, depth + 1, obligations)
.into()
}) })
} }
@ -1018,7 +1015,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
depth: usize, depth: usize,
obligations: &mut Vec<PredicateObligation<'tcx>>, obligations: &mut Vec<PredicateObligation<'tcx>>,
) -> Result<Option<Term<'tcx>>, InProgress> { ) -> Result<Option<Term<'tcx>>, InProgress> {
let infcx = selcx.infcx(); let infcx = selcx.infcx;
// Don't use the projection cache in intercrate mode - // Don't use the projection cache in intercrate mode -
// the `infcx` may be re-used between intercrate in non-intercrate // the `infcx` may be re-used between intercrate in non-intercrate
// mode, which could lead to using incorrect cache results. // mode, which could lead to using incorrect cache results.
@ -1110,7 +1107,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
// an impl, where-clause etc) and hence we must // an impl, where-clause etc) and hence we must
// re-normalize it // re-normalize it
let projected_term = selcx.infcx().resolve_vars_if_possible(projected_term); let projected_term = selcx.infcx.resolve_vars_if_possible(projected_term);
let mut result = if projected_term.has_projections() { let mut result = if projected_term.has_projections() {
let mut normalizer = AssocTypeNormalizer::new( let mut normalizer = AssocTypeNormalizer::new(
@ -1206,9 +1203,9 @@ fn normalize_to_error<'a, 'tcx>(
param_env, param_env,
predicate: trait_ref.without_const().to_predicate(selcx.tcx()), predicate: trait_ref.without_const().to_predicate(selcx.tcx()),
}; };
let tcx = selcx.infcx().tcx; let tcx = selcx.infcx.tcx;
let def_id = projection_ty.item_def_id; let def_id = projection_ty.item_def_id;
let new_value = selcx.infcx().next_ty_var(TypeVariableOrigin { let new_value = selcx.infcx.next_ty_var(TypeVariableOrigin {
kind: TypeVariableOriginKind::NormalizeProjectionType, kind: TypeVariableOriginKind::NormalizeProjectionType,
span: tcx.def_span(def_id), span: tcx.def_span(def_id),
}); });
@ -1330,7 +1327,7 @@ fn assemble_candidate_for_impl_trait_in_trait<'cx, 'tcx>(
let trait_predicate = let trait_predicate =
ty::Binder::dummy(ty::TraitRef { def_id: trait_def_id, substs: trait_substs }); ty::Binder::dummy(ty::TraitRef { def_id: trait_def_id, substs: trait_substs });
let _ = selcx.infcx().commit_if_ok(|_| { let _ = selcx.infcx.commit_if_ok(|_| {
match selcx.select(&obligation.with(tcx, trait_predicate)) { match selcx.select(&obligation.with(tcx, trait_predicate)) {
Ok(Some(super::ImplSource::UserDefined(data))) => { Ok(Some(super::ImplSource::UserDefined(data))) => {
candidate_set.push_candidate(ProjectionCandidate::ImplTraitInTrait( candidate_set.push_candidate(ProjectionCandidate::ImplTraitInTrait(
@ -1435,7 +1432,7 @@ fn assemble_candidates_from_object_ty<'cx, 'tcx>(
let tcx = selcx.tcx(); let tcx = selcx.tcx();
let self_ty = obligation.predicate.self_ty(); let self_ty = obligation.predicate.self_ty();
let object_ty = selcx.infcx().shallow_resolve(self_ty); let object_ty = selcx.infcx.shallow_resolve(self_ty);
let data = match object_ty.kind() { let data = match object_ty.kind() {
ty::Dynamic(data, ..) => data, ty::Dynamic(data, ..) => data,
ty::Infer(ty::TyVar(_)) => { ty::Infer(ty::TyVar(_)) => {
@ -1473,7 +1470,7 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
env_predicates: impl Iterator<Item = ty::Predicate<'tcx>>, env_predicates: impl Iterator<Item = ty::Predicate<'tcx>>,
potentially_unnormalized_candidates: bool, potentially_unnormalized_candidates: bool,
) { ) {
let infcx = selcx.infcx(); let infcx = selcx.infcx;
for predicate in env_predicates { for predicate in env_predicates {
let bound_predicate = predicate.kind(); let bound_predicate = predicate.kind();
if let ty::PredicateKind::Clause(ty::Clause::Projection(data)) = if let ty::PredicateKind::Clause(ty::Clause::Projection(data)) =
@ -1529,7 +1526,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
// start out by selecting the predicate `T as TraitRef<...>`: // start out by selecting the predicate `T as TraitRef<...>`:
let poly_trait_ref = ty::Binder::dummy(obligation.predicate.trait_ref(selcx.tcx())); let poly_trait_ref = ty::Binder::dummy(obligation.predicate.trait_ref(selcx.tcx()));
let trait_obligation = obligation.with(selcx.tcx(), poly_trait_ref); let trait_obligation = obligation.with(selcx.tcx(), poly_trait_ref);
let _ = selcx.infcx().commit_if_ok(|_| { let _ = selcx.infcx.commit_if_ok(|_| {
let impl_source = match selcx.select(&trait_obligation) { let impl_source = match selcx.select(&trait_obligation) {
Ok(Some(impl_source)) => impl_source, Ok(Some(impl_source)) => impl_source,
Ok(None) => { Ok(None) => {
@ -1587,7 +1584,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
if obligation.param_env.reveal() == Reveal::All { if obligation.param_env.reveal() == Reveal::All {
// NOTE(eddyb) inference variables can resolve to parameters, so // NOTE(eddyb) inference variables can resolve to parameters, so
// assume `poly_trait_ref` isn't monomorphic, if it contains any. // assume `poly_trait_ref` isn't monomorphic, if it contains any.
let poly_trait_ref = selcx.infcx().resolve_vars_if_possible(poly_trait_ref); let poly_trait_ref = selcx.infcx.resolve_vars_if_possible(poly_trait_ref);
!poly_trait_ref.still_further_specializable() !poly_trait_ref.still_further_specializable()
} else { } else {
debug!( debug!(
@ -1603,7 +1600,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
// While a builtin impl may be known to exist, the associated type may not yet // While a builtin impl may be known to exist, the associated type may not yet
// be known. Any type with multiple potential associated types is therefore // be known. Any type with multiple potential associated types is therefore
// not eligible. // not eligible.
let self_ty = selcx.infcx().shallow_resolve(obligation.predicate.self_ty()); let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
let lang_items = selcx.tcx().lang_items(); let lang_items = selcx.tcx().lang_items();
if lang_items.discriminant_kind_trait() == Some(poly_trait_ref.def_id()) { if lang_items.discriminant_kind_trait() == Some(poly_trait_ref.def_id()) {
@ -1690,7 +1687,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
// type parameters, opaques, and unnormalized projections have pointer // type parameters, opaques, and unnormalized projections have pointer
// metadata if they're known (e.g. by the param_env) to be sized // metadata if they're known (e.g. by the param_env) to be sized
ty::Param(_) | ty::Projection(..) | ty::Opaque(..) ty::Param(_) | ty::Projection(..) | ty::Opaque(..)
if selcx.infcx().predicate_must_hold_modulo_regions( if selcx.infcx.predicate_must_hold_modulo_regions(
&obligation.with( &obligation.with(
selcx.tcx(), selcx.tcx(),
ty::Binder::dummy( ty::Binder::dummy(
@ -1818,8 +1815,7 @@ fn confirm_candidate<'cx, 'tcx>(
// when possible for this to work. See `auto-trait-projection-recursion.rs` // when possible for this to work. See `auto-trait-projection-recursion.rs`
// for a case where this matters. // for a case where this matters.
if progress.term.has_infer_regions() { if progress.term.has_infer_regions() {
progress.term = progress.term = progress.term.fold_with(&mut OpportunisticRegionResolver::new(selcx.infcx));
progress.term.fold_with(&mut OpportunisticRegionResolver::new(selcx.infcx()));
} }
progress progress
} }
@ -2000,7 +1996,7 @@ fn confirm_fn_pointer_candidate<'cx, 'tcx>(
obligation: &ProjectionTyObligation<'tcx>, obligation: &ProjectionTyObligation<'tcx>,
fn_pointer_impl_source: ImplSourceFnPointerData<'tcx, PredicateObligation<'tcx>>, fn_pointer_impl_source: ImplSourceFnPointerData<'tcx, PredicateObligation<'tcx>>,
) -> Progress<'tcx> { ) -> Progress<'tcx> {
let fn_type = selcx.infcx().shallow_resolve(fn_pointer_impl_source.fn_ty); let fn_type = selcx.infcx.shallow_resolve(fn_pointer_impl_source.fn_ty);
let sig = fn_type.fn_sig(selcx.tcx()); let sig = fn_type.fn_sig(selcx.tcx());
let Normalized { value: sig, obligations } = normalize_with_depth( let Normalized { value: sig, obligations } = normalize_with_depth(
selcx, selcx,
@ -2073,7 +2069,7 @@ fn confirm_param_env_candidate<'cx, 'tcx>(
poly_cache_entry: ty::PolyProjectionPredicate<'tcx>, poly_cache_entry: ty::PolyProjectionPredicate<'tcx>,
potentially_unnormalized_candidate: bool, potentially_unnormalized_candidate: bool,
) -> Progress<'tcx> { ) -> Progress<'tcx> {
let infcx = selcx.infcx(); let infcx = selcx.infcx;
let cause = &obligation.cause; let cause = &obligation.cause;
let param_env = obligation.param_env; let param_env = obligation.param_env;
@ -2168,7 +2164,7 @@ fn confirm_impl_candidate<'cx, 'tcx>(
// * `substs` ends up as `[u32, S]` // * `substs` ends up as `[u32, S]`
let substs = obligation.predicate.substs.rebase_onto(tcx, trait_def_id, substs); let substs = obligation.predicate.substs.rebase_onto(tcx, trait_def_id, substs);
let substs = let substs =
translate_substs(selcx.infcx(), param_env, impl_def_id, substs, assoc_ty.defining_node); translate_substs(selcx.infcx, param_env, impl_def_id, substs, assoc_ty.defining_node);
let ty = tcx.bound_type_of(assoc_ty.item.def_id); let ty = tcx.bound_type_of(assoc_ty.item.def_id);
let is_const = matches!(tcx.def_kind(assoc_ty.item.def_id), DefKind::AssocConst); let is_const = matches!(tcx.def_kind(assoc_ty.item.def_id), DefKind::AssocConst);
let term: ty::EarlyBinder<ty::Term<'tcx>> = if is_const { let term: ty::EarlyBinder<ty::Term<'tcx>> = if is_const {
@ -2264,7 +2260,7 @@ fn confirm_impl_trait_in_trait_candidate<'tcx>(
let impl_fn_substs = let impl_fn_substs =
obligation.predicate.substs.rebase_onto(tcx, tcx.parent(trait_fn_def_id), data.substs); obligation.predicate.substs.rebase_onto(tcx, tcx.parent(trait_fn_def_id), data.substs);
let impl_fn_substs = translate_substs( let impl_fn_substs = translate_substs(
selcx.infcx(), selcx.infcx,
obligation.param_env, obligation.param_env,
data.impl_def_id, data.impl_def_id,
impl_fn_substs, impl_fn_substs,
@ -2424,7 +2420,7 @@ impl<'cx, 'tcx> ProjectionCacheKeyExt<'cx, 'tcx> for ProjectionCacheKey<'tcx> {
selcx: &mut SelectionContext<'cx, 'tcx>, selcx: &mut SelectionContext<'cx, 'tcx>,
predicate: ty::PolyProjectionPredicate<'tcx>, predicate: ty::PolyProjectionPredicate<'tcx>,
) -> Option<Self> { ) -> Option<Self> {
let infcx = selcx.infcx(); let infcx = selcx.infcx;
// We don't do cross-snapshot caching of obligations with escaping regions, // We don't do cross-snapshot caching of obligations with escaping regions,
// so there's no cache key to use // so there's no cache key to use
predicate.no_bound_vars().map(|predicate| { predicate.no_bound_vars().map(|predicate| {

View file

@ -238,7 +238,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
param_env: obligation.param_env, param_env: obligation.param_env,
cause: obligation.cause.clone(), cause: obligation.cause.clone(),
recursion_depth: obligation.recursion_depth, recursion_depth: obligation.recursion_depth,
predicate: self.infcx().resolve_vars_if_possible(obligation.predicate), predicate: self.infcx.resolve_vars_if_possible(obligation.predicate),
}; };
if obligation.predicate.skip_binder().self_ty().is_ty_var() { if obligation.predicate.skip_binder().self_ty().is_ty_var() {
@ -689,9 +689,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
debug!(?poly_trait_ref, "assemble_candidates_from_object_ty"); debug!(?poly_trait_ref, "assemble_candidates_from_object_ty");
let poly_trait_predicate = self.infcx().resolve_vars_if_possible(obligation.predicate); let poly_trait_predicate = self.infcx.resolve_vars_if_possible(obligation.predicate);
let placeholder_trait_predicate = let placeholder_trait_predicate =
self.infcx().replace_bound_vars_with_placeholders(poly_trait_predicate); self.infcx.replace_bound_vars_with_placeholders(poly_trait_predicate);
// Count only those upcast versions that match the trait-ref // Count only those upcast versions that match the trait-ref
// we are looking for. Specifically, do not only check for the // we are looking for. Specifically, do not only check for the
@ -940,7 +940,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
return; return;
} }
let self_ty = self.infcx().shallow_resolve(obligation.self_ty()); let self_ty = self.infcx.shallow_resolve(obligation.self_ty());
match self_ty.skip_binder().kind() { match self_ty.skip_binder().kind() {
ty::Opaque(..) ty::Opaque(..)
| ty::Dynamic(..) | ty::Dynamic(..)
@ -1007,7 +1007,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation: &TraitObligation<'tcx>, obligation: &TraitObligation<'tcx>,
candidates: &mut SelectionCandidateSet<'tcx>, candidates: &mut SelectionCandidateSet<'tcx>,
) { ) {
let self_ty = self.infcx().shallow_resolve(obligation.self_ty().skip_binder()); let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder());
match self_ty.kind() { match self_ty.kind() {
ty::Tuple(_) => { ty::Tuple(_) => {
candidates.vec.push(BuiltinCandidate { has_nested: false }); candidates.vec.push(BuiltinCandidate { has_nested: false });

View file

@ -147,7 +147,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let trait_predicate = self.infcx.shallow_resolve(obligation.predicate); let trait_predicate = self.infcx.shallow_resolve(obligation.predicate);
let placeholder_trait_predicate = let placeholder_trait_predicate =
self.infcx().replace_bound_vars_with_placeholders(trait_predicate).trait_ref; self.infcx.replace_bound_vars_with_placeholders(trait_predicate).trait_ref;
let placeholder_self_ty = placeholder_trait_predicate.self_ty(); let placeholder_self_ty = placeholder_trait_predicate.self_ty();
let placeholder_trait_predicate = ty::Binder::dummy(placeholder_trait_predicate); let placeholder_trait_predicate = ty::Binder::dummy(placeholder_trait_predicate);
let (def_id, substs) = match *placeholder_self_ty.kind() { let (def_id, substs) = match *placeholder_self_ty.kind() {
@ -639,7 +639,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
debug!(?obligation, "confirm_trait_alias_candidate"); debug!(?obligation, "confirm_trait_alias_candidate");
let alias_def_id = obligation.predicate.def_id(); let alias_def_id = obligation.predicate.def_id();
let predicate = self.infcx().replace_bound_vars_with_placeholders(obligation.predicate); let predicate = self.infcx.replace_bound_vars_with_placeholders(obligation.predicate);
let trait_ref = predicate.trait_ref; let trait_ref = predicate.trait_ref;
let trait_def_id = trait_ref.def_id; let trait_def_id = trait_ref.def_id;
let substs = trait_ref.substs; let substs = trait_ref.substs;

View file

@ -101,7 +101,7 @@ impl IntercrateAmbiguityCause {
} }
pub struct SelectionContext<'cx, 'tcx> { pub struct SelectionContext<'cx, 'tcx> {
infcx: &'cx InferCtxt<'tcx>, pub infcx: &'cx InferCtxt<'tcx>,
/// Freshener used specifically for entries on the obligation /// Freshener used specifically for entries on the obligation
/// stack. This ensures that all entries on the stack at one time /// stack. This ensures that all entries on the stack at one time
@ -237,10 +237,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
self.intercrate_ambiguity_causes.take().unwrap_or_default() self.intercrate_ambiguity_causes.take().unwrap_or_default()
} }
pub fn infcx(&self) -> &'cx InferCtxt<'tcx> {
self.infcx
}
pub fn tcx(&self) -> TyCtxt<'tcx> { pub fn tcx(&self) -> TyCtxt<'tcx> {
self.infcx.tcx self.infcx.tcx
} }
@ -693,10 +689,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
match (evaluate(c1), evaluate(c2)) { match (evaluate(c1), evaluate(c2)) {
(Ok(c1), Ok(c2)) => { (Ok(c1), Ok(c2)) => {
match self match self.infcx.at(&obligation.cause, obligation.param_env).eq(c1, c2)
.infcx()
.at(&obligation.cause, obligation.param_env)
.eq(c1, c2)
{ {
Ok(_) => Ok(EvaluatedToOk), Ok(_) => Ok(EvaluatedToOk),
Err(_) => Ok(EvaluatedToErr), Err(_) => Ok(EvaluatedToErr),
@ -1212,7 +1205,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
} }
let obligation = &stack.obligation; let obligation = &stack.obligation;
let predicate = self.infcx().resolve_vars_if_possible(obligation.predicate); let predicate = self.infcx.resolve_vars_if_possible(obligation.predicate);
// Okay to skip binder because of the nature of the // Okay to skip binder because of the nature of the
// trait-ref-is-knowable check, which does not care about // trait-ref-is-knowable check, which does not care about
@ -1349,9 +1342,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
&mut self, &mut self,
obligation: &TraitObligation<'tcx>, obligation: &TraitObligation<'tcx>,
) -> smallvec::SmallVec<[(usize, ty::BoundConstness); 2]> { ) -> smallvec::SmallVec<[(usize, ty::BoundConstness); 2]> {
let poly_trait_predicate = self.infcx().resolve_vars_if_possible(obligation.predicate); let poly_trait_predicate = self.infcx.resolve_vars_if_possible(obligation.predicate);
let placeholder_trait_predicate = let placeholder_trait_predicate =
self.infcx().replace_bound_vars_with_placeholders(poly_trait_predicate); self.infcx.replace_bound_vars_with_placeholders(poly_trait_predicate);
debug!(?placeholder_trait_predicate); debug!(?placeholder_trait_predicate);
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;
@ -2131,7 +2124,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation: &TraitObligation<'tcx>, obligation: &TraitObligation<'tcx>,
) -> Result<Normalized<'tcx, SubstsRef<'tcx>>, ()> { ) -> Result<Normalized<'tcx, SubstsRef<'tcx>>, ()> {
let placeholder_obligation = let placeholder_obligation =
self.infcx().replace_bound_vars_with_placeholders(obligation.predicate); self.infcx.replace_bound_vars_with_placeholders(obligation.predicate);
let placeholder_obligation_trait_ref = placeholder_obligation.trait_ref; let placeholder_obligation_trait_ref = placeholder_obligation.trait_ref;
let impl_substs = self.infcx.fresh_substs_for_item(obligation.cause.span, impl_def_id); let impl_substs = self.infcx.fresh_substs_for_item(obligation.cause.span, impl_def_id);

View file

@ -203,13 +203,13 @@ pub fn impl_subject_and_oblig<'a, 'tcx>(
let subject = selcx.tcx().bound_impl_subject(impl_def_id); let subject = selcx.tcx().bound_impl_subject(impl_def_id);
let subject = subject.subst(selcx.tcx(), impl_substs); let subject = subject.subst(selcx.tcx(), impl_substs);
let InferOk { value: subject, obligations: normalization_obligations1 } = selcx let InferOk { value: subject, obligations: normalization_obligations1 } = selcx
.infcx() .infcx
.partially_normalize_associated_types_in(ObligationCause::dummy(), param_env, subject); .partially_normalize_associated_types_in(ObligationCause::dummy(), param_env, subject);
let predicates = selcx.tcx().predicates_of(impl_def_id); let predicates = selcx.tcx().predicates_of(impl_def_id);
let predicates = predicates.instantiate(selcx.tcx(), impl_substs); let predicates = predicates.instantiate(selcx.tcx(), impl_substs);
let InferOk { value: predicates, obligations: normalization_obligations2 } = selcx let InferOk { value: predicates, obligations: normalization_obligations2 } = selcx
.infcx() .infcx
.partially_normalize_associated_types_in(ObligationCause::dummy(), param_env, predicates); .partially_normalize_associated_types_in(ObligationCause::dummy(), param_env, predicates);
let impl_obligations = let impl_obligations =
super::predicates_for_generics(|_, _| ObligationCause::dummy(), param_env, predicates); super::predicates_for_generics(|_, _| ObligationCause::dummy(), param_env, predicates);