add a debug assertion that only outlives-oblig. result from norm.
This commit is contained in:
parent
6288faa3a3
commit
fc04c41a40
1 changed files with 32 additions and 7 deletions
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue