Skip to content

Commit 73f01ff

Browse files
authored
Rollup merge of #104820 - spastorino:remove-normalize_projection_type, r=jackh726
Remove normalize_projection_type r? ``@lcnr``
2 parents 83d1aab + 1930c77 commit 73f01ff

File tree

4 files changed

+13
-68
lines changed

4 files changed

+13
-68
lines changed

compiler/rustc_infer/src/traits/engine.rs

-8
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ use super::FulfillmentError;
88
use super::{ObligationCause, PredicateObligation};
99

1010
pub trait TraitEngine<'tcx>: 'tcx {
11-
fn normalize_projection_type(
12-
&mut self,
13-
infcx: &InferCtxt<'tcx>,
14-
param_env: ty::ParamEnv<'tcx>,
15-
projection_ty: ty::ProjectionTy<'tcx>,
16-
cause: ObligationCause<'tcx>,
17-
) -> Ty<'tcx>;
18-
1911
/// Requires that `ty` must implement the trait with `def_id` in
2012
/// the given environment. This trait must not have any type
2113
/// parameters (except for `Self`).

compiler/rustc_trait_selection/src/autoderef.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::errors::AutoDerefReachedRecursionLimit;
2+
use crate::infer::InferCtxtExt as _;
23
use crate::traits::query::evaluate_obligation::InferCtxtExt;
34
use crate::traits::{self, TraitEngine, TraitEngineExt};
45
use rustc_hir as hir;
@@ -137,16 +138,14 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
137138
return None;
138139
}
139140

140-
let mut fulfillcx = <dyn TraitEngine<'tcx>>::new_in_snapshot(tcx);
141-
let normalized_ty = fulfillcx.normalize_projection_type(
142-
&self.infcx,
143-
self.param_env,
144-
ty::ProjectionTy {
145-
item_def_id: tcx.lang_items().deref_target()?,
146-
substs: trait_ref.substs,
147-
},
141+
let normalized_ty = self.infcx.partially_normalize_associated_types_in(
148142
cause,
143+
self.param_env,
144+
tcx.mk_projection(tcx.lang_items().deref_target()?, trait_ref.substs),
149145
);
146+
let mut fulfillcx = <dyn TraitEngine<'tcx>>::new_in_snapshot(tcx);
147+
let normalized_ty =
148+
normalized_ty.into_value_registering_obligations(self.infcx, &mut *fulfillcx);
150149
let errors = fulfillcx.select_where_possible(&self.infcx);
151150
if !errors.is_empty() {
152151
// This shouldn't happen, except for evaluate/fulfill mismatches,

compiler/rustc_trait_selection/src/traits/chalk_fulfill.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use crate::infer::canonical::OriginalQueryValues;
44
use crate::infer::InferCtxt;
55
use crate::traits::query::NoSolution;
66
use crate::traits::{
7-
ChalkEnvironmentAndGoal, FulfillmentError, FulfillmentErrorCode, ObligationCause,
8-
PredicateObligation, SelectionError, TraitEngine,
7+
ChalkEnvironmentAndGoal, FulfillmentError, FulfillmentErrorCode, PredicateObligation,
8+
SelectionError, TraitEngine,
99
};
1010
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
11-
use rustc_middle::ty::{self, Ty, TypeVisitable};
11+
use rustc_middle::ty::{self, TypeVisitable};
1212

1313
pub struct FulfillmentContext<'tcx> {
1414
obligations: FxIndexSet<PredicateObligation<'tcx>>,
@@ -33,16 +33,6 @@ impl FulfillmentContext<'_> {
3333
}
3434

3535
impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
36-
fn normalize_projection_type(
37-
&mut self,
38-
infcx: &InferCtxt<'tcx>,
39-
_param_env: ty::ParamEnv<'tcx>,
40-
projection_ty: ty::ProjectionTy<'tcx>,
41-
_cause: ObligationCause<'tcx>,
42-
) -> Ty<'tcx> {
43-
infcx.tcx.mk_ty(ty::Projection(projection_ty))
44-
}
45-
4636
fn register_predicate_obligation(
4737
&mut self,
4838
infcx: &InferCtxt<'tcx>,

compiler/rustc_trait_selection/src/traits/fulfill.rs

+3-39
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ use rustc_data_structures::obligation_forest::ProcessResult;
44
use rustc_data_structures::obligation_forest::{Error, ForestObligation, Outcome};
55
use rustc_data_structures::obligation_forest::{ObligationForest, ObligationProcessor};
66
use rustc_infer::traits::ProjectionCacheKey;
7-
use rustc_infer::traits::{SelectionError, TraitEngine, TraitEngineExt as _, TraitObligation};
7+
use rustc_infer::traits::{SelectionError, TraitEngine, TraitObligation};
88
use rustc_middle::mir::interpret::ErrorHandled;
99
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
1010
use rustc_middle::ty::error::{ExpectedFound, TypeError};
1111
use rustc_middle::ty::subst::SubstsRef;
12-
use rustc_middle::ty::{self, Binder, Const, Ty, TypeVisitable};
12+
use rustc_middle::ty::{self, Binder, Const, TypeVisitable};
1313
use std::marker::PhantomData;
1414

1515
use super::const_evaluatable;
@@ -20,9 +20,9 @@ use super::CodeAmbiguity;
2020
use super::CodeProjectionError;
2121
use super::CodeSelectionError;
2222
use super::EvaluationResult;
23+
use super::PredicateObligation;
2324
use super::Unimplemented;
2425
use super::{FulfillmentError, FulfillmentErrorCode};
25-
use super::{ObligationCause, PredicateObligation};
2626

2727
use crate::traits::project::PolyProjectionObligation;
2828
use crate::traits::project::ProjectionCacheKeyExt as _;
@@ -126,42 +126,6 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
126126
}
127127

128128
impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
129-
/// "Normalize" a projection type `<SomeType as SomeTrait>::X` by
130-
/// creating a fresh type variable `$0` as well as a projection
131-
/// predicate `<SomeType as SomeTrait>::X == $0`. When the
132-
/// inference engine runs, it will attempt to find an impl of
133-
/// `SomeTrait` or a where-clause that lets us unify `$0` with
134-
/// something concrete. If this fails, we'll unify `$0` with
135-
/// `projection_ty` again.
136-
#[instrument(level = "debug", skip(self, infcx, param_env, cause))]
137-
fn normalize_projection_type(
138-
&mut self,
139-
infcx: &InferCtxt<'tcx>,
140-
param_env: ty::ParamEnv<'tcx>,
141-
projection_ty: ty::ProjectionTy<'tcx>,
142-
cause: ObligationCause<'tcx>,
143-
) -> Ty<'tcx> {
144-
debug_assert!(!projection_ty.has_escaping_bound_vars());
145-
146-
// FIXME(#20304) -- cache
147-
148-
let mut selcx = SelectionContext::new(infcx);
149-
let mut obligations = vec![];
150-
let normalized_ty = project::normalize_projection_type(
151-
&mut selcx,
152-
param_env,
153-
projection_ty,
154-
cause,
155-
0,
156-
&mut obligations,
157-
);
158-
self.register_predicate_obligations(infcx, obligations);
159-
160-
debug!(?normalized_ty);
161-
162-
normalized_ty.ty().unwrap()
163-
}
164-
165129
fn register_predicate_obligation(
166130
&mut self,
167131
infcx: &InferCtxt<'tcx>,

0 commit comments

Comments
 (0)