summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_trait_selection/src/traits/project.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_trait_selection/src/traits/project.rs')
-rw-r--r--compiler/rustc_trait_selection/src/traits/project.rs35
1 files changed, 26 insertions, 9 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs
index 06a1027e5..f7b4794db 100644
--- a/compiler/rustc_trait_selection/src/traits/project.rs
+++ b/compiler/rustc_trait_selection/src/traits/project.rs
@@ -659,6 +659,18 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
normalized_ty
}
ty::Weak => {
+ let recursion_limit = self.interner().recursion_limit();
+ if !recursion_limit.value_within_limit(self.depth) {
+ self.selcx.infcx.err_ctxt().report_overflow_error(
+ &ty,
+ self.cause.span,
+ false,
+ |diag| {
+ diag.note(crate::fluent_generated::trait_selection_ty_alias_overflow);
+ },
+ );
+ }
+
let infcx = self.selcx.infcx;
self.obligations.extend(
infcx.tcx.predicates_of(data.def_id).instantiate_own(infcx.tcx, data.args).map(
@@ -678,7 +690,14 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
},
),
);
- infcx.tcx.type_of(data.def_id).instantiate(infcx.tcx, data.args).fold_with(self)
+ self.depth += 1;
+ let res = infcx
+ .tcx
+ .type_of(data.def_id)
+ .instantiate(infcx.tcx, data.args)
+ .fold_with(self);
+ self.depth -= 1;
+ res
}
ty::Inherent if !data.has_escaping_bound_vars() => {
@@ -742,7 +761,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
self.selcx.infcx,
&mut self.universes,
constant,
- |constant| constant.eval(tcx, self.param_env),
+ |constant| constant.normalize(tcx, self.param_env),
)
}
}
@@ -1214,7 +1233,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
let projected_term = selcx.infcx.resolve_vars_if_possible(projected_term);
- let result = if projected_term.has_projections() {
+ let mut result = if projected_term.has_projections() {
let mut normalizer = AssocTypeNormalizer::new(
selcx,
param_env,
@@ -1224,14 +1243,14 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
);
let normalized_ty = normalizer.fold(projected_term);
- let mut deduped = SsoHashSet::with_capacity(projected_obligations.len());
- projected_obligations.retain(|obligation| deduped.insert(obligation.clone()));
-
Normalized { value: normalized_ty, obligations: projected_obligations }
} else {
Normalized { value: projected_term, obligations: projected_obligations }
};
+ let mut deduped = SsoHashSet::with_capacity(result.obligations.len());
+ result.obligations.retain(|obligation| deduped.insert(obligation.clone()));
+
if use_cache {
infcx.inner.borrow_mut().projection_cache().insert_term(cache_key, result.clone());
}
@@ -1625,7 +1644,7 @@ fn assemble_candidates_from_object_ty<'cx, 'tcx>(
let env_predicates = data
.projection_bounds()
.filter(|bound| bound.item_def_id() == obligation.predicate.def_id)
- .map(|p| p.with_self_ty(tcx, object_ty).to_predicate(tcx));
+ .map(|p| ty::Clause::from_projection_clause(tcx, p.with_self_ty(tcx, object_ty)));
assemble_candidates_from_predicates(
selcx,
@@ -1794,7 +1813,6 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
| ty::Closure(..)
| ty::Generator(..)
| ty::GeneratorWitness(..)
- | ty::GeneratorWitnessMIR(..)
| ty::Never
| ty::Tuple(..)
// Integers and floats always have `u8` as their discriminant.
@@ -1844,7 +1862,6 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
| ty::Closure(..)
| ty::Generator(..)
| ty::GeneratorWitness(..)
- | ty::GeneratorWitnessMIR(..)
| ty::Never
// Extern types have unit metadata, according to RFC 2850
| ty::Foreign(_)