Skip to content

Commit fc71083

Browse files
partially_normalize_... -> At::normalize
1 parent f12e772 commit fc71083

File tree

18 files changed

+58
-93
lines changed

18 files changed

+58
-93
lines changed

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ where
291291
// FIXME(lqd): Unify and de-duplicate the following with the actual
292292
// `rustc_traits::type_op::type_op_normalize` query to allow the span we need in the
293293
// `ObligationCause`. The normalization results are currently different between
294-
// `AtExt::normalize` used in the query and `normalize` called below: the former fails
295-
// to normalize the `nll/relate_tys/impl-fn-ignore-binder-via-bottom.rs` test. Check
296-
// after #85499 lands to see if its fixes have erased this difference.
294+
// `QueryNormalizeExt::query_normalize` used in the query and `normalize` called below:
295+
// the former fails to normalize the `nll/relate_tys/impl-fn-ignore-binder-via-bottom.rs` test.
296+
// Check after #85499 lands to see if its fixes have erased this difference.
297297
let (param_env, value) = key.into_parts();
298298
let _ = ocx.normalize(cause, param_env, value.value);
299299

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ use rustc_span::def_id::LocalDefId;
3030
use rustc_span::hygiene::DesugaringKind;
3131
use rustc_span::symbol::{kw, sym, Ident};
3232
use rustc_span::{Span, DUMMY_SP};
33-
use rustc_trait_selection::infer::InferCtxtExt as _;
3433
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
35-
use rustc_trait_selection::traits::{self, ObligationCause, ObligationCauseCode, ObligationCtxt};
34+
use rustc_trait_selection::traits::{
35+
self, NormalizeExt, ObligationCause, ObligationCauseCode, ObligationCtxt,
36+
};
3637

3738
use std::collections::hash_map::Entry;
3839
use std::slice;
@@ -382,11 +383,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
382383
where
383384
T: TypeFoldable<'tcx>,
384385
{
385-
self.inh.partially_normalize_associated_types_in(
386-
ObligationCause::misc(span, self.body_id),
387-
self.param_env,
388-
value,
389-
)
386+
self.at(&ObligationCause::misc(span, self.body_id), self.param_env).normalize(value)
390387
}
391388

392389
pub(in super::super) fn normalize_op_associated_types_in_as_infer_ok<T>(
@@ -398,8 +395,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
398395
where
399396
T: TypeFoldable<'tcx>,
400397
{
401-
self.inh.partially_normalize_associated_types_in(
402-
ObligationCause::new(
398+
self.at(
399+
&ObligationCause::new(
403400
span,
404401
self.body_id,
405402
traits::BinOp {
@@ -410,8 +407,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
410407
},
411408
),
412409
self.param_env,
413-
value,
414410
)
411+
.normalize(value)
415412
}
416413

417414
pub fn require_type_meets(

compiler/rustc_hir_typeck/src/inherited.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ use rustc_middle::ty::visit::TypeVisitable;
1212
use rustc_middle::ty::{self, Ty, TyCtxt};
1313
use rustc_span::def_id::LocalDefIdMap;
1414
use rustc_span::{self, Span};
15-
use rustc_trait_selection::infer::InferCtxtExt as _;
1615
use rustc_trait_selection::traits::{
17-
self, ObligationCause, ObligationCtxt, TraitEngine, TraitEngineExt as _,
16+
self, NormalizeExt, ObligationCause, ObligationCtxt, TraitEngine, TraitEngineExt as _,
1817
};
1918

2019
use std::cell::RefCell;
@@ -206,7 +205,7 @@ impl<'tcx> Inherited<'tcx> {
206205
where
207206
T: TypeFoldable<'tcx>,
208207
{
209-
let ok = self.partially_normalize_associated_types_in(cause, param_env, value);
208+
let ok = self.at(&cause, param_env).normalize(value);
210209
debug!(?ok);
211210
self.register_infer_ok_obligations(ok)
212211
}

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ 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 _;
3534
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
3635
use rustc_trait_selection::traits::query::method_autoderef::MethodAutoderefBadTy;
3736
use rustc_trait_selection::traits::query::method_autoderef::{
3837
CandidateStep, MethodAutoderefStepsResult,
3938
};
4039
use rustc_trait_selection::traits::query::CanonicalTyGoal;
40+
use rustc_trait_selection::traits::NormalizeExt;
4141
use rustc_trait_selection::traits::{self, ObligationCause};
4242
use std::cmp::max;
4343
use std::iter;
@@ -716,9 +716,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
716716
// maybe shouldn't include `Param`s, but rather fresh variables or be canonicalized,
717717
// see issue #89650
718718
let cause = traits::ObligationCause::misc(self.span, self.body_id);
719-
let InferOk { value: xform_self_ty, obligations } = self
720-
.fcx
721-
.partially_normalize_associated_types_in(cause, self.param_env, xform_self_ty);
719+
let InferOk { value: xform_self_ty, obligations } =
720+
self.fcx.at(&cause, self.param_env).normalize(xform_self_ty);
722721

723722
debug!(
724723
"assemble_inherent_impl_probe after normalization: xform_self_ty = {:?}/{:?}",
@@ -1507,11 +1506,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
15071506
let InferOk {
15081507
value: normalized_xform_ret_ty,
15091508
obligations: normalization_obligations,
1510-
} = self.fcx.partially_normalize_associated_types_in(
1511-
cause.clone(),
1512-
self.param_env,
1513-
probe.xform_ret_ty,
1514-
);
1509+
} = self.fcx.at(&cause, self.param_env).normalize(probe.xform_ret_ty);
15151510
xform_ret_ty = normalized_xform_ret_ty;
15161511
debug!("xform_ret_ty after normalization: {:?}", xform_ret_ty);
15171512

@@ -1521,11 +1516,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
15211516
let impl_bounds = impl_bounds.instantiate(self.tcx, substs);
15221517

15231518
let InferOk { value: impl_bounds, obligations: norm_obligations } =
1524-
self.fcx.partially_normalize_associated_types_in(
1525-
cause.clone(),
1526-
self.param_env,
1527-
impl_bounds,
1528-
);
1519+
self.fcx.at(&cause, self.param_env).normalize(impl_bounds);
15291520

15301521
// Convert the bounds into obligations.
15311522
let impl_obligations = traits::predicates_for_generics(

compiler/rustc_trait_selection/src/autoderef.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::errors::AutoDerefReachedRecursionLimit;
2-
use crate::infer::InferCtxtExt as _;
32
use crate::traits::query::evaluate_obligation::InferCtxtExt;
3+
use crate::traits::NormalizeExt;
44
use crate::traits::{self, TraitEngine, TraitEngineExt};
55
use rustc_hir as hir;
66
use rustc_infer::infer::InferCtxt;
@@ -138,11 +138,10 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
138138
return None;
139139
}
140140

141-
let normalized_ty = self.infcx.partially_normalize_associated_types_in(
142-
cause,
143-
self.param_env,
144-
tcx.mk_projection(tcx.lang_items().deref_target()?, trait_ref.substs),
145-
);
141+
let normalized_ty = self
142+
.infcx
143+
.at(&cause, self.param_env)
144+
.normalize(tcx.mk_projection(tcx.lang_items().deref_target()?, trait_ref.substs));
146145
let mut fulfillcx = <dyn TraitEngine<'tcx>>::new_in_snapshot(tcx);
147146
let normalized_ty =
148147
normalized_ty.into_value_registering_obligations(self.infcx, &mut *fulfillcx);

compiler/rustc_trait_selection/src/infer.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::traits::{self, ObligationCtxt};
33

44
use rustc_hir::def_id::DefId;
55
use rustc_hir::lang_items::LangItem;
6-
use rustc_infer::traits::ObligationCause;
76
use rustc_middle::arena::ArenaAllocatable;
87
use rustc_middle::infer::canonical::{Canonical, CanonicalizedQueryResponse, QueryResponse};
98
use rustc_middle::traits::query::Fallible;
@@ -30,15 +29,6 @@ pub trait InferCtxtExt<'tcx> {
3029
span: Span,
3130
) -> bool;
3231

33-
fn partially_normalize_associated_types_in<T>(
34-
&self,
35-
cause: ObligationCause<'tcx>,
36-
param_env: ty::ParamEnv<'tcx>,
37-
value: T,
38-
) -> InferOk<'tcx, T>
39-
where
40-
T: TypeFoldable<'tcx>;
41-
4232
/// Check whether a `ty` implements given trait(trait_def_id).
4333
/// The inputs are:
4434
///
@@ -88,24 +78,6 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
8878
traits::type_known_to_meet_bound_modulo_regions(self, param_env, ty, lang_item, span)
8979
}
9080

91-
/// Normalizes associated types in `value`, potentially returning
92-
/// new obligations that must further be processed.
93-
#[instrument(level = "debug", skip(self, cause, param_env), ret)]
94-
fn partially_normalize_associated_types_in<T>(
95-
&self,
96-
cause: ObligationCause<'tcx>,
97-
param_env: ty::ParamEnv<'tcx>,
98-
value: T,
99-
) -> InferOk<'tcx, T>
100-
where
101-
T: TypeFoldable<'tcx>,
102-
{
103-
let mut selcx = traits::SelectionContext::new(self);
104-
let traits::Normalized { value, obligations } =
105-
traits::normalize(&mut selcx, param_env, cause, value);
106-
InferOk { value, obligations }
107-
}
108-
10981
#[instrument(level = "debug", skip(self, params), ret)]
11082
fn type_implements_trait(
11183
&self,

compiler/rustc_trait_selection/src/traits/engine.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fmt::Debug;
33

44
use super::TraitEngine;
55
use super::{ChalkFulfillmentContext, FulfillmentContext};
6-
use crate::infer::InferCtxtExt;
6+
use crate::traits::NormalizeExt;
77
use rustc_data_structures::fx::FxIndexSet;
88
use rustc_hir::def_id::{DefId, LocalDefId};
99
use rustc_infer::infer::at::ToTrace;
@@ -104,11 +104,12 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
104104

105105
pub fn normalize<T: TypeFoldable<'tcx>>(
106106
&self,
107+
// FIXME(compiler-errors): Make this borrow
107108
cause: ObligationCause<'tcx>,
108109
param_env: ty::ParamEnv<'tcx>,
109110
value: T,
110111
) -> T {
111-
let infer_ok = self.infcx.partially_normalize_associated_types_in(cause, param_env, value);
112+
let infer_ok = self.infcx.at(&cause, param_env).normalize(value);
112113
self.register_infer_ok_obligations(infer_ok)
113114
}
114115

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ 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 _;
1312
use crate::infer::{self, InferCtxt, TyCtxtInferExt};
1413
use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
15-
use crate::traits::query::normalize::AtExt as _;
14+
use crate::traits::query::normalize::QueryNormalizeExt as _;
1615
use crate::traits::specialize::to_pretty_impl_header;
16+
use crate::traits::NormalizeExt;
1717
use on_unimplemented::OnUnimplementedNote;
1818
use on_unimplemented::TypeErrCtxtExt as _;
1919
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
@@ -2535,11 +2535,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
25352535
pred.fold_with(&mut ParamToVarFolder { infcx: self, var_map: Default::default() });
25362536

25372537
let InferOk { value: cleaned_pred, .. } =
2538-
self.infcx.partially_normalize_associated_types_in(
2539-
ObligationCause::dummy(),
2540-
param_env,
2541-
cleaned_pred,
2542-
);
2538+
self.infcx.at(&ObligationCause::dummy(), param_env).normalize(cleaned_pred);
25432539

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

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::{DefIdOrName, Obligation, ObligationCause, ObligationCauseCode, Predi
22

33
use crate::autoderef::Autoderef;
44
use crate::infer::InferCtxt;
5+
use crate::traits::NormalizeExt;
56

67
use hir::def::CtorOf;
78
use hir::HirId;
@@ -2972,12 +2973,8 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
29722973
self.tcx.mk_substs_trait(trait_pred.self_ty(), []),
29732974
)
29742975
});
2975-
let InferOk { value: projection_ty, .. } = self
2976-
.partially_normalize_associated_types_in(
2977-
obligation.cause.clone(),
2978-
obligation.param_env,
2979-
projection_ty,
2980-
);
2976+
let InferOk { value: projection_ty, .. } =
2977+
self.at(&obligation.cause, obligation.param_env).normalize(projection_ty);
29812978

29822979
debug!(
29832980
normalized_projection_type = ?self.resolve_vars_if_possible(projection_ty)

compiler/rustc_trait_selection/src/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub use self::object_safety::astconv_object_safety_violations;
5656
pub use self::object_safety::is_vtable_safe_method;
5757
pub use self::object_safety::MethodViolationCode;
5858
pub use self::object_safety::ObjectSafetyViolation;
59-
pub use self::project::{normalize, normalize_projection_type, normalize_to};
59+
pub use self::project::{normalize, normalize_projection_type, normalize_to, NormalizeExt};
6060
pub use self::select::{EvaluationCache, SelectionCache, SelectionContext};
6161
pub use self::select::{EvaluationResult, IntercrateAmbiguityCause, OverflowError};
6262
pub use self::specialize::specialization_graph::FutureCompatOverlapError;

compiler/rustc_trait_selection/src/traits/project.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use rustc_errors::ErrorGuaranteed;
2727
use rustc_hir::def::DefKind;
2828
use rustc_hir::def_id::DefId;
2929
use rustc_hir::lang_items::LangItem;
30+
use rustc_infer::infer::at::At;
3031
use rustc_infer::infer::resolve::OpportunisticRegionResolver;
3132
use rustc_infer::traits::ImplSourceBuiltinData;
3233
use rustc_middle::traits::select::OverflowError;
@@ -48,6 +49,19 @@ pub type ProjectionTyObligation<'tcx> = Obligation<'tcx, ty::ProjectionTy<'tcx>>
4849

4950
pub(super) struct InProgress;
5051

52+
pub trait NormalizeExt<'tcx> {
53+
fn normalize<T: TypeFoldable<'tcx>>(&self, t: T) -> InferOk<'tcx, T>;
54+
}
55+
56+
impl<'tcx> NormalizeExt<'tcx> for At<'_, 'tcx> {
57+
fn normalize<T: TypeFoldable<'tcx>>(&self, value: T) -> InferOk<'tcx, T> {
58+
let mut selcx = SelectionContext::new(self.infcx);
59+
let Normalized { value, obligations } =
60+
normalize(&mut selcx, self.param_env, self.cause.clone(), value);
61+
InferOk { value, obligations }
62+
}
63+
}
64+
5165
/// When attempting to resolve `<T as TraitRef>::Name` ...
5266
#[derive(Debug)]
5367
pub enum ProjectionError<'tcx> {

compiler/rustc_trait_selection/src/traits/query/normalize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ use super::NoSolution;
2222

2323
pub use rustc_middle::traits::query::NormalizationResult;
2424

25-
pub trait AtExt<'tcx> {
25+
pub trait QueryNormalizeExt<'tcx> {
2626
fn query_normalize<T>(&self, value: T) -> Result<Normalized<'tcx, T>, NoSolution>
2727
where
2828
T: TypeFoldable<'tcx>;
2929
}
3030

31-
impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> {
31+
impl<'cx, 'tcx> QueryNormalizeExt<'tcx> for At<'cx, 'tcx> {
3232
/// Normalize `value` in the context of the inference context,
3333
/// yielding a resulting type, or an error if `value` cannot be
3434
/// normalized. If you don't care about regions, you should prefer

compiler/rustc_trait_selection/src/traits/util.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ 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::NormalizeExt;
1112
use super::{Obligation, ObligationCause, PredicateObligation, SelectionContext};
12-
use crate::infer::InferCtxtExt;
1313
use rustc_infer::infer::InferOk;
1414
pub use rustc_infer::traits::{self, util::*};
1515

@@ -202,15 +202,13 @@ pub fn impl_subject_and_oblig<'a, 'tcx>(
202202
) -> (ImplSubject<'tcx>, impl Iterator<Item = PredicateObligation<'tcx>>) {
203203
let subject = selcx.tcx().bound_impl_subject(impl_def_id);
204204
let subject = subject.subst(selcx.tcx(), impl_substs);
205-
let InferOk { value: subject, obligations: normalization_obligations1 } = selcx
206-
.infcx
207-
.partially_normalize_associated_types_in(ObligationCause::dummy(), param_env, subject);
205+
let InferOk { value: subject, obligations: normalization_obligations1 } =
206+
selcx.infcx.at(&ObligationCause::dummy(), param_env).normalize(subject);
208207

209208
let predicates = selcx.tcx().predicates_of(impl_def_id);
210209
let predicates = predicates.instantiate(selcx.tcx(), impl_substs);
211-
let InferOk { value: predicates, obligations: normalization_obligations2 } = selcx
212-
.infcx
213-
.partially_normalize_associated_types_in(ObligationCause::dummy(), param_env, predicates);
210+
let InferOk { value: predicates, obligations: normalization_obligations2 } =
211+
selcx.infcx.at(&ObligationCause::dummy(), param_env).normalize(predicates);
214212
let impl_obligations =
215213
super::predicates_for_generics(|_, _| ObligationCause::dummy(), param_env, predicates);
216214

compiler/rustc_traits/src/dropck_outlives.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_trait_selection::traits::query::dropck_outlives::trivial_dropck_outliv
1111
use rustc_trait_selection::traits::query::dropck_outlives::{
1212
DropckConstraint, DropckOutlivesResult,
1313
};
14-
use rustc_trait_selection::traits::query::normalize::AtExt;
14+
use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt;
1515
use rustc_trait_selection::traits::query::{CanonicalTyGoal, NoSolution};
1616
use rustc_trait_selection::traits::{Normalized, ObligationCause};
1717

compiler/rustc_traits/src/normalize_erasing_regions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_infer::infer::TyCtxtInferExt;
22
use rustc_middle::traits::query::NoSolution;
33
use rustc_middle::ty::query::Providers;
44
use rustc_middle::ty::{self, ParamEnvAnd, TyCtxt, TypeFoldable};
5-
use rustc_trait_selection::traits::query::normalize::AtExt;
5+
use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt;
66
use rustc_trait_selection::traits::{Normalized, ObligationCause};
77
use std::sync::atomic::Ordering;
88

compiler/rustc_traits/src/type_op.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_middle::ty::{ParamEnvAnd, Predicate, ToPredicate};
88
use rustc_middle::ty::{UserSelfTy, UserSubsts};
99
use rustc_span::{Span, DUMMY_SP};
1010
use rustc_trait_selection::infer::InferCtxtBuilderExt;
11-
use rustc_trait_selection::traits::query::normalize::AtExt;
11+
use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt;
1212
use rustc_trait_selection::traits::query::type_op::ascribe_user_type::AscribeUserType;
1313
use rustc_trait_selection::traits::query::type_op::eq::Eq;
1414
use rustc_trait_selection::traits::query::type_op::normalize::Normalize;

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,7 @@ fn normalize<'tcx>(cx: &mut DocContext<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'tcx>>
15811581
}
15821582

15831583
use crate::rustc_trait_selection::infer::TyCtxtInferExt;
1584-
use crate::rustc_trait_selection::traits::query::normalize::AtExt;
1584+
use crate::rustc_trait_selection::traits::query::normalize::QueryNormalizeExt;
15851585
use rustc_middle::traits::ObligationCause;
15861586

15871587
// Try to normalize `<X as Y>::T` to a type

0 commit comments

Comments
 (0)