diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2018-03-09 16:44:20 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2018-03-13 11:22:08 -0400 |
| commit | fc04c41a4075cef1cc9c84911fbdc17b5b9265b7 (patch) | |
| tree | b0131d95aabec7240a85295f211eec8d44715cbd | |
| parent | 6288faa3a31844a38b703b2a20a7f3cb9e15ed31 (diff) | |
add a debug assertion that only outlives-oblig. result from norm.
| -rw-r--r-- | src/librustc_traits/normalize_erasing_regions.rs | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/src/librustc_traits/normalize_erasing_regions.rs b/src/librustc_traits/normalize_erasing_regions.rs index 805bf1030b3..14f8694dbf7 100644 --- a/src/librustc_traits/normalize_erasing_regions.rs +++ b/src/librustc_traits/normalize_erasing_regions.rs @@ -10,7 +10,7 @@ use rustc::traits::{Normalized, ObligationCause}; use rustc::traits::query::NoSolution; -use rustc::ty::{ParamEnvAnd, Ty, TyCtxt}; +use rustc::ty::{self, ParamEnvAnd, Ty, TyCtxt}; use rustc::util::common::CellUsizeExt; crate fn normalize_ty_after_erasing_regions<'tcx>( @@ -18,15 +18,27 @@ crate fn normalize_ty_after_erasing_regions<'tcx>( goal: ParamEnvAnd<'tcx, Ty<'tcx>>, ) -> Ty<'tcx> { let ParamEnvAnd { param_env, value } = goal; - tcx.sess.perf_stats.normalize_ty_after_erasing_regions.increment(); + tcx.sess + .perf_stats + .normalize_ty_after_erasing_regions + .increment(); tcx.infer_ctxt().enter(|infcx| { let cause = ObligationCause::dummy(); match infcx.at(&cause, param_env).normalize(&value) { - Ok(Normalized { value: normalized_value, obligations: _ }) => { - // ^^^^^^^^^^^ - // We don't care about the `obligations`, - // they are always only region relations, - // and we are about to erase those anyway. + Ok(Normalized { + value: normalized_value, + obligations: normalized_obligations, + }) => { + // We don't care about the `obligations`; they are + // always only region relations, and we are about to + // erase those anyway: + debug_assert_eq!( + normalized_obligations + .iter() + .find(|p| not_outlives_predicate(&p.predicate)), + None, + ); + let normalized_value = infcx.resolve_type_vars_if_possible(&normalized_value); let normalized_value = infcx.tcx.erase_regions(&normalized_value); tcx.lift_to_global(&normalized_value).unwrap() @@ -35,3 +47,16 @@ crate fn normalize_ty_after_erasing_regions<'tcx>( } }) } + +fn not_outlives_predicate(p: &ty::Predicate<'_>) -> bool { + match p { + ty::Predicate::RegionOutlives(..) | ty::Predicate::TypeOutlives(..) => false, + ty::Predicate::Trait(..) + | ty::Predicate::Projection(..) + | ty::Predicate::WellFormed(..) + | ty::Predicate::ObjectSafe(..) + | ty::Predicate::ClosureKind(..) + | ty::Predicate::Subtype(..) + | ty::Predicate::ConstEvaluatable(..) => true, + } +} |
