Skip to content

Commit 7fac504

Browse files
authored
Rollup merge of #104835 - spastorino:use-partially_normalize_associated_types_in, r=lcnr
Use infcx.partially_normalize_associated_types_in r? ``@lcnr``
2 parents aec60c6 + 3dee3aa commit 7fac504

File tree

4 files changed

+43
-36
lines changed

4 files changed

+43
-36
lines changed

compiler/rustc_hir_typeck/src/method/probe.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use rustc_span::lev_distance::{
3131
use rustc_span::symbol::sym;
3232
use rustc_span::{symbol::Ident, Span, Symbol, DUMMY_SP};
3333
use rustc_trait_selection::autoderef::{self, Autoderef};
34+
use rustc_trait_selection::infer::InferCtxtExt as _;
3435
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
3536
use rustc_trait_selection::traits::query::method_autoderef::MethodAutoderefBadTy;
3637
use rustc_trait_selection::traits::query::method_autoderef::{
@@ -716,9 +717,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
716717
// maybe shouldn't include `Param`s, but rather fresh variables or be canonicalized,
717718
// see issue #89650
718719
let cause = traits::ObligationCause::misc(self.span, self.body_id);
719-
let selcx = &mut traits::SelectionContext::new(self.fcx);
720-
let traits::Normalized { value: xform_self_ty, obligations } =
721-
traits::normalize(selcx, self.param_env, cause, xform_self_ty);
720+
let InferOk { value: xform_self_ty, obligations } = self
721+
.fcx
722+
.partially_normalize_associated_types_in(cause, self.param_env, xform_self_ty);
723+
722724
debug!(
723725
"assemble_inherent_impl_probe after normalization: xform_self_ty = {:?}/{:?}",
724726
xform_self_ty, xform_ret_ty
@@ -1490,7 +1492,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14901492
let mut xform_ret_ty = probe.xform_ret_ty;
14911493
debug!(?xform_ret_ty);
14921494

1493-
let selcx = &mut traits::SelectionContext::new(self);
14941495
let cause = traits::ObligationCause::misc(self.span, self.body_id);
14951496

14961497
let mut parent_pred = None;
@@ -1504,19 +1505,28 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
15041505
// `xform_ret_ty` hasn't been normalized yet, only `xform_self_ty`,
15051506
// see the reasons mentioned in the comments in `assemble_inherent_impl_probe`
15061507
// for why this is necessary
1507-
let traits::Normalized {
1508+
let InferOk {
15081509
value: normalized_xform_ret_ty,
15091510
obligations: normalization_obligations,
1510-
} = traits::normalize(selcx, self.param_env, cause.clone(), probe.xform_ret_ty);
1511+
} = self.fcx.partially_normalize_associated_types_in(
1512+
cause.clone(),
1513+
self.param_env,
1514+
probe.xform_ret_ty,
1515+
);
15111516
xform_ret_ty = normalized_xform_ret_ty;
15121517
debug!("xform_ret_ty after normalization: {:?}", xform_ret_ty);
15131518

15141519
// Check whether the impl imposes obligations we have to worry about.
15151520
let impl_def_id = probe.item.container_id(self.tcx);
15161521
let impl_bounds = self.tcx.predicates_of(impl_def_id);
15171522
let impl_bounds = impl_bounds.instantiate(self.tcx, substs);
1518-
let traits::Normalized { value: impl_bounds, obligations: norm_obligations } =
1519-
traits::normalize(selcx, self.param_env, cause.clone(), impl_bounds);
1523+
1524+
let InferOk { value: impl_bounds, obligations: norm_obligations } =
1525+
self.fcx.partially_normalize_associated_types_in(
1526+
cause.clone(),
1527+
self.param_env,
1528+
impl_bounds,
1529+
);
15201530

15211531
// Convert the bounds into obligations.
15221532
let impl_obligations = traits::predicates_for_generics(

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use super::{
99
};
1010
use crate::infer::error_reporting::{TyCategory, TypeAnnotationNeeded as ErrorCode};
1111
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
12+
use crate::infer::InferCtxtExt as _;
1213
use crate::infer::{self, InferCtxt, TyCtxtInferExt};
1314
use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
1415
use crate::traits::query::normalize::AtExt as _;
@@ -28,7 +29,7 @@ use rustc_hir::GenericParam;
2829
use rustc_hir::Item;
2930
use rustc_hir::Node;
3031
use rustc_infer::infer::error_reporting::TypeErrCtxt;
31-
use rustc_infer::infer::TypeTrace;
32+
use rustc_infer::infer::{InferOk, TypeTrace};
3233
use rustc_middle::traits::select::OverflowError;
3334
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
3435
use rustc_middle::ty::error::ExpectedFound;
@@ -2525,18 +2526,15 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
25252526
}
25262527

25272528
self.probe(|_| {
2528-
let mut selcx = SelectionContext::new(self);
2529-
25302529
let cleaned_pred =
25312530
pred.fold_with(&mut ParamToVarFolder { infcx: self, var_map: Default::default() });
25322531

2533-
let cleaned_pred = super::project::normalize(
2534-
&mut selcx,
2535-
param_env,
2536-
ObligationCause::dummy(),
2537-
cleaned_pred,
2538-
)
2539-
.value;
2532+
let InferOk { value: cleaned_pred, .. } =
2533+
self.infcx.partially_normalize_associated_types_in(
2534+
ObligationCause::dummy(),
2535+
param_env,
2536+
cleaned_pred,
2537+
);
25402538

25412539
let obligation =
25422540
Obligation::new(self.tcx, ObligationCause::dummy(), param_env, cleaned_pred);

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
use super::{
2-
DefIdOrName, Obligation, ObligationCause, ObligationCauseCode, PredicateObligation,
3-
SelectionContext,
4-
};
1+
use super::{DefIdOrName, Obligation, ObligationCause, ObligationCauseCode, PredicateObligation};
52

63
use crate::autoderef::Autoderef;
74
use crate::infer::InferCtxt;
8-
use crate::traits::normalize_to;
95

106
use hir::def::CtorOf;
117
use hir::HirId;
@@ -23,7 +19,7 @@ use rustc_hir::lang_items::LangItem;
2319
use rustc_hir::{AsyncGeneratorKind, GeneratorKind, Node};
2420
use rustc_infer::infer::error_reporting::TypeErrCtxt;
2521
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
26-
use rustc_infer::infer::LateBoundRegionConversionTime;
22+
use rustc_infer::infer::{InferOk, LateBoundRegionConversionTime};
2723
use rustc_middle::hir::map;
2824
use rustc_middle::ty::{
2925
self, suggest_arbitrary_trait_bound, suggest_constraining_type_param, AdtKind, DefIdTree,
@@ -2979,13 +2975,12 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
29792975
self.tcx.mk_substs_trait(trait_pred.self_ty(), []),
29802976
)
29812977
});
2982-
let projection_ty = normalize_to(
2983-
&mut SelectionContext::new(self),
2984-
obligation.param_env,
2985-
obligation.cause.clone(),
2986-
projection_ty,
2987-
&mut vec![],
2988-
);
2978+
let InferOk { value: projection_ty, .. } = self
2979+
.partially_normalize_associated_types_in(
2980+
obligation.cause.clone(),
2981+
obligation.param_env,
2982+
projection_ty,
2983+
);
29892984

29902985
debug!(
29912986
normalized_projection_type = ?self.resolve_vars_if_possible(projection_ty)

compiler/rustc_trait_selection/src/traits/util.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use rustc_hir::def_id::DefId;
88
use rustc_middle::ty::{self, ImplSubject, ToPredicate, Ty, TyCtxt, TypeVisitable};
99
use rustc_middle::ty::{GenericArg, SubstsRef};
1010

11-
use super::{Normalized, Obligation, ObligationCause, PredicateObligation, SelectionContext};
11+
use super::{Obligation, ObligationCause, PredicateObligation, SelectionContext};
12+
use crate::infer::InferCtxtExt;
13+
use rustc_infer::infer::InferOk;
1214
pub use rustc_infer::traits::{self, util::*};
1315

1416
///////////////////////////////////////////////////////////////////////////
@@ -200,13 +202,15 @@ pub fn impl_subject_and_oblig<'a, 'tcx>(
200202
) -> (ImplSubject<'tcx>, impl Iterator<Item = PredicateObligation<'tcx>>) {
201203
let subject = selcx.tcx().bound_impl_subject(impl_def_id);
202204
let subject = subject.subst(selcx.tcx(), impl_substs);
203-
let Normalized { value: subject, obligations: normalization_obligations1 } =
204-
super::normalize(selcx, param_env, ObligationCause::dummy(), subject);
205+
let InferOk { value: subject, obligations: normalization_obligations1 } = selcx
206+
.infcx()
207+
.partially_normalize_associated_types_in(ObligationCause::dummy(), param_env, subject);
205208

206209
let predicates = selcx.tcx().predicates_of(impl_def_id);
207210
let predicates = predicates.instantiate(selcx.tcx(), impl_substs);
208-
let Normalized { value: predicates, obligations: normalization_obligations2 } =
209-
super::normalize(selcx, param_env, ObligationCause::dummy(), predicates);
211+
let InferOk { value: predicates, obligations: normalization_obligations2 } = selcx
212+
.infcx()
213+
.partially_normalize_associated_types_in(ObligationCause::dummy(), param_env, predicates);
210214
let impl_obligations =
211215
super::predicates_for_generics(|_, _| ObligationCause::dummy(), param_env, predicates);
212216

0 commit comments

Comments
 (0)