Use infcx.partially_normalize_associated_types_in
This commit is contained in:
parent
341d8b8a2c
commit
3dee3aac78
@ -31,6 +31,7 @@
|
|||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use rustc_span::{symbol::Ident, Span, Symbol, DUMMY_SP};
|
use rustc_span::{symbol::Ident, Span, Symbol, DUMMY_SP};
|
||||||
use rustc_trait_selection::autoderef::{self, Autoderef};
|
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::evaluate_obligation::InferCtxtExt;
|
||||||
use rustc_trait_selection::traits::query::method_autoderef::MethodAutoderefBadTy;
|
use rustc_trait_selection::traits::query::method_autoderef::MethodAutoderefBadTy;
|
||||||
use rustc_trait_selection::traits::query::method_autoderef::{
|
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,
|
// maybe shouldn't include `Param`s, but rather fresh variables or be canonicalized,
|
||||||
// see issue #89650
|
// see issue #89650
|
||||||
let cause = traits::ObligationCause::misc(self.span, self.body_id);
|
let cause = traits::ObligationCause::misc(self.span, self.body_id);
|
||||||
let selcx = &mut traits::SelectionContext::new(self.fcx);
|
let InferOk { value: xform_self_ty, obligations } = self
|
||||||
let traits::Normalized { value: xform_self_ty, obligations } =
|
.fcx
|
||||||
traits::normalize(selcx, self.param_env, cause, xform_self_ty);
|
.partially_normalize_associated_types_in(cause, self.param_env, xform_self_ty);
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"assemble_inherent_impl_probe after normalization: xform_self_ty = {:?}/{:?}",
|
"assemble_inherent_impl_probe after normalization: xform_self_ty = {:?}/{:?}",
|
||||||
xform_self_ty, xform_ret_ty
|
xform_self_ty, xform_ret_ty
|
||||||
@ -1490,7 +1492,6 @@ fn consider_probe(
|
|||||||
let mut xform_ret_ty = probe.xform_ret_ty;
|
let mut xform_ret_ty = probe.xform_ret_ty;
|
||||||
debug!(?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 cause = traits::ObligationCause::misc(self.span, self.body_id);
|
||||||
|
|
||||||
let mut parent_pred = None;
|
let mut parent_pred = None;
|
||||||
@ -1504,10 +1505,14 @@ fn consider_probe(
|
|||||||
// `xform_ret_ty` hasn't been normalized yet, only `xform_self_ty`,
|
// `xform_ret_ty` hasn't been normalized yet, only `xform_self_ty`,
|
||||||
// see the reasons mentioned in the comments in `assemble_inherent_impl_probe`
|
// see the reasons mentioned in the comments in `assemble_inherent_impl_probe`
|
||||||
// for why this is necessary
|
// for why this is necessary
|
||||||
let traits::Normalized {
|
let InferOk {
|
||||||
value: normalized_xform_ret_ty,
|
value: normalized_xform_ret_ty,
|
||||||
obligations: normalization_obligations,
|
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;
|
xform_ret_ty = normalized_xform_ret_ty;
|
||||||
debug!("xform_ret_ty after normalization: {:?}", 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_def_id = probe.item.container_id(self.tcx);
|
||||||
let impl_bounds = self.tcx.predicates_of(impl_def_id);
|
let impl_bounds = self.tcx.predicates_of(impl_def_id);
|
||||||
let impl_bounds = impl_bounds.instantiate(self.tcx, substs);
|
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.
|
// Convert the bounds into obligations.
|
||||||
let impl_obligations = traits::predicates_for_generics(
|
let impl_obligations = traits::predicates_for_generics(
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
};
|
};
|
||||||
use crate::infer::error_reporting::{TyCategory, TypeAnnotationNeeded as ErrorCode};
|
use crate::infer::error_reporting::{TyCategory, TypeAnnotationNeeded as ErrorCode};
|
||||||
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||||
|
use crate::infer::InferCtxtExt as _;
|
||||||
use crate::infer::{self, InferCtxt, TyCtxtInferExt};
|
use crate::infer::{self, InferCtxt, TyCtxtInferExt};
|
||||||
use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
|
use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
|
||||||
use crate::traits::query::normalize::AtExt as _;
|
use crate::traits::query::normalize::AtExt as _;
|
||||||
@ -28,7 +29,7 @@
|
|||||||
use rustc_hir::Item;
|
use rustc_hir::Item;
|
||||||
use rustc_hir::Node;
|
use rustc_hir::Node;
|
||||||
use rustc_infer::infer::error_reporting::TypeErrCtxt;
|
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::traits::select::OverflowError;
|
||||||
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
|
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
|
||||||
use rustc_middle::ty::error::ExpectedFound;
|
use rustc_middle::ty::error::ExpectedFound;
|
||||||
@ -2528,18 +2529,15 @@ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.probe(|_| {
|
self.probe(|_| {
|
||||||
let mut selcx = SelectionContext::new(self);
|
|
||||||
|
|
||||||
let cleaned_pred =
|
let cleaned_pred =
|
||||||
pred.fold_with(&mut ParamToVarFolder { infcx: self, var_map: Default::default() });
|
pred.fold_with(&mut ParamToVarFolder { infcx: self, var_map: Default::default() });
|
||||||
|
|
||||||
let cleaned_pred = super::project::normalize(
|
let InferOk { value: cleaned_pred, .. } =
|
||||||
&mut selcx,
|
self.infcx.partially_normalize_associated_types_in(
|
||||||
param_env,
|
|
||||||
ObligationCause::dummy(),
|
ObligationCause::dummy(),
|
||||||
|
param_env,
|
||||||
cleaned_pred,
|
cleaned_pred,
|
||||||
)
|
);
|
||||||
.value;
|
|
||||||
|
|
||||||
let obligation =
|
let obligation =
|
||||||
Obligation::new(self.tcx, ObligationCause::dummy(), param_env, cleaned_pred);
|
Obligation::new(self.tcx, ObligationCause::dummy(), param_env, cleaned_pred);
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
use super::{
|
use super::{DefIdOrName, Obligation, ObligationCause, ObligationCauseCode, PredicateObligation};
|
||||||
DefIdOrName, Obligation, ObligationCause, ObligationCauseCode, PredicateObligation,
|
|
||||||
SelectionContext,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::autoderef::Autoderef;
|
use crate::autoderef::Autoderef;
|
||||||
use crate::infer::InferCtxt;
|
use crate::infer::InferCtxt;
|
||||||
use crate::traits::normalize_to;
|
|
||||||
|
|
||||||
use hir::def::CtorOf;
|
use hir::def::CtorOf;
|
||||||
use hir::HirId;
|
use hir::HirId;
|
||||||
@ -23,7 +19,7 @@
|
|||||||
use rustc_hir::{AsyncGeneratorKind, GeneratorKind, Node};
|
use rustc_hir::{AsyncGeneratorKind, GeneratorKind, Node};
|
||||||
use rustc_infer::infer::error_reporting::TypeErrCtxt;
|
use rustc_infer::infer::error_reporting::TypeErrCtxt;
|
||||||
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
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::hir::map;
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{
|
||||||
self, suggest_arbitrary_trait_bound, suggest_constraining_type_param, AdtKind, DefIdTree,
|
self, suggest_arbitrary_trait_bound, suggest_constraining_type_param, AdtKind, DefIdTree,
|
||||||
@ -2986,12 +2982,11 @@ fn suggest_await_before_try(
|
|||||||
self.tcx.mk_substs_trait(trait_pred.self_ty(), []),
|
self.tcx.mk_substs_trait(trait_pred.self_ty(), []),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
let projection_ty = normalize_to(
|
let InferOk { value: projection_ty, .. } = self
|
||||||
&mut SelectionContext::new(self),
|
.partially_normalize_associated_types_in(
|
||||||
obligation.param_env,
|
|
||||||
obligation.cause.clone(),
|
obligation.cause.clone(),
|
||||||
|
obligation.param_env,
|
||||||
projection_ty,
|
projection_ty,
|
||||||
&mut vec![],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
|
@ -8,7 +8,9 @@
|
|||||||
use rustc_middle::ty::{self, ImplSubject, ToPredicate, Ty, TyCtxt, TypeVisitable};
|
use rustc_middle::ty::{self, ImplSubject, ToPredicate, Ty, TyCtxt, TypeVisitable};
|
||||||
use rustc_middle::ty::{GenericArg, SubstsRef};
|
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::*};
|
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>>) {
|
) -> (ImplSubject<'tcx>, impl Iterator<Item = PredicateObligation<'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 Normalized { value: subject, obligations: normalization_obligations1 } =
|
let InferOk { value: subject, obligations: normalization_obligations1 } = selcx
|
||||||
super::normalize(selcx, param_env, ObligationCause::dummy(), subject);
|
.infcx()
|
||||||
|
.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 Normalized { value: predicates, obligations: normalization_obligations2 } =
|
let InferOk { value: predicates, obligations: normalization_obligations2 } = selcx
|
||||||
super::normalize(selcx, param_env, ObligationCause::dummy(), predicates);
|
.infcx()
|
||||||
|
.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);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user