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