1 use rustc::traits::{Normalized, ObligationCause};
2 use rustc::traits::query::NoSolution;
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<'_>) {
9 normalize_ty_after_erasing_regions,
14 fn normalize_ty_after_erasing_regions<'tcx>(
16 goal: ParamEnvAnd<'tcx, Ty<'tcx>>,
18 debug!("normalize_ty_after_erasing_regions(goal={:#?})", goal);
20 let ParamEnvAnd { param_env, value } = goal;
21 tcx.sess.perf_stats.normalize_ty_after_erasing_regions.fetch_add(1, Ordering::Relaxed);
22 tcx.infer_ctxt().enter(|infcx| {
23 let cause = ObligationCause::dummy();
24 match infcx.at(&cause, param_env).normalize(&value) {
26 value: normalized_value,
27 obligations: normalized_obligations,
29 // We don't care about the `obligations`; they are
30 // always only region relations, and we are about to
31 // erase those anyway:
33 normalized_obligations
35 .find(|p| not_outlives_predicate(&p.predicate)),
39 let normalized_value = infcx.resolve_vars_if_possible(&normalized_value);
40 infcx.tcx.erase_regions(&normalized_value)
42 Err(NoSolution) => bug!("could not fully normalize `{:?}`", value),
47 fn not_outlives_predicate(p: &ty::Predicate<'_>) -> bool {
49 ty::Predicate::RegionOutlives(..) | ty::Predicate::TypeOutlives(..) => false,
50 ty::Predicate::Trait(..)
51 | ty::Predicate::Projection(..)
52 | ty::Predicate::WellFormed(..)
53 | ty::Predicate::ObjectSafe(..)
54 | ty::Predicate::ClosureKind(..)
55 | ty::Predicate::Subtype(..)
56 | ty::Predicate::ConstEvaluatable(..) => true,