1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use rustc::traits::{Normalized, ObligationCause};
12 use rustc::traits::query::NoSolution;
13 use rustc::ty::query::Providers;
14 use rustc::ty::{self, ParamEnvAnd, Ty, TyCtxt};
15 use std::sync::atomic::Ordering;
17 crate fn provide(p: &mut Providers) {
19 normalize_ty_after_erasing_regions,
24 fn normalize_ty_after_erasing_regions<'tcx>(
25 tcx: TyCtxt<'_, 'tcx, 'tcx>,
26 goal: ParamEnvAnd<'tcx, Ty<'tcx>>,
28 debug!("normalize_ty_after_erasing_regions(goal={:#?})", goal);
30 let ParamEnvAnd { param_env, value } = goal;
31 tcx.sess.perf_stats.normalize_ty_after_erasing_regions.fetch_add(1, Ordering::Relaxed);
32 tcx.infer_ctxt().enter(|infcx| {
33 let cause = ObligationCause::dummy();
34 match infcx.at(&cause, param_env).normalize(&value) {
36 value: normalized_value,
37 obligations: normalized_obligations,
39 // We don't care about the `obligations`; they are
40 // always only region relations, and we are about to
41 // erase those anyway:
43 normalized_obligations
45 .find(|p| not_outlives_predicate(&p.predicate)),
49 let normalized_value = infcx.resolve_type_vars_if_possible(&normalized_value);
50 let normalized_value = infcx.tcx.erase_regions(&normalized_value);
51 tcx.lift_to_global(&normalized_value).unwrap()
53 Err(NoSolution) => bug!("could not fully normalize `{:?}`", value),
58 fn not_outlives_predicate(p: &ty::Predicate<'_>) -> bool {
60 ty::Predicate::RegionOutlives(..) | ty::Predicate::TypeOutlives(..) => false,
61 ty::Predicate::Trait(..)
62 | ty::Predicate::Projection(..)
63 | ty::Predicate::WellFormed(..)
64 | ty::Predicate::ObjectSafe(..)
65 | ty::Predicate::ClosureKind(..)
66 | ty::Predicate::Subtype(..)
67 | ty::Predicate::ConstEvaluatable(..) => true,