Rollup merge of #104835 - spastorino:use-partially_normalize_associated_types_in, r=lcnr

Use infcx.partially_normalize_associated_types_in

r? ``@lcnr``
This commit is contained in:
Matthias Krüger 2022-11-25 18:35:41 +01:00 committed by GitHub
commit 7fac5048c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 36 deletions

View File

@ -31,6 +31,7 @@
use rustc_span::symbol::sym;
use rustc_span::{symbol::Ident, Span, Symbol, DUMMY_SP};
use rustc_trait_selection::autoderef::{self, Autoderef};
use rustc_trait_selection::infer::InferCtxtExt as _;
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
use rustc_trait_selection::traits::query::method_autoderef::MethodAutoderefBadTy;
use rustc_trait_selection::traits::query::method_autoderef::{
@ -716,9 +717,10 @@ fn assemble_inherent_impl_probe(&mut self, impl_def_id: DefId) {
// maybe shouldn't include `Param`s, but rather fresh variables or be canonicalized,
// see issue #89650
let cause = traits::ObligationCause::misc(self.span, self.body_id);
let selcx = &mut traits::SelectionContext::new(self.fcx);
let traits::Normalized { value: xform_self_ty, obligations } =
traits::normalize(selcx, self.param_env, cause, xform_self_ty);
let InferOk { value: xform_self_ty, obligations } = self
.fcx
.partially_normalize_associated_types_in(cause, self.param_env, xform_self_ty);
debug!(
"assemble_inherent_impl_probe after normalization: xform_self_ty = {:?}/{:?}",
xform_self_ty, xform_ret_ty
@ -1490,7 +1492,6 @@ fn consider_probe(
let mut xform_ret_ty = probe.xform_ret_ty;
debug!(?xform_ret_ty);
let selcx = &mut traits::SelectionContext::new(self);
let cause = traits::ObligationCause::misc(self.span, self.body_id);
let mut parent_pred = None;
@ -1504,10 +1505,14 @@ fn consider_probe(
// `xform_ret_ty` hasn't been normalized yet, only `xform_self_ty`,
// see the reasons mentioned in the comments in `assemble_inherent_impl_probe`
// for why this is necessary
let traits::Normalized {
let InferOk {
value: normalized_xform_ret_ty,
obligations: normalization_obligations,
} = traits::normalize(selcx, self.param_env, cause.clone(), probe.xform_ret_ty);
} = self.fcx.partially_normalize_associated_types_in(
cause.clone(),
self.param_env,
probe.xform_ret_ty,
);
xform_ret_ty = normalized_xform_ret_ty;
debug!("xform_ret_ty after normalization: {:?}", xform_ret_ty);
@ -1515,8 +1520,13 @@ fn consider_probe(
let impl_def_id = probe.item.container_id(self.tcx);
let impl_bounds = self.tcx.predicates_of(impl_def_id);
let impl_bounds = impl_bounds.instantiate(self.tcx, substs);
let traits::Normalized { value: impl_bounds, obligations: norm_obligations } =
traits::normalize(selcx, self.param_env, cause.clone(), impl_bounds);
let InferOk { value: impl_bounds, obligations: norm_obligations } =
self.fcx.partially_normalize_associated_types_in(
cause.clone(),
self.param_env,
impl_bounds,
);
// Convert the bounds into obligations.
let impl_obligations = traits::predicates_for_generics(

View File

@ -9,6 +9,7 @@
};
use crate::infer::error_reporting::{TyCategory, TypeAnnotationNeeded as ErrorCode};
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use crate::infer::InferCtxtExt as _;
use crate::infer::{self, InferCtxt, TyCtxtInferExt};
use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
use crate::traits::query::normalize::AtExt as _;
@ -28,7 +29,7 @@
use rustc_hir::Item;
use rustc_hir::Node;
use rustc_infer::infer::error_reporting::TypeErrCtxt;
use rustc_infer::infer::TypeTrace;
use rustc_infer::infer::{InferOk, TypeTrace};
use rustc_middle::traits::select::OverflowError;
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
use rustc_middle::ty::error::ExpectedFound;
@ -2525,18 +2526,15 @@ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'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 = super::project::normalize(
&mut selcx,
param_env,
ObligationCause::dummy(),
cleaned_pred,
)
.value;
let InferOk { value: cleaned_pred, .. } =
self.infcx.partially_normalize_associated_types_in(
ObligationCause::dummy(),
param_env,
cleaned_pred,
);
let obligation =
Obligation::new(self.tcx, ObligationCause::dummy(), param_env, cleaned_pred);

View File

@ -1,11 +1,7 @@
use super::{
DefIdOrName, Obligation, ObligationCause, ObligationCauseCode, PredicateObligation,
SelectionContext,
};
use super::{DefIdOrName, Obligation, ObligationCause, ObligationCauseCode, PredicateObligation};
use crate::autoderef::Autoderef;
use crate::infer::InferCtxt;
use crate::traits::normalize_to;
use hir::def::CtorOf;
use hir::HirId;
@ -23,7 +19,7 @@
use rustc_hir::{AsyncGeneratorKind, GeneratorKind, Node};
use rustc_infer::infer::error_reporting::TypeErrCtxt;
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc_infer::infer::LateBoundRegionConversionTime;
use rustc_infer::infer::{InferOk, LateBoundRegionConversionTime};
use rustc_middle::hir::map;
use rustc_middle::ty::{
self, suggest_arbitrary_trait_bound, suggest_constraining_type_param, AdtKind, DefIdTree,
@ -2979,13 +2975,12 @@ fn suggest_await_before_try(
self.tcx.mk_substs_trait(trait_pred.self_ty(), []),
)
});
let projection_ty = normalize_to(
&mut SelectionContext::new(self),
obligation.param_env,
obligation.cause.clone(),
projection_ty,
&mut vec![],
);
let InferOk { value: projection_ty, .. } = self
.partially_normalize_associated_types_in(
obligation.cause.clone(),
obligation.param_env,
projection_ty,
);
debug!(
normalized_projection_type = ?self.resolve_vars_if_possible(projection_ty)

View File

@ -8,7 +8,9 @@
use rustc_middle::ty::{self, ImplSubject, ToPredicate, Ty, TyCtxt, TypeVisitable};
use rustc_middle::ty::{GenericArg, SubstsRef};
use super::{Normalized, Obligation, ObligationCause, PredicateObligation, SelectionContext};
use super::{Obligation, ObligationCause, PredicateObligation, SelectionContext};
use crate::infer::InferCtxtExt;
use rustc_infer::infer::InferOk;
pub use rustc_infer::traits::{self, util::*};
///////////////////////////////////////////////////////////////////////////
@ -200,13 +202,15 @@ pub fn impl_subject_and_oblig<'a, 'tcx>(
) -> (ImplSubject<'tcx>, impl Iterator<Item = PredicateObligation<'tcx>>) {
let subject = selcx.tcx().bound_impl_subject(impl_def_id);
let subject = subject.subst(selcx.tcx(), impl_substs);
let Normalized { value: subject, obligations: normalization_obligations1 } =
super::normalize(selcx, param_env, ObligationCause::dummy(), subject);
let InferOk { value: subject, obligations: normalization_obligations1 } = selcx
.infcx()
.partially_normalize_associated_types_in(ObligationCause::dummy(), param_env, subject);
let predicates = selcx.tcx().predicates_of(impl_def_id);
let predicates = predicates.instantiate(selcx.tcx(), impl_substs);
let Normalized { value: predicates, obligations: normalization_obligations2 } =
super::normalize(selcx, param_env, ObligationCause::dummy(), predicates);
let InferOk { value: predicates, obligations: normalization_obligations2 } = selcx
.infcx()
.partially_normalize_associated_types_in(ObligationCause::dummy(), param_env, predicates);
let impl_obligations =
super::predicates_for_generics(|_, _| ObligationCause::dummy(), param_env, predicates);