1 use rustc::traits::query::NoSolution;
2 use rustc::ty::query::Providers;
3 use rustc::ty::{self, ParamEnvAnd, Ty, TyCtxt};
4 use rustc_infer::infer::TyCtxtInferExt;
5 use rustc_infer::traits::{Normalized, ObligationCause};
6 use std::sync::atomic::Ordering;
8 crate fn provide(p: &mut Providers<'_>) {
9 *p = Providers { normalize_ty_after_erasing_regions, ..*p };
12 fn normalize_ty_after_erasing_regions<'tcx>(
14 goal: ParamEnvAnd<'tcx, Ty<'tcx>>,
16 debug!("normalize_ty_after_erasing_regions(goal={:#?})", goal);
18 let ParamEnvAnd { param_env, value } = goal;
19 tcx.sess.perf_stats.normalize_ty_after_erasing_regions.fetch_add(1, Ordering::Relaxed);
20 tcx.infer_ctxt().enter(|infcx| {
21 let cause = ObligationCause::dummy();
22 match infcx.at(&cause, param_env).normalize(&value) {
23 Ok(Normalized { value: normalized_value, obligations: normalized_obligations }) => {
24 // We don't care about the `obligations`; they are
25 // always only region relations, and we are about to
26 // erase those anyway:
28 normalized_obligations.iter().find(|p| not_outlives_predicate(&p.predicate)),
32 let normalized_value = infcx.resolve_vars_if_possible(&normalized_value);
33 infcx.tcx.erase_regions(&normalized_value)
35 Err(NoSolution) => bug!("could not fully normalize `{:?}`", value),
40 fn not_outlives_predicate(p: &ty::Predicate<'_>) -> bool {
42 ty::Predicate::RegionOutlives(..) | ty::Predicate::TypeOutlives(..) => false,
43 ty::Predicate::Trait(..)
44 | ty::Predicate::Projection(..)
45 | ty::Predicate::WellFormed(..)
46 | ty::Predicate::ObjectSafe(..)
47 | ty::Predicate::ClosureKind(..)
48 | ty::Predicate::Subtype(..)
49 | ty::Predicate::ConstEvaluatable(..) => true,