Skip to content

Commit bd03d81

Browse files
committed
Remove generalization over projection
Instead, just use a term everywhere.
1 parent 1c4fe64 commit bd03d81

File tree

9 files changed

+160
-325
lines changed

9 files changed

+160
-325
lines changed

compiler/rustc_infer/src/infer/at.rs

+20
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,26 @@ impl<'tcx> ToTrace<'tcx> for &'tcx Const<'tcx> {
286286
}
287287
}
288288

289+
impl<'tcx> ToTrace<'tcx> for ty::Term<'tcx> {
290+
fn to_trace(
291+
tcx: TyCtxt<'tcx>,
292+
cause: &ObligationCause<'tcx>,
293+
a_is_expected: bool,
294+
a: Self,
295+
b: Self,
296+
) -> TypeTrace<'tcx> {
297+
match (a, b) {
298+
(ty::Term::Ty(a), ty::Term::Ty(b)) => {
299+
ToTrace::to_trace(tcx, cause, a_is_expected, a, b)
300+
}
301+
(ty::Term::Const(a), ty::Term::Const(b)) => {
302+
ToTrace::to_trace(tcx, cause, a_is_expected, a, b)
303+
}
304+
(_, _) => span_bug!(cause.span, "Unexpected type/const mismatch"),
305+
}
306+
}
307+
}
308+
289309
impl<'tcx> ToTrace<'tcx> for ty::TraitRef<'tcx> {
290310
fn to_trace(
291311
_: TyCtxt<'tcx>,

compiler/rustc_infer/src/traits/project.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub enum ProjectionCacheEntry<'tcx> {
9393
Recur,
9494
Error,
9595
NormalizedTy {
96-
ty: NormalizedTy<'tcx>,
96+
ty: Normalized<'tcx, ty::Term<'tcx>>,
9797
/// If we were able to successfully evaluate the
9898
/// corresponding cache entry key during predicate
9999
/// evaluation, then this field stores the final
@@ -174,7 +174,11 @@ impl<'tcx> ProjectionCache<'_, 'tcx> {
174174
}
175175

176176
/// Indicates that `key` was normalized to `value`.
177-
pub fn insert_ty(&mut self, key: ProjectionCacheKey<'tcx>, value: NormalizedTy<'tcx>) {
177+
pub fn insert_term(
178+
&mut self,
179+
key: ProjectionCacheKey<'tcx>,
180+
value: Normalized<'tcx, ty::Term<'tcx>>,
181+
) {
178182
debug!(
179183
"ProjectionCacheEntry::insert_ty: adding cache entry: key={:?}, value={:?}",
180184
key, value

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

+21-9
Original file line numberDiff line numberDiff line change
@@ -1351,19 +1351,31 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
13511351
| ObligationCauseCode::ObjectCastObligation(_)
13521352
| ObligationCauseCode::OpaqueType
13531353
);
1354-
// FIXME(associated_const_equality): Handle Consts here
1355-
let data_ty = data.term.ty().unwrap();
13561354
if let Err(error) = self.at(&obligation.cause, obligation.param_env).eq_exp(
13571355
is_normalized_ty_expected,
13581356
normalized_ty,
1359-
data_ty,
1357+
data.term,
13601358
) {
1361-
values = Some(infer::ValuePairs::Types(ExpectedFound::new(
1362-
is_normalized_ty_expected,
1363-
normalized_ty,
1364-
data_ty,
1365-
)));
1366-
1359+
values = Some(match (normalized_ty, data.term) {
1360+
(ty::Term::Ty(normalized_ty), ty::Term::Ty(ty)) => {
1361+
infer::ValuePairs::Types(ExpectedFound::new(
1362+
is_normalized_ty_expected,
1363+
normalized_ty,
1364+
ty,
1365+
))
1366+
}
1367+
(ty::Term::Const(normalized_ct), ty::Term::Const(ct)) => {
1368+
infer::ValuePairs::Consts(ExpectedFound::new(
1369+
is_normalized_ty_expected,
1370+
normalized_ct,
1371+
ct,
1372+
))
1373+
}
1374+
(_, _) => span_bug!(
1375+
obligation.cause.span,
1376+
"found const or type where other expected"
1377+
),
1378+
});
13671379
err_buf = error;
13681380
err = &err_buf;
13691381
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2496,7 +2496,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
24962496
let try_obligation = self.mk_trait_obligation_with_new_self_ty(
24972497
obligation.param_env,
24982498
trait_pred,
2499-
normalized_ty,
2499+
normalized_ty.ty().unwrap(),
25002500
);
25012501
debug!("suggest_await_before_try: try_trait_obligation {:?}", try_obligation);
25022502
if self.predicate_may_hold(&try_obligation)

compiler/rustc_trait_selection/src/traits/fulfill.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
200200

201201
debug!(?normalized_ty);
202202

203-
normalized_ty
203+
normalized_ty.ty().unwrap()
204204
}
205205

206206
fn register_predicate_obligation(

0 commit comments

Comments
 (0)