Skip to content

Commit 486c7b6

Browse files
committed
never normalize without eager inference replacement
1 parent bea5beb commit 486c7b6

File tree

3 files changed

+11
-82
lines changed

3 files changed

+11
-82
lines changed

compiler/rustc_trait_selection/src/traits/fulfill.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
312312

313313
if obligation.predicate.has_projections() {
314314
let mut obligations = Vec::new();
315-
let predicate = crate::traits::project::try_normalize_with_depth_to(
315+
let predicate = crate::traits::project::normalize_with_depth_to(
316316
&mut self.selcx,
317317
obligation.param_env,
318318
obligation.cause.clone(),

compiler/rustc_trait_selection/src/traits/project.rs

+9-79
Original file line numberDiff line numberDiff line change
@@ -374,32 +374,6 @@ where
374374
result
375375
}
376376

377-
#[instrument(level = "info", skip(selcx, param_env, cause, obligations))]
378-
pub(crate) fn try_normalize_with_depth_to<'a, 'b, 'tcx, T>(
379-
selcx: &'a mut SelectionContext<'b, 'tcx>,
380-
param_env: ty::ParamEnv<'tcx>,
381-
cause: ObligationCause<'tcx>,
382-
depth: usize,
383-
value: T,
384-
obligations: &mut Vec<PredicateObligation<'tcx>>,
385-
) -> T
386-
where
387-
T: TypeFoldable<TyCtxt<'tcx>>,
388-
{
389-
debug!(obligations.len = obligations.len());
390-
let mut normalizer = AssocTypeNormalizer::new_without_eager_inference_replacement(
391-
selcx,
392-
param_env,
393-
cause,
394-
depth,
395-
obligations,
396-
);
397-
let result = ensure_sufficient_stack(|| normalizer.fold(value));
398-
debug!(?result, obligations.len = normalizer.obligations.len());
399-
debug!(?normalizer.obligations,);
400-
result
401-
}
402-
403377
pub(crate) fn needs_normalization<'tcx, T: TypeVisitable<TyCtxt<'tcx>>>(
404378
value: &T,
405379
reveal: Reveal,
@@ -426,10 +400,6 @@ struct AssocTypeNormalizer<'a, 'b, 'tcx> {
426400
obligations: &'a mut Vec<PredicateObligation<'tcx>>,
427401
depth: usize,
428402
universes: Vec<Option<ty::UniverseIndex>>,
429-
/// If true, when a projection is unable to be completed, an inference
430-
/// variable will be created and an obligation registered to project to that
431-
/// inference variable. Also, constants will be eagerly evaluated.
432-
eager_inference_replacement: bool,
433403
}
434404

435405
impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
@@ -441,33 +411,7 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
441411
obligations: &'a mut Vec<PredicateObligation<'tcx>>,
442412
) -> AssocTypeNormalizer<'a, 'b, 'tcx> {
443413
debug_assert!(!selcx.infcx.next_trait_solver());
444-
AssocTypeNormalizer {
445-
selcx,
446-
param_env,
447-
cause,
448-
obligations,
449-
depth,
450-
universes: vec![],
451-
eager_inference_replacement: true,
452-
}
453-
}
454-
455-
fn new_without_eager_inference_replacement(
456-
selcx: &'a mut SelectionContext<'b, 'tcx>,
457-
param_env: ty::ParamEnv<'tcx>,
458-
cause: ObligationCause<'tcx>,
459-
depth: usize,
460-
obligations: &'a mut Vec<PredicateObligation<'tcx>>,
461-
) -> AssocTypeNormalizer<'a, 'b, 'tcx> {
462-
AssocTypeNormalizer {
463-
selcx,
464-
param_env,
465-
cause,
466-
obligations,
467-
depth,
468-
universes: vec![],
469-
eager_inference_replacement: false,
470-
}
414+
AssocTypeNormalizer { selcx, param_env, cause, obligations, depth, universes: vec![] }
471415
}
472416

473417
fn fold<T: TypeFoldable<TyCtxt<'tcx>>>(&mut self, value: T) -> T {
@@ -570,28 +514,14 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
570514
// register an obligation to *later* project, since we know
571515
// there won't be bound vars there.
572516
let data = data.fold_with(self);
573-
let normalized_ty = if self.eager_inference_replacement {
574-
normalize_projection_type(
575-
self.selcx,
576-
self.param_env,
577-
data,
578-
self.cause.clone(),
579-
self.depth,
580-
self.obligations,
581-
)
582-
} else {
583-
opt_normalize_projection_type(
584-
self.selcx,
585-
self.param_env,
586-
data,
587-
self.cause.clone(),
588-
self.depth,
589-
self.obligations,
590-
)
591-
.ok()
592-
.flatten()
593-
.unwrap_or_else(|| ty.super_fold_with(self).into())
594-
};
517+
let normalized_ty = normalize_projection_type(
518+
self.selcx,
519+
self.param_env,
520+
data,
521+
self.cause.clone(),
522+
self.depth,
523+
self.obligations,
524+
);
595525
debug!(
596526
?self.depth,
597527
?ty,

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use super::{
2222
use crate::infer::{InferCtxt, InferOk, TypeFreshener};
2323
use crate::solve::InferCtxtSelectExt;
2424
use crate::traits::error_reporting::TypeErrCtxtExt;
25-
use crate::traits::project::try_normalize_with_depth_to;
2625
use crate::traits::project::ProjectAndUnifyResult;
2726
use crate::traits::project::ProjectionCacheKeyExt;
2827
use crate::traits::ProjectionCacheKey;
@@ -1070,7 +1069,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
10701069
&& fresh_trait_pred.is_global()
10711070
{
10721071
let mut nested_obligations = Vec::new();
1073-
let predicate = try_normalize_with_depth_to(
1072+
let predicate = normalize_with_depth_to(
10741073
this,
10751074
param_env,
10761075
obligation.cause.clone(),

0 commit comments

Comments
 (0)